- Notifications
You must be signed in to change notification settings - Fork1k
Fix bug where empty messages might be created in the Anthropic model#1027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Can you provide an MRE, please? |
fromanthropicimportAsyncAnthropicfromopenaiimportAsyncOpenAIfrompydantic_aiimportAgentfrompydantic_ai.messagesimportModelRequest,SystemPromptPart,TextPart,ModelResponse,UserPromptPartfrompydantic_ai.models.anthropicimportAnthropicModelfrompydantic_ai.models.openaiimportOpenAIModelasyncdeftest_anthropic_issue()->None:openai_key=""anthropic_key=""models= [ ("OpenAI",OpenAIModel(model_name="gpt-4o-mini",openai_client=AsyncOpenAI(api_key=openai_key))), ("Anthropic",AnthropicModel(model_name="claude-3-7-sonnet-latest",anthropic_client=AsyncAnthropic(api_key=anthropic_key))), ]forname,modelinmodels:print(f"\n\nModel:{name}")agent=Agent(model=model, )messages= [ModelRequest(parts=[SystemPromptPart("Respond with the user's last message in upper-case")]),# ModelRequest(parts=[UserPromptPart(content="Hello")]), <-- Issue does not happen if uncommentedModelResponse(parts=[TextPart(content="HELLO")]), ]awaitagent.run(user_prompt="Test",message_history=messages,result_type=str, ) |
Please convert the MRE into a test |
I've tried to do this without any other changes in the codebase -- it's quite hard. The function is an internal function not accessible without some indirections. One way would be to create a live test, but this seems a bit extreme perhaps. @alexmojaki What would you suggest I do? |
OK then I think it's fine unless@Kludex has some ideas. |
I'll create a test with VCR. |
@Kludex I'm hitting this error on most of our attempts to use Claude 3.7 |
3b12530
intopydantic:mainUh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This PR fixes an issue where empty messages are created.
The error happens when the function
_map_message
runs with this input:The following error is eventually returned from the Anthropic API: