diff --git a/python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py b/python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py index a783d4965e17..16d56b57f956 100644 --- a/python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py +++ b/python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py @@ -523,6 +523,9 @@ async def create_stream( if choice and choice.finish_reason is not None: if isinstance(choice.finish_reason, CompletionsFinishReason): finish_reason = cast(FinishReasons, choice.finish_reason.value) + # Handle special case for TOOL_CALLS finish reason + if choice.finish_reason is CompletionsFinishReason.TOOL_CALLS: + finish_reason = "function_calls" else: if choice.finish_reason in ["stop", "length", "function_calls", "content_filter", "unknown"]: finish_reason = choice.finish_reason # type: ignore @@ -554,9 +557,6 @@ async def create_stream( if finish_reason is None: raise ValueError("No stop reason found") - if choice and choice.finish_reason is CompletionsFinishReason.TOOL_CALLS: - finish_reason = "function_calls" - content: Union[str, List[FunctionCall]] if len(content_deltas) > 1: