Skip to content

Commit 6f67b95

Browse files
litterzhangweizhang3ekzhu
authored
Fix finish_reason logic in Azure AI client streaming response (#6963)
Co-authored-by: weizhang3 <weizhang3@microsoft.com> Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
1 parent c469fc0 commit 6f67b95

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ async def create_stream(
523523
if choice and choice.finish_reason is not None:
524524
if isinstance(choice.finish_reason, CompletionsFinishReason):
525525
finish_reason = cast(FinishReasons, choice.finish_reason.value)
526+
# Handle special case for TOOL_CALLS finish reason
527+
if choice.finish_reason is CompletionsFinishReason.TOOL_CALLS:
528+
finish_reason = "function_calls"
526529
else:
527530
if choice.finish_reason in ["stop", "length", "function_calls", "content_filter", "unknown"]:
528531
finish_reason = choice.finish_reason # type: ignore
@@ -554,9 +557,6 @@ async def create_stream(
554557
if finish_reason is None:
555558
raise ValueError("No stop reason found")
556559

557-
if choice and choice.finish_reason is CompletionsFinishReason.TOOL_CALLS:
558-
finish_reason = "function_calls"
559-
560560
content: Union[str, List[FunctionCall]]
561561

562562
if len(content_deltas) > 1:

0 commit comments

Comments
 (0)