Skip to content

Commit

Permalink
fix: Recover the response_format setting in modelbackend (#1484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Jan 22, 2025
1 parent 13fcb21 commit 14ac957
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,18 @@ def step(
)

self.original_model_dict = self.model_backend.model_config_dict
if response_format and self.model_type in {"gpt-4o", "gpt-4o-mini"}:
model_response_format_modified = False
if (
response_format
and self.model_type.support_native_structured_output
):
self.model_backend.model_config_dict = (
self.original_model_dict.copy()
)
self.model_backend.model_config_dict["response_format"] = (
response_format
)
model_response_format_modified = True

# Convert input message to BaseMessage if necessary
if isinstance(input_message, str):
Expand All @@ -604,7 +609,12 @@ def step(
# Add user input to memory
self.update_memory(input_message, OpenAIBackendRole.USER)

return self._handle_step(response_format, self.single_iteration)
try:
return self._handle_step(response_format, self.single_iteration)
finally:
if model_response_format_modified:
# Reset model config back to original state
self.model_backend.model_config_dict = self.original_model_dict

def _inject_tool_prompt(self) -> None:
r"""Generate and add the tool prompt to memory."""
Expand Down

0 comments on commit 14ac957

Please sign in to comment.