mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
fix chat_options in kwargs error path in responses client (#483)
This commit is contained in:
committed by
GitHub
Unverified
parent
32c26c3c25
commit
7942a52ca1
@@ -499,6 +499,7 @@ class ChatClientBase(AFBaseModel, ABC):
|
||||
Returns:
|
||||
A chat response from the model.
|
||||
"""
|
||||
# Should we merge chat options instead of ignoring the input params?
|
||||
if "chat_options" in kwargs:
|
||||
chat_options = kwargs.pop("chat_options")
|
||||
if not isinstance(chat_options, ChatOptions):
|
||||
@@ -579,6 +580,7 @@ class ChatClientBase(AFBaseModel, ABC):
|
||||
Yields:
|
||||
A stream representing the response(s) from the LLM.
|
||||
"""
|
||||
# Should we merge chat options instead of ignoring the input params?
|
||||
if "chat_options" in kwargs:
|
||||
chat_options = kwargs.pop("chat_options")
|
||||
if not isinstance(chat_options, ChatOptions):
|
||||
|
||||
@@ -1792,11 +1792,14 @@ class ChatOptions(AFBaseModel):
|
||||
if not isinstance(other, ChatOptions):
|
||||
return self
|
||||
other_tools = other.tools
|
||||
# tool_choice has a specialized serialize method. Save it here so we can fix it later.
|
||||
tool_choice = other.tool_choice or self.tool_choice
|
||||
updated_values = other.model_dump(exclude_none=True, exclude={"tools"})
|
||||
logit_bias = updated_values.pop("logit_bias", {})
|
||||
metadata = updated_values.pop("metadata", {})
|
||||
additional_properties = updated_values.pop("additional_properties", {})
|
||||
combined = self.model_copy(update=updated_values)
|
||||
combined.tool_choice = tool_choice
|
||||
combined.logit_bias = {**(combined.logit_bias or {}), **logit_bias}
|
||||
combined.metadata = {**(combined.metadata or {}), **metadata}
|
||||
combined.additional_properties = {**(combined.additional_properties or {}), **additional_properties}
|
||||
|
||||
@@ -166,7 +166,8 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
|
||||
)
|
||||
)
|
||||
|
||||
chat_options = ChatOptions(
|
||||
return await super().get_response(
|
||||
messages=messages,
|
||||
max_tokens=max_tokens,
|
||||
response_format=response_format,
|
||||
seed=seed,
|
||||
@@ -177,11 +178,6 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
|
||||
top_p=top_p,
|
||||
user=user,
|
||||
additional_properties=additional_properties,
|
||||
)
|
||||
|
||||
return await super().get_response(
|
||||
messages=messages,
|
||||
chat_options=chat_options,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
@@ -262,7 +258,8 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
|
||||
)
|
||||
)
|
||||
|
||||
chat_options = ChatOptions(
|
||||
async for update in super().get_streaming_response(
|
||||
messages=messages,
|
||||
max_tokens=max_tokens,
|
||||
response_format=response_format,
|
||||
seed=seed,
|
||||
@@ -273,11 +270,6 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
|
||||
top_p=top_p,
|
||||
user=user,
|
||||
additional_properties=additional_properties,
|
||||
)
|
||||
|
||||
async for update in super().get_streaming_response(
|
||||
messages=messages,
|
||||
chat_options=chat_options,
|
||||
**kwargs,
|
||||
):
|
||||
yield update
|
||||
|
||||
Reference in New Issue
Block a user