-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Transform and to text parts for Google models that don't support tools #3591
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4307,6 +4307,7 @@ def test_google_thought_signature_on_thinking_part(): | |
| provider_name='google-gla', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| new_google_response = _content_model_response( | ||
| ModelResponse( | ||
|
|
@@ -4318,6 +4319,7 @@ def test_google_thought_signature_on_thinking_part(): | |
| provider_name='google-gla', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| assert old_google_response == snapshot( | ||
| { | ||
|
|
@@ -4342,6 +4344,7 @@ def test_google_thought_signature_on_thinking_part(): | |
| provider_name='google-gla', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| new_google_response = _content_model_response( | ||
| ModelResponse( | ||
|
|
@@ -4352,6 +4355,7 @@ def test_google_thought_signature_on_thinking_part(): | |
| provider_name='google-gla', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| assert old_google_response == snapshot( | ||
| { | ||
|
|
@@ -4376,6 +4380,7 @@ def test_google_thought_signature_on_thinking_part(): | |
| provider_name='google-gla', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| new_google_response = _content_model_response( | ||
| ModelResponse( | ||
|
|
@@ -4386,6 +4391,7 @@ def test_google_thought_signature_on_thinking_part(): | |
| provider_name='google-gla', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| assert old_google_response == snapshot( | ||
| { | ||
|
|
@@ -4412,6 +4418,7 @@ def test_google_missing_tool_call_thought_signature(): | |
| provider_name='openai', | ||
| ), | ||
| 'google-gla', | ||
| True, | ||
| ) | ||
| assert google_response == snapshot( | ||
| { | ||
|
|
@@ -4425,3 +4432,22 @@ def test_google_missing_tool_call_thought_signature(): | |
| ], | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def test_google_mapping_when_does_not_support_tools(): | ||
|
||
| google_response = _content_model_response( | ||
| ModelResponse( | ||
| parts=[ | ||
| ToolCallPart(tool_name='tool', args={}, tool_call_id='tool_call_id'), | ||
| ], | ||
| provider_name='openai', | ||
| ), | ||
| 'google-gla', | ||
| False, | ||
| ) | ||
| assert google_response == snapshot( | ||
| { | ||
| 'role': 'model', | ||
| 'parts': [{'text': 'Tool tool called with args {}'}], | ||
| } | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the arguments and return value can be very long, I want those on a separate line.
Also because there could be parallel tool calls with the same name, we should include the tool call ID.
I'd also want to format this in a more special way so the model understands this is not actually a user/assistant "message".
So I suggest doing something similar to how we send text files to OpenAI:
pydantic-ai/pydantic_ai_slim/pydantic_ai/models/openai.py
Lines 1006 to 1014 in c27e5e4
And we're doing that for Google as well: #3269.