OllamaClient
OllamaClient(response_format: Optional[Union[BaseModel, dict[str, Any]]] = None, **kwargs)
Client for Ollama’s API.
Note that no api_key or environment variable is required for Ollama.
Parameters:
Name | Description |
---|
response_format | Type: Optional[Union[BaseModel, dict[str, Any]]]
Default: None |
**kwargs | |
Class Attributes
Static Methods
get_usage
get_usage(response) -> dict
Return usage summary of the response using RESPONSE_USAGE_KEYS.
Parameters:
Instance Methods
cost(self, response) -> float
Parameters:
create(self, params:Â dict) -> ChatCompletionExtended
Parameters:
Name | Description |
---|
params | Type: dict |
message_retrieval
message_retrieval(self, response) -> list
Retrieve and return a list of strings or a list of Choice.Message from the response.
NOTE: if a list of Choice.Message is returned, it currently needs to contain the fields of OpenAI’s ChatCompletion Message object,
since that is expected for function or tool calling in the rest of the codebase at the moment, unless a custom agent is being used.
Parameters:
oai_messages_to_ollama_messages
oai_messages_to_ollama_messages(
self,
messages: list[dict[str, Any]],
tools:Â list
) -> list[dict[str, Any]]
Convert messages from OAI format to Ollama’s format.
We correct for any specific role orders and types, and convert tools to messages (as Ollama can’t use tool messages)
Parameters:
Name | Description |
---|
messages | Type: list[dict[str, Any]] |
tools | Type: list |
parse_params
parse_params(self, params: dict[str, Any]) -> dict[str, Any]
Loads the parameters for Ollama API from the passed in parameters and returns a validated set. Checks types, ranges, and sets defaults
Parameters:
Name | Description |
---|
params | Type: dict[str, Any] |