From b6dd861166596ad1c1a6f34478fbb6fe8d29500a Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Sun, 26 May 2024 08:21:48 -0400 Subject: [PATCH] Organize model client (#24) * Organize model client * update patterns --- README.md | 2 +- examples/patterns.py | 2 +- .../agent_components/model_client/__init__.py | 24 +++++++++++++++++++ .../_model_client.py} | 2 +- .../_model_info.py} | 2 +- .../_openai_client.py} | 8 +++---- .../models_clients/__init__.py | 3 --- 7 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 src/agnext/agent_components/model_client/__init__.py rename src/agnext/agent_components/{model_client.py => model_client/_model_client.py} (95%) rename src/agnext/agent_components/{models_clients/model_info.py => model_client/_model_info.py} (97%) rename src/agnext/agent_components/{models_clients/openai_client.py => model_client/_openai_client.py} (98%) delete mode 100644 src/agnext/agent_components/models_clients/__init__.py diff --git a/README.md b/README.md index c658564d893..403c54751ec 100644 --- a/README.md +++ b/README.md @@ -55,5 +55,5 @@ pip install -e ".[docs]" sphinx-build docs/src docs/build # To view the docs: -python -m http.server -d docs/build/html +python -m http.server -d docs/build ``` diff --git a/examples/patterns.py b/examples/patterns.py index defa872988f..9dc0f6b3524 100644 --- a/examples/patterns.py +++ b/examples/patterns.py @@ -3,7 +3,7 @@ from typing import Any import openai -from agnext.agent_components.models_clients.openai_client import OpenAI +from agnext.agent_components.model_client import OpenAI from agnext.application_components.single_threaded_agent_runtime import ( SingleThreadedAgentRuntime, ) diff --git a/src/agnext/agent_components/model_client/__init__.py b/src/agnext/agent_components/model_client/__init__.py new file mode 100644 index 00000000000..d5a5ec187db --- /dev/null +++ b/src/agnext/agent_components/model_client/__init__.py @@ -0,0 +1,24 @@ +from ._model_client import ModelCapabilities, ModelClient +from ._openai_client import ( + AsyncAzureADTokenProvider, + AzureOpenAI, + AzureOpenAIClientConfiguration, + BaseOpenAIClientConfiguration, + CreateArguments, + OpenAI, + OpenAIClientConfiguration, + ResponseFormat, +) + +__all__ = [ + "AzureOpenAI", + "OpenAI", + "OpenAIClientConfiguration", + "AzureOpenAIClientConfiguration", + "ResponseFormat", + "CreateArguments", + "AsyncAzureADTokenProvider", + "BaseOpenAIClientConfiguration", + "ModelCapabilities", + "ModelClient", +] diff --git a/src/agnext/agent_components/model_client.py b/src/agnext/agent_components/model_client/_model_client.py similarity index 95% rename from src/agnext/agent_components/model_client.py rename to src/agnext/agent_components/model_client/_model_client.py index bea8cfbd426..9f46b4f8279 100644 --- a/src/agnext/agent_components/model_client.py +++ b/src/agnext/agent_components/model_client/_model_client.py @@ -11,7 +11,7 @@ Union, ) -from .types import CreateResult, FunctionDefinition, LLMMessage, RequestUsage +from ..types import CreateResult, FunctionDefinition, LLMMessage, RequestUsage class ModelCapabilities(TypedDict, total=False): diff --git a/src/agnext/agent_components/models_clients/model_info.py b/src/agnext/agent_components/model_client/_model_info.py similarity index 97% rename from src/agnext/agent_components/models_clients/model_info.py rename to src/agnext/agent_components/model_client/_model_info.py index af4ca15fbd8..7cbf9ebc398 100644 --- a/src/agnext/agent_components/models_clients/model_info.py +++ b/src/agnext/agent_components/model_client/_model_info.py @@ -1,6 +1,6 @@ from typing import Dict -from ..model_client import ModelCapabilities +from ._model_client import ModelCapabilities # Based on: https://platform.openai.com/docs/models/continuous-model-upgrades # This is a moving target, so correctness is checked by the model value returned by openai against expected values at runtime`` diff --git a/src/agnext/agent_components/models_clients/openai_client.py b/src/agnext/agent_components/model_client/_openai_client.py similarity index 98% rename from src/agnext/agent_components/models_clients/openai_client.py rename to src/agnext/agent_components/model_client/_openai_client.py index 62eafcc817c..1c1f024ecdb 100644 --- a/src/agnext/agent_components/models_clients/openai_client.py +++ b/src/agnext/agent_components/model_client/_openai_client.py @@ -33,7 +33,6 @@ # from ..._pydantic import type2schema from ..image import Image -from ..model_client import ModelCapabilities, ModelClient from ..types import ( AssistantMessage, CreateResult, @@ -45,7 +44,8 @@ SystemMessage, UserMessage, ) -from . import model_info +from . import _model_info +from ._model_client import ModelCapabilities, ModelClient openai_init_kwargs = set(inspect.getfullargspec(AsyncOpenAI.__init__).kwonlyargs) aopenai_init_kwargs = set(inspect.getfullargspec(AsyncAzureOpenAI.__init__).kwonlyargs) @@ -273,13 +273,13 @@ def __init__( if model_capabilities is None and isinstance(client, AsyncAzureOpenAI): raise ValueError("AzureOpenAI requires explicit model capabilities") elif model_capabilities is None: - self._model_capabilities = model_info.get_capabilties(create_args["model"]) + self._model_capabilities = _model_info.get_capabilties(create_args["model"]) else: self._model_capabilities = model_capabilities self._resolved_model: Optional[str] = None if "model" in create_args: - self._resolved_model = model_info.resolve_model(create_args["model"]) + self._resolved_model = _model_info.resolve_model(create_args["model"]) if ( "response_format" in create_args diff --git a/src/agnext/agent_components/models_clients/__init__.py b/src/agnext/agent_components/models_clients/__init__.py deleted file mode 100644 index b3895b7c584..00000000000 --- a/src/agnext/agent_components/models_clients/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .openai_client import AzureOpenAI, OpenAI - -__all__ = ("OpenAI", "AzureOpenAI")