ModelBackendMeta
<think>
tags) before they
are sent to the model.
new
BaseModelBackend
- model_type (Union[ModelType, str]): Model for which a backend is created.
- model_config_dict (Optional[Dict[str, Any]], optional): A config dictionary. (default: :obj:
{}
) - api_key (Optional[str], optional): The API key for authenticating with the model service. (default: :obj:
None
) - url (Optional[str], optional): The url to the model service. (default: :obj:
None
) - token_counter (Optional[BaseTokenCounter], optional): Token counter to use for the model. If not provided, :obj:
OpenAITokenCounter
will be used. (default: :obj:None
) - timeout (Optional[float], optional): The timeout value in seconds for API calls. (default: :obj:
None
) - max_retries (int, optional): Maximum number of retries for API calls. (default: :obj:
3
)
init
token_counter
preprocess_messages
- messages (List[OpenAIMessage]): Original messages.
_log_request
- messages (List[OpenAIMessage]): The messages to log.
_log_response
- log_path (str): The path to the log file.
- response (Any): The response to log.
_run
- messages (List[OpenAIMessage]): Message list with the chat history in OpenAI API format.
- response_format (Optional[Type[BaseModel]]): The format of the response.
- tools (Optional[List[Dict[str, Any]]]): The schema of the tools to use for the request.
ChatCompletion
in the non-stream mode, or
Stream[ChatCompletionChunk]
in the stream mode,
or ChatCompletionStreamManager[BaseModel]
in the structured
stream mode.
run
- messages (List[OpenAIMessage]): Message list with the chat history in OpenAI API format.
- response_format (Optional[Type[BaseModel]]): The response format to use for the model. (default: :obj:
None
) - tools (Optional[List[Tool]]): The schema of tools to use for the model for this request. Will override the tools specified in the model configuration (but not change the configuration). (default: :obj:
None
)
ChatCompletion
in the non-stream mode,
Stream[ChatCompletionChunk]
in the stream mode, or
ChatCompletionStreamManager[BaseModel]
in the structured
stream mode.
count_tokens_from_messages
- messages (List[Dict]): message list with the chat history in OpenAI API format.