Add models.openai and tools.langchain namespaces (#4601)

* add models.openai namespace

* refactor tools namespace

* update lock file

* revert pyproject changes

* update docs and add cast

* update ext models doc ref

* increase underline

* add reply models namespace

* update imports

* fix test

* linting

* fix missing conflicts

* revert pydantic changes

* rename to replay

* replay

* fix reply

* Fix test

* formatting

* example

---------

Co-authored-by: Leonardo Pinheiro <lpinheiro@microsoft.com>
Co-authored-by: Jack Gerrits <jack@jackgerrits.com>
Co-authored-by: Jack Gerrits <jackgerrits@users.noreply.github.com>
This commit is contained in:
Leonardo Pinheiro 2024-12-10 13:18:09 +10:00 committed by GitHub
parent 3e5e12bff0
commit 253fe216fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
63 changed files with 634 additions and 621 deletions

View File

@ -121,7 +121,7 @@ class AssistantAgent(BaseChatAgent):
import asyncio
from autogen_core import CancellationToken
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
@ -149,7 +149,7 @@ class AssistantAgent(BaseChatAgent):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from autogen_agentchat.ui import Console
@ -183,7 +183,7 @@ class AssistantAgent(BaseChatAgent):
import asyncio
from autogen_core import CancellationToken
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage

View File

@ -40,7 +40,7 @@ class SocietyOfMindAgent(BaseChatAgent):
import asyncio
from autogen_agentchat.agents import AssistantAgent, SocietyOfMindAgent
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import MaxMessageTermination

View File

@ -15,23 +15,23 @@ class Handoff(BaseModel):
target: str
"""The name of the target agent to handoff to."""
description: str = Field(default=None)
description: str = Field(default="")
"""The description of the handoff such as the condition under which it should happen and the target agent's ability.
If not provided, it is generated from the target agent's name."""
name: str = Field(default=None)
name: str = Field(default="")
"""The name of this handoff configuration. If not provided, it is generated from the target agent's name."""
message: str = Field(default=None)
message: str = Field(default="")
"""The message to the target agent.
If not provided, it is generated from the target agent's name."""
@model_validator(mode="before")
@classmethod
def set_defaults(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if values.get("description") is None:
if not values.get("description"):
values["description"] = f"Handoff to {values['target']}."
if values.get("name") is None:
if not values.get("name"):
values["name"] = f"transfer_to_{values['target']}".lower()
else:
name = values["name"]
@ -40,7 +40,7 @@ class Handoff(BaseModel):
# Check if name is a valid identifier.
if not name.isidentifier():
raise ValueError(f"Handoff name must be a valid identifier: {values['name']}")
if values.get("message") is None:
if not values.get("message"):
values["message"] = (
f"Transferred to {values['target']}, adopting the role of {values['target']} immediately."
)

View File

@ -188,7 +188,7 @@ class BaseGroupChat(Team, ABC):
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:
@ -219,7 +219,7 @@ class BaseGroupChat(Team, ABC):
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_core import CancellationToken
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:
@ -286,7 +286,7 @@ class BaseGroupChat(Team, ABC):
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:
@ -320,7 +320,7 @@ class BaseGroupChat(Team, ABC):
from autogen_agentchat.ui import Console
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_core import CancellationToken
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:
@ -437,7 +437,7 @@ class BaseGroupChat(Team, ABC):
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:

View File

@ -38,7 +38,7 @@ class MagenticOneGroupChat(BaseGroupChat):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import MagenticOneGroupChat
from autogen_agentchat.ui import Console

View File

@ -83,7 +83,7 @@ class RoundRobinGroupChat(BaseGroupChat):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import TextMentionTermination
@ -113,7 +113,7 @@ class RoundRobinGroupChat(BaseGroupChat):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.conditions import TextMentionTermination

View File

@ -219,7 +219,7 @@ class SelectorGroupChat(BaseGroupChat):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import SelectorGroupChat
from autogen_agentchat.conditions import TextMentionTermination
@ -273,7 +273,7 @@ class SelectorGroupChat(BaseGroupChat):
import asyncio
from typing import Sequence
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import SelectorGroupChat
from autogen_agentchat.conditions import TextMentionTermination

View File

@ -108,7 +108,7 @@ class Swarm(BaseGroupChat):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import Swarm
from autogen_agentchat.conditions import MaxMessageTermination
@ -143,7 +143,7 @@ class Swarm(BaseGroupChat):
.. code-block:: python
import asyncio
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import Swarm
from autogen_agentchat.conditions import HandoffTermination, MaxMessageTermination

View File

@ -16,7 +16,7 @@ from autogen_agentchat.messages import (
)
from autogen_core import Image
from autogen_core.tools import FunctionTool
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from openai.resources.chat.completions import AsyncCompletions
from openai.types.chat.chat_completion import ChatCompletion, Choice
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk

View File

@ -35,7 +35,8 @@ from autogen_agentchat.ui import Console
from autogen_core import AgentId, CancellationToken
from autogen_core.tools import FunctionTool
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
from autogen_ext.models import OpenAIChatCompletionClient, ReplayChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.models.replay import ReplayChatCompletionClient
from openai.resources.chat.completions import AsyncCompletions
from openai.types.chat.chat_completion import ChatCompletion, Choice
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk

View File

@ -18,7 +18,7 @@ from autogen_agentchat.teams import (
)
from autogen_agentchat.teams._group_chat._magentic_one._magentic_one_orchestrator import MagenticOneOrchestrator
from autogen_core import AgentId, CancellationToken
from autogen_ext.models import ReplayChatCompletionClient
from autogen_ext.models.replay import ReplayChatCompletionClient
from utils import FileLogHandler
logger = logging.getLogger(EVENT_LOGGER_NAME)

View File

@ -5,7 +5,7 @@ import pytest
from autogen_agentchat.agents import AssistantAgent, SocietyOfMindAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from openai.resources.chat.completions import AsyncCompletions
from openai.types.chat.chat_completion import ChatCompletion, Choice
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk

View File

@ -45,8 +45,9 @@ python/autogen_ext.agents.web_surfer
python/autogen_ext.agents.file_surfer
python/autogen_ext.agents.video_surfer
python/autogen_ext.agents.video_surfer.tools
python/autogen_ext.models
python/autogen_ext.tools
python/autogen_ext.models.openai
python/autogen_ext.models.replay
python/autogen_ext.tools.langchain
python/autogen_ext.code_executors.local
python/autogen_ext.code_executors.docker
python/autogen_ext.code_executors.azure

View File

@ -0,0 +1,8 @@
autogen\_ext.models.openai
==========================
.. automodule:: autogen_ext.models.openai
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,8 @@
autogen\_ext.models.replay
==========================
.. automodule:: autogen_ext.models.replay
:members:
:undoc-members:
:show-inheritance:

View File

@ -1,8 +0,0 @@
autogen\_ext.models
===================
.. automodule:: autogen_ext.models
:members:
:undoc-members:
:show-inheritance:

View File

@ -27,7 +27,7 @@
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_core.tools import FunctionTool\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -27,7 +27,7 @@
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_core.tools import FunctionTool\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -21,7 +21,7 @@
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -76,7 +76,7 @@
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"\n",
"# Define a tool\n",

View File

@ -33,7 +33,7 @@
"from autogen_agentchat.agents import AssistantAgent\n",
"from autogen_agentchat.messages import TextMessage\n",
"from autogen_core import CancellationToken\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"\n",
"# Define a tool that searches the web for information.\n",

View File

@ -44,7 +44,7 @@
"metadata": {},
"outputs": [],
"source": [
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"opneai_model_client = OpenAIChatCompletionClient(\n",
" model=\"gpt-4o-2024-08-06\",\n",
@ -128,7 +128,7 @@
"metadata": {},
"outputs": [],
"source": [
"from autogen_ext.models import AzureOpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import AzureOpenAIChatCompletionClient\n",
"from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n",
"\n",
"# Create the token provider\n",

View File

@ -67,7 +67,7 @@
"from autogen_agentchat.messages import AgentMessage\n",
"from autogen_agentchat.teams import SelectorGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -39,7 +39,7 @@
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_core import CancellationToken\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"assistant_agent = AssistantAgent(\n",
" name=\"assistant_agent\",\n",

View File

@ -100,7 +100,7 @@
"from autogen_agentchat.messages import HandoffMessage\n",
"from autogen_agentchat.teams import Swarm\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -33,7 +33,7 @@
"from autogen_agentchat.agents import AssistantAgent\n",
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"# Create an OpenAI model client.\n",
"model_client = OpenAIChatCompletionClient(\n",
@ -260,7 +260,7 @@
"from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"# Create an OpenAI model client.\n",
"model_client = OpenAIChatCompletionClient(\n",
@ -633,7 +633,7 @@
"from autogen_agentchat.base import Handoff\n",
"from autogen_agentchat.conditions import HandoffTermination, TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"# Create an OpenAI model client.\n",
"model_client = OpenAIChatCompletionClient(\n",

View File

@ -58,7 +58,7 @@
"from autogen_agentchat.conditions import MaxMessageTermination, TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat\n",
"from autogen_agentchat.ui import Console\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"model_client = OpenAIChatCompletionClient(\n",
" model=\"gpt-4o\",\n",

View File

@ -15,7 +15,7 @@ pip install azure-identity
## Using the Model Client
```python
from autogen_ext.models import AzureOpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
# Create the token provider

View File

@ -55,7 +55,7 @@
" SystemMessage,\n",
" UserMessage,\n",
")\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -66,7 +66,7 @@
"from typing import Optional\n",
"\n",
"from autogen_core.models import UserMessage\n",
"from autogen_ext.models import AzureOpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import AzureOpenAIChatCompletionClient\n",
"\n",
"\n",
"# Function to get environment variable and ensure it is not None\n",

View File

@ -38,7 +38,7 @@
"from autogen_core.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n",
"from autogen_core.tools import PythonCodeExecutionTool, ToolSchema\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -91,7 +91,7 @@
" UserMessage,\n",
")\n",
"from autogen_core.tools import FunctionTool\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"from IPython.display import display # type: ignore\n",
"from pydantic import BaseModel\n",
"from rich.console import Console\n",

View File

@ -75,7 +75,7 @@
" UserMessage,\n",
")\n",
"from autogen_core.tools import FunctionTool, Tool\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"from pydantic import BaseModel"
]
},
@ -296,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [

View File

@ -59,7 +59,7 @@
" SystemMessage,\n",
" UserMessage,\n",
")\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -442,7 +442,7 @@
],
"source": [
"from autogen_core import DefaultTopicId, SingleThreadedAgentRuntime\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"runtime = SingleThreadedAgentRuntime()\n",
"await ReviewerAgent.register(\n",

View File

@ -58,7 +58,7 @@
" type_subscription,\n",
")\n",
"from autogen_core.models import ChatCompletionClient, SystemMessage, UserMessage\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
"from autogen_ext.models.openai import OpenAIChatCompletionClient"
]
},
{

View File

@ -46,7 +46,7 @@ Model capabilites are additional capabilities an LLM may have beyond the standar
Model capabilities can be passed into a model, which will override the default definitions. These capabilities will not affect what the underlying model is actually capable of, but will allow or disallow behaviors associated with them. This is particularly useful when [using local LLMs](cookbook/local-llms-ollama-litellm.ipynb).
```python
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
client = OpenAIChatCompletionClient(
model="gpt-4o",

View File

@ -33,7 +33,7 @@
"outputs": [],
"source": [
"from autogen_core.models import UserMessage\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"# Create an OpenAI model client.\n",
"model_client = OpenAIChatCompletionClient(\n",
@ -290,7 +290,7 @@
"metadata": {},
"outputs": [],
"source": [
"from autogen_ext.models import AzureOpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import AzureOpenAIChatCompletionClient\n",
"from azure.identity import DefaultAzureCredential, get_bearer_token_provider\n",
"\n",
"# Create the token provider\n",
@ -334,7 +334,7 @@
"\n",
"from autogen_core import MessageContext, RoutedAgent, SingleThreadedAgentRuntime, message_handler\n",
"from autogen_core.models import ChatCompletionClient, SystemMessage, UserMessage\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"\n",
"@dataclass\n",

View File

@ -171,7 +171,7 @@
")\n",
"from autogen_core.tool_agent import ToolAgent, tool_agent_caller_loop\n",
"from autogen_core.tools import FunctionTool, Tool, ToolSchema\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"\n",
"@dataclass\n",

View File

@ -324,7 +324,7 @@
"\n",
"from autogen_core import SingleThreadedAgentRuntime\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"work_dir = tempfile.mkdtemp()\n",
"\n",

View File

@ -9,7 +9,7 @@ from autogen_core.models import (
LLMMessage,
UserMessage,
)
from autogen_ext.models import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from typing_extensions import Literal

View File

@ -4,7 +4,7 @@ from typing import Dict
from autogen_core.models import (
LLMMessage,
)
from autogen_ext.models import AzureOpenAIClientConfiguration
from autogen_ext.models.openai import AzureOpenAIClientConfiguration
from pydantic import BaseModel

View File

@ -5,7 +5,7 @@ from typing import Any, Iterable, Type
import yaml
from _types import AppConfig
from autogen_core import MessageSerializer, try_get_known_serializers_for_type
from autogen_ext.models import AzureOpenAIClientConfiguration
from autogen_ext.models.openai import AzureOpenAIClientConfiguration
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

View File

@ -8,7 +8,7 @@ from _utils import get_serializers, load_config, set_all_log_levels
from autogen_core import (
TypeSubscription,
)
from autogen_ext.models import AzureOpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntime
from rich.console import Console
from rich.markdown import Markdown

View File

@ -8,7 +8,7 @@ from _utils import get_serializers, load_config, set_all_log_levels
from autogen_core import (
TypeSubscription,
)
from autogen_ext.models import AzureOpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntime
from rich.console import Console
from rich.markdown import Markdown

View File

@ -8,7 +8,7 @@ from _utils import get_serializers, load_config, set_all_log_levels
from autogen_core import (
TypeSubscription,
)
from autogen_ext.models import AzureOpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntime
from rich.console import Console
from rich.markdown import Markdown

View File

@ -42,7 +42,7 @@ class VideoSurfer(AssistantAgent):
from autogen_agentchat.ui import Console
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.agents.video_surfer import VideoSurfer
async def main() -> None:
@ -76,7 +76,7 @@ class VideoSurfer(AssistantAgent):
from autogen_agentchat.ui import Console
from autogen_agentchat.teams import MagenticOneGroupChat
from autogen_agentchat.agents import UserProxyAgent
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.agents.video_surfer import VideoSurfer
async def main() -> None:

View File

@ -1,14 +1,12 @@
from ._openai._openai_client import (
from ._openai_client import (
AzureOpenAIChatCompletionClient,
OpenAIChatCompletionClient,
)
from ._openai.config import AzureOpenAIClientConfiguration, OpenAIClientConfiguration
from ._reply_chat_completion_client import ReplayChatCompletionClient
from .config import AzureOpenAIClientConfiguration, OpenAIClientConfiguration
__all__ = [
"AzureOpenAIClientConfiguration",
"AzureOpenAIChatCompletionClient",
"OpenAIClientConfiguration",
"OpenAIChatCompletionClient",
"ReplayChatCompletionClient",
]

View File

@ -43,6 +43,9 @@ from autogen_core.models import (
UserMessage,
)
from autogen_core.tools import Tool, ToolSchema
from pydantic import BaseModel
from typing_extensions import Unpack
from openai import AsyncAzureOpenAI, AsyncOpenAI
from openai.types.chat import (
ChatCompletion,
@ -63,8 +66,6 @@ from openai.types.chat import (
from openai.types.chat.chat_completion import Choice
from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice
from openai.types.shared_params import FunctionDefinition, FunctionParameters
from pydantic import BaseModel
from typing_extensions import Unpack
from . import _model_info
from .config import AzureOpenAIClientConfiguration, OpenAIClientConfiguration
@ -909,13 +910,13 @@ class OpenAIChatCompletionClient(BaseOpenAIChatCompletionClient):
.. code-block:: bash
pip install 'autogen-ext[openai]==0.4.0.dev9'
pip install 'autogen-ext[openai]==0.4.0.dev8'
The following code snippet shows how to use the client with an OpenAI model:
.. code-block:: python
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import UserMessage
openai_client = OpenAIChatCompletionClient(
@ -931,7 +932,7 @@ class OpenAIChatCompletionClient(BaseOpenAIChatCompletionClient):
.. code-block:: python
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
custom_model_client = OpenAIChatCompletionClient(
model="custom-model-name",
@ -989,7 +990,7 @@ class AzureOpenAIChatCompletionClient(BaseOpenAIChatCompletionClient):
.. code-block:: bash
pip install 'autogen-ext[openai,azure]==0.4.0.dev9'
pip install 'autogen-ext[openai,azure]==0.4.0.dev8'
To use the client, you need to provide your deployment id, Azure Cognitive Services endpoint,
api version, and model capabilities.
@ -1000,7 +1001,7 @@ class AzureOpenAIChatCompletionClient(BaseOpenAIChatCompletionClient):
.. code-block:: python
from autogen_ext.models import AzureOpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
# Create the token provider

View File

@ -0,0 +1,5 @@
from ._replay_chat_completion_client import ReplayChatCompletionClient
__all__ = [
"ReplayChatCompletionClient",
]

View File

@ -37,7 +37,7 @@ class ReplayChatCompletionClient:
.. code-block:: python
from autogen_ext.models import ReplayChatCompletionClient
from autogen_ext.models.replay import ReplayChatCompletionClient
from autogen_core.models import UserMessage
@ -57,7 +57,7 @@ class ReplayChatCompletionClient:
.. code-block:: python
import asyncio
from autogen_ext.models import ReplayChatCompletionClient
from autogen_ext.models.replay import ReplayChatCompletionClient
from autogen_core.models import UserMessage
@ -83,7 +83,7 @@ class ReplayChatCompletionClient:
.. code-block:: python
import asyncio
from autogen_ext.models import ReplayChatCompletionClient
from autogen_ext.models.replay import ReplayChatCompletionClient
from autogen_core.models import UserMessage

View File

@ -15,9 +15,9 @@ from autogen_core.models import (
UserMessage,
)
from autogen_core.tools import BaseTool, FunctionTool
from autogen_ext.models import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from autogen_ext.models._openai._model_info import resolve_model
from autogen_ext.models._openai._openai_client import calculate_vision_tokens, convert_tools
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from autogen_ext.models.openai._model_info import resolve_model
from autogen_ext.models.openai._openai_client import calculate_vision_tokens, convert_tools
from openai.resources.chat.completions import AsyncCompletions
from openai.types.chat.chat_completion import ChatCompletion, Choice
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk, ChoiceDelta
@ -275,9 +275,7 @@ async def test_openai_chat_completion_client_count_tokens(monkeypatch: pytest.Mo
tools = [FunctionTool(tool1, description="example tool 1"), FunctionTool(tool2, description="example tool 2")]
mockcalculate_vision_tokens = MagicMock()
monkeypatch.setattr(
"autogen_ext.models._openai._openai_client.calculate_vision_tokens", mockcalculate_vision_tokens
)
monkeypatch.setattr("autogen_ext.models.openai._openai_client.calculate_vision_tokens", mockcalculate_vision_tokens)
num_tokens = client.count_tokens(messages, tools=tools)
assert num_tokens

View File

@ -13,7 +13,7 @@ from autogen_core import (
message_handler,
)
from autogen_core.models import ChatCompletionClient, CreateResult, SystemMessage, UserMessage
from autogen_ext.models import ReplayChatCompletionClient
from autogen_ext.models.replay import ReplayChatCompletionClient
@dataclass
@ -48,7 +48,7 @@ class LLMAgentWithDefaultSubscription(LLMAgent): ...
@pytest.mark.asyncio
async def test_reply_chat_completion_client() -> None:
async def test_replay_chat_completion_client() -> None:
num_messages = 5
messages = [f"Message {i}" for i in range(num_messages)]
reply_model_client = ReplayChatCompletionClient(messages)
@ -61,7 +61,7 @@ async def test_reply_chat_completion_client() -> None:
@pytest.mark.asyncio
async def test_reply_chat_completion_client_create_stream() -> None:
async def test_replay_chat_completion_client_create_stream() -> None:
num_messages = 5
messages = [f"Message {i}" for i in range(num_messages)]
reply_model_client = ReplayChatCompletionClient(messages)
@ -155,7 +155,7 @@ async def test_token_count_logics() -> None:
@pytest.mark.asyncio
async def test_reply_chat_completion_client_reset() -> None:
async def test_replay_chat_completion_client_reset() -> None:
"""Test that reset functionality properly resets the client state."""
messages = ["First message", "Second message", "Third message"]
client = ReplayChatCompletionClient(messages)

View File

@ -1,8 +1,9 @@
from typing import Optional, Type
from typing import Optional, Type, cast
import pytest
from autogen_core import CancellationToken
from autogen_ext.tools import LangChainToolAdapter # type: ignore
from autogen_core.tools import Tool
from autogen_ext.tools.langchain import LangChainToolAdapter # type: ignore
from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun, CallbackManagerForToolRun
from langchain_core.tools import BaseTool as LangChainTool
from langchain_core.tools import tool # pyright: ignore
@ -46,7 +47,7 @@ async def test_langchain_tool_adapter() -> None:
langchain_tool = add # type: ignore
# Create an adapter
adapter = LangChainToolAdapter(langchain_tool) # type: ignore
adapter = cast(Tool, LangChainToolAdapter(langchain_tool)) # type: ignore
# Test schema generation
schema = adapter.schema

View File

@ -11,7 +11,7 @@ from autogen_core.models import (
ChatCompletionClient,
ModelCapabilities,
)
from autogen_ext.models import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from autogen_ext.models.openai import AzureOpenAIChatCompletionClient, OpenAIChatCompletionClient
from .messages import (
AgentEvent,

View File

@ -13,7 +13,7 @@ from autogen_core.tools import FunctionTool
from autogen_ext.agents.file_surfer import FileSurfer
from autogen_ext.agents.magentic_one import MagenticOneCoderAgent
from autogen_ext.agents.web_surfer import MultimodalWebSurfer
from autogen_ext.models import OpenAIChatCompletionClient
from autogen_ext.models.openai import OpenAIChatCompletionClient
from ..datamodel.types import (
AgentConfig,

View File

@ -210,7 +210,7 @@
"from autogen_agentchat.agents import AssistantAgent\n",
"from autogen_agentchat.conditions import TextMentionTermination\n",
"from autogen_agentchat.teams import RoundRobinGroupChat, SelectorGroupChat\n",
"from autogen_ext.models import OpenAIChatCompletionClient\n",
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
"\n",
"planner_agent = AssistantAgent(\n",
" \"planner_agent\",\n",