mirror of
https://github.com/microsoft/autogen.git
synced 2025-12-25 05:59:19 +00:00
Ollama client docs (#5605)
<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? Adds ollama client documentation to the docs page ## Related issue number https://github.com/microsoft/autogen/issues/5604 ## Checks - [ ] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://microsoft.github.io/autogen/docs/Contribute#documentation to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
This commit is contained in:
parent
4959b24777
commit
2842c76aeb
@ -52,6 +52,7 @@ python/autogen_ext.models.openai
|
||||
python/autogen_ext.models.replay
|
||||
python/autogen_ext.models.azure
|
||||
python/autogen_ext.models.semantic_kernel
|
||||
python/autogen_ext.models.ollama
|
||||
python/autogen_ext.tools.code_execution
|
||||
python/autogen_ext.tools.graphrag
|
||||
python/autogen_ext.tools.http
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
autogen\_ext.models.ollama
|
||||
==========================
|
||||
|
||||
|
||||
.. automodule:: autogen_ext.models.ollama
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
@ -402,6 +402,7 @@ class BaseOllamaChatCompletionClient(ChatCompletionClient):
|
||||
response_format_value = value.model_json_schema()
|
||||
else:
|
||||
# response_format_value is not a Pydantic model class
|
||||
# TODO: Should this be an warning/error?
|
||||
response_format_value = None
|
||||
|
||||
# Remove 'response_format' from create_args to prevent passing it twice
|
||||
@ -842,15 +843,16 @@ class BaseOllamaChatCompletionClient(ChatCompletionClient):
|
||||
class OllamaChatCompletionClient(BaseOllamaChatCompletionClient, Component[BaseOllamaClientConfigurationConfigModel]):
|
||||
"""Chat completion client for Ollama hosted models.
|
||||
|
||||
You can also use this client for Ollama-compatible ChatCompletion endpoints.
|
||||
|
||||
Ollama must be installed and the appropriate model pulled.
|
||||
|
||||
Args:
|
||||
model (str): Which Ollama model to use.
|
||||
host (str): Model host url.
|
||||
response_format (optional, pydantic.BaseModel)
|
||||
host (optional, str): Model host url.
|
||||
response_format (optional, pydantic.BaseModel): The format of the response. If provided, the response will be parsed into this format as json.
|
||||
model_info (optional, ModelInfo): The capabilities of the model. **Required if the model is not listed in the ollama model info.**
|
||||
|
||||
Note:
|
||||
Only models with 200k+ downloads (as of Jan 21, 2025), + phi4, deepseek-r1 have pre-defined model infos. See `this file <https://github.com/microsoft/autogen/blob/main/python/packages/autogen-ext/src/autogen_ext/models/ollama/_model_info.py>`__ for the full list. An entry for one model encompases all parameter variants of that model.
|
||||
|
||||
To use this client, you must install the `ollama` extension:
|
||||
|
||||
@ -886,7 +888,11 @@ class OllamaChatCompletionClient(BaseOllamaChatCompletionClient, Component[BaseO
|
||||
client = ChatCompletionClient.load_component(config)
|
||||
|
||||
To output structured data, you can use the `response_format` argument:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from autogen_ext.models.ollama import OllamaChatCompletionClient
|
||||
from autogen_core.models import UserMessage
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@ -902,7 +908,8 @@ class OllamaChatCompletionClient(BaseOllamaChatCompletionClient, Component[BaseO
|
||||
result = await ollama_client.create([UserMessage(content="Who was the first man on the moon?", source="user")]) # type: ignore
|
||||
print(result)
|
||||
|
||||
Note: Tool usage in ollama is stricter than in its OpenAI counterparts. While OpenAI accepts a map of [str, Any], Ollama requires a map of [str, Property] where Property is a typed object containing ``type`` and ``description`` fields. Therefore, only the keys ``type`` and ``description`` will be converted from the properties blob in the tool schema.
|
||||
Note:
|
||||
Tool usage in ollama is stricter than in its OpenAI counterparts. While OpenAI accepts a map of [str, Any], Ollama requires a map of [str, Property] where Property is a typed object containing ``type`` and ``description`` fields. Therefore, only the keys ``type`` and ``description`` will be converted from the properties blob in the tool schema.
|
||||
|
||||
To view the full list of available configuration options, see the :py:class:`OllamaClientConfigurationConfigModel` class.
|
||||
|
||||
|
||||
@ -5,9 +5,12 @@ from pydantic import BaseModel
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
# response_format MUST be a pydantic.BaseModel type or None
|
||||
# TODO: check if we can extend response_format to support json and/or dict
|
||||
class CreateArguments(TypedDict, total=False):
|
||||
model: str
|
||||
host: Optional[str]
|
||||
response_format: Any
|
||||
|
||||
|
||||
class BaseOllamaClientConfiguration(CreateArguments, total=False):
|
||||
@ -20,9 +23,11 @@ class BaseOllamaClientConfiguration(CreateArguments, total=False):
|
||||
|
||||
|
||||
# Pydantic equivalents of the above TypedDicts
|
||||
# response_format MUST be a pydantic.BaseModel type or None
|
||||
class CreateArgumentsConfigModel(BaseModel):
|
||||
model: str
|
||||
host: str | None = None
|
||||
response_format: Any = None
|
||||
|
||||
|
||||
class BaseOllamaClientConfigurationConfigModel(CreateArgumentsConfigModel):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user