From a7c97dbbbf4bb88af8b953f41ae322233a13a105 Mon Sep 17 00:00:00 2001 From: Sudhakar Date: Mon, 13 Jan 2025 17:49:05 +0000 Subject: [PATCH 1/3] Typo in teams.ipynb (#5028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Minor typo, Let’s calls the run() method to start the team with a task. Fixed as, Let’s call the run() method to start the team with a task. --- .../src/user-guide/agentchat-user-guide/tutorial/teams.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb index ce0f39664158..d12a273edbda 100644 --- a/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb +++ b/python/packages/autogen-core/docs/src/user-guide/agentchat-user-guide/tutorial/teams.ipynb @@ -83,7 +83,7 @@ "source": [ "## Running a Team\n", "\n", - "Let's calls the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run` method\n", + "Let's call the {py:meth}`~autogen_agentchat.teams.BaseGroupChat.run` method\n", "to start the team with a task." ] }, From c0082dd9cce9429df86d5704534780b1a88ce1f4 Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Mon, 13 Jan 2025 13:26:31 -0500 Subject: [PATCH 2/3] fix: Normalize openai client stop reason to make more robust (#5027) * Normalize stop reason to make more robust * format * add unknown finish reason --- .../src/autogen_core/models/_types.py | 2 +- .../models/openai/_openai_client.py | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/python/packages/autogen-core/src/autogen_core/models/_types.py b/python/packages/autogen-core/src/autogen_core/models/_types.py index fb118562e4d3..a3d6af1edde4 100644 --- a/python/packages/autogen-core/src/autogen_core/models/_types.py +++ b/python/packages/autogen-core/src/autogen_core/models/_types.py @@ -52,7 +52,7 @@ class RequestUsage: completion_tokens: int -FinishReasons = Literal["stop", "length", "function_calls", "content_filter"] +FinishReasons = Literal["stop", "length", "function_calls", "content_filter", "unknown"] @dataclass diff --git a/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py b/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py index 5b9f51129a88..ad9ce6e84712 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py @@ -30,6 +30,7 @@ Image, MessageHandlerContext, ) +from autogen_core.models import FinishReasons from autogen_core.logging import LLMCallEvent from autogen_core.models import ( AssistantMessage, @@ -327,6 +328,21 @@ def assert_valid_name(name: str) -> str: return name +def normalize_stop_reason(stop_reason: str | None) -> FinishReasons: + if stop_reason is None: + return "unknown" + + # Convert to lower case + stop_reason = stop_reason.lower() + + KNOWN_STOP_MAPPINGS: Dict[str, FinishReasons] = { + "end_turn": "stop", + "tool_calls": "function_calls", + } + + return KNOWN_STOP_MAPPINGS.get(stop_reason, "unknown") + + class BaseOpenAIChatCompletionClient(ChatCompletionClient): def __init__( self, @@ -747,8 +763,8 @@ async def create_stream( else: prompt_tokens = 0 - if stop_reason is None: - raise ValueError("No stop reason found") + if stop_reason == "function_call": + raise ValueError("Function calls are not supported in this context") content: Union[str, List[FunctionCall]] if len(content_deltas) > 1: @@ -770,13 +786,9 @@ async def create_stream( prompt_tokens=prompt_tokens, completion_tokens=completion_tokens, ) - if stop_reason == "function_call": - raise ValueError("Function calls are not supported in this context") - if stop_reason == "tool_calls": - stop_reason = "function_calls" result = CreateResult( - finish_reason=stop_reason, # type: ignore + finish_reason=normalize_stop_reason(stop_reason), content=content, usage=usage, cached=False, From 1a6e9766c9652a45809b0d23642310e100f1c5d6 Mon Sep 17 00:00:00 2001 From: Johan Forngren Date: Mon, 13 Jan 2025 19:53:18 +0100 Subject: [PATCH 3/3] Add tiktoken as a dependency in pyproject.toml (#5008) * Add tiktoken as a dependency in pyproject.toml Signed-off-by: Johan Forngren Update uv.lock with tiktoken dependency from fbfdc9f652384b70f7461c90ada13f87e83677e0 Signed-off-by: Johan Forngren * Updating autogen-ext dependencies per https://github.com/microsoft/autogen/pull/5008#issuecomment-2585383877 Signed-off-by: Johan Forngren --------- Signed-off-by: Johan Forngren Co-authored-by: Victor Dibia --- python/packages/autogen-studio/pyproject.toml | 4 ++-- python/uv.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/packages/autogen-studio/pyproject.toml b/python/packages/autogen-studio/pyproject.toml index 869bdb78b8f6..5c9cbcc6cf47 100644 --- a/python/packages/autogen-studio/pyproject.toml +++ b/python/packages/autogen-studio/pyproject.toml @@ -35,8 +35,8 @@ dependencies = [ "pyyaml", "autogen-core==0.4.0", "autogen-agentchat==0.4.0", - "autogen-ext[magentic-one]==0.4.0", - "azure-identity", + "autogen-ext[magentic-one, openai, azure]==0.4.0", + "azure-identity" ] optional-dependencies = {web = ["fastapi", "uvicorn"], database = ["psycopg"]} diff --git a/python/uv.lock b/python/uv.lock index 95db2f3c8185..156a298cc262 100644 --- a/python/uv.lock +++ b/python/uv.lock @@ -659,7 +659,7 @@ dependencies = [ { name = "alembic" }, { name = "autogen-agentchat" }, { name = "autogen-core" }, - { name = "autogen-ext", extra = ["magentic-one"] }, + { name = "autogen-ext", extra = ["azure", "magentic-one", "openai"] }, { name = "azure-identity" }, { name = "fastapi" }, { name = "loguru" }, @@ -690,7 +690,7 @@ requires-dist = [ { name = "alembic" }, { name = "autogen-agentchat", editable = "packages/autogen-agentchat" }, { name = "autogen-core", editable = "packages/autogen-core" }, - { name = "autogen-ext", extras = ["magentic-one"], editable = "packages/autogen-ext" }, + { name = "autogen-ext", extras = ["azure", "magentic-one", "openai"], editable = "packages/autogen-ext" }, { name = "azure-identity" }, { name = "fastapi" }, { name = "fastapi", marker = "extra == 'web'" },