Organize model client (#24)

* Organize model client

* update patterns
This commit is contained in:
Jack Gerrits 2024-05-26 08:21:48 -04:00 committed by GitHub
parent 39400e74dd
commit b6dd861166
7 changed files with 32 additions and 11 deletions

View File

@ -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
```

View File

@ -3,7 +3,7 @@ import asyncio
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,
)

View File

@ -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",
]

View File

@ -11,7 +11,7 @@ from typing_extensions import (
Union,
)
from .types import CreateResult, FunctionDefinition, LLMMessage, RequestUsage
from ..types import CreateResult, FunctionDefinition, LLMMessage, RequestUsage
class ModelCapabilities(TypedDict, total=False):

View File

@ -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``

View File

@ -33,7 +33,6 @@ from typing_extensions import Required, TypedDict, Unpack
# from ..._pydantic import type2schema
from ..image import Image
from ..model_client import ModelCapabilities, ModelClient
from ..types import (
AssistantMessage,
CreateResult,
@ -45,7 +44,8 @@ from ..types import (
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 @@ class BaseOpenAI(ModelClient):
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

View File

@ -1,3 +0,0 @@
from .openai_client import AzureOpenAI, OpenAI
__all__ = ("OpenAI", "AzureOpenAI")