Enforce json for non reasoning anthropic models even in deepthought

This commit is contained in:
Debanjum
2025-06-05 03:15:04 -07:00
parent d2c7e5516f
commit 7f6db526c3

View File

@@ -73,7 +73,7 @@ def anthropic_completion_with_backoff(
if response_schema: if response_schema:
tool = create_anthropic_tool_definition(response_schema=response_schema) tool = create_anthropic_tool_definition(response_schema=response_schema)
model_kwargs["tools"] = [tool] model_kwargs["tools"] = [tool]
elif response_type == "json_object" and not deepthought: elif response_type == "json_object" and not (is_reasoning_model(model_name) and deepthought):
# Prefill model response with '{' to make it output a valid JSON object. Not supported with extended thinking. # Prefill model response with '{' to make it output a valid JSON object. Not supported with extended thinking.
formatted_messages.append(anthropic.types.MessageParam(role="assistant", content="{")) formatted_messages.append(anthropic.types.MessageParam(role="assistant", content="{"))
aggregated_response += "{" aggregated_response += "{"