Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/builtin-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ The [`ImageGenerationTool`][pydantic_ai.builtin_tools.ImageGenerationTool] enabl
| Provider | Supported | Notes |
|----------|-----------|-------|
| OpenAI Responses | ✅ | Full feature support. Only supported by models newer than `gpt-5`. Metadata about the generated image, like the [`revised_prompt`](https://platform.openai.com/docs/guides/tools-image-generation#revised-prompt) sent to the underlying image model, is available on the [`BuiltinToolReturnPart`][pydantic_ai.messages.BuiltinToolReturnPart] that's available via [`ModelResponse.builtin_tool_calls`][pydantic_ai.messages.ModelResponse.builtin_tool_calls]. |
| Google | ✅ | No parameter support. Only supported by [image generation models](https://ai.google.dev/gemini-api/docs/image-generation) like `gemini-2.5-flash-image`. These models do not support [structured output](output.md) or [function tools](tools.md). These models will always generate images, even if this built-in tool is not explicitly specified. |
| Google | ✅ | No parameter support. Only supported by [image generation models](https://ai.google.dev/gemini-api/docs/image-generation) like `gemini-2.5-flash-image` and `gemini-3-pro-image-preview`. These models do not support [function tools](tools.md). These models will always have the option of generating images, even if this built-in tool is not explicitly specified. |
| Anthropic | ❌ | |
| Groq | ❌ | |
| Bedrock | ❌ | |
Expand Down
2 changes: 2 additions & 0 deletions pydantic_ai_slim/pydantic_ai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
'google-gla:gemini-2.5-flash-lite-preview-09-2025',
'google-gla:gemini-2.5-pro',
'google-gla:gemini-3-pro-preview',
'google-gla:gemini-3-pro-image-preview',
'google-vertex:gemini-flash-latest',
'google-vertex:gemini-flash-lite-latest',
'google-vertex:gemini-2.0-flash',
Expand All @@ -167,6 +168,7 @@
'google-vertex:gemini-2.5-flash-lite-preview-09-2025',
'google-vertex:gemini-2.5-pro',
'google-vertex:gemini-3-pro-preview',
'google-vertex:gemini-3-pro-image-preview',
'grok:grok-2-image-1212',
'grok:grok-2-vision-1212',
'grok:grok-3',
Expand Down
10 changes: 8 additions & 2 deletions pydantic_ai_slim/pydantic_ai/models/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
'gemini-2.5-flash-lite-preview-09-2025',
'gemini-2.5-pro',
'gemini-3-pro-preview',
'gemini-3-pro-image-preview',
]
"""Latest Gemini models."""

Expand Down Expand Up @@ -420,7 +421,7 @@ async def _build_content_and_config(
model_request_parameters: ModelRequestParameters,
) -> tuple[list[ContentUnionDict], GenerateContentConfigDict]:
tools = self._get_tools(model_request_parameters)
if tools and not self.profile.supports_tools:
if model_request_parameters.function_tools and not self.profile.supports_tools:
raise UserError('Tools are not supported by this model.')

response_mime_type = None
Expand Down Expand Up @@ -559,7 +560,7 @@ async def _map_messages(
)
elif isinstance(part, RetryPromptPart):
if part.tool_name is None:
message_parts.append({'text': part.model_response()}) # pragma: no cover
message_parts.append({'text': part.model_response()})
else:
message_parts.append(
{
Expand Down Expand Up @@ -741,6 +742,11 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
if maybe_event is not None: # pragma: no branch
yield maybe_event
elif part.inline_data is not None:
if part.thought: # pragma: no cover
# Per https://ai.google.dev/gemini-api/docs/image-generation#thinking-process:
# > The model generates up to two interim images to test composition and logic. The last image within Thinking is also the final rendered image.
# We currently don't expose these image thoughts as they can't be represented with `ThinkingPart`
continue
data = part.inline_data.data
mime_type = part.inline_data.mime_type
assert data and mime_type, 'Inline data must have data and mime type'
Expand Down
4 changes: 2 additions & 2 deletions pydantic_ai_slim/pydantic_ai/profiles/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def google_model_profile(model_name: str) -> ModelProfile | None:
return GoogleModelProfile(
json_schema_transformer=GoogleJsonSchemaTransformer,
supports_image_output=is_image_model,
supports_json_schema_output=not is_image_model,
supports_json_object_output=not is_image_model,
supports_json_schema_output=is_3_or_newer or not is_image_model,
supports_json_object_output=is_3_or_newer or not is_image_model,
supports_tools=not is_image_model,
google_supports_native_output_with_builtin_tools=is_3_or_newer,
)
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading