Skip to content

Drop JSON schema url from schema on Gemini #1342

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged
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
9 changes: 4 additions & 5 deletions pydantic_ai_slim/pydantic_ai/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ async def request(
async with self._make_request(
messages, False, cast(GeminiModelSettings, model_settings or {}), model_request_parameters
) as http_response:
response = _gemini_response_ta.validate_json(await http_response.aread())
data = await http_response.aread()
response = _gemini_response_ta.validate_json(data)
Comment on lines +138 to +139
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had to do this many times, since I use breakpoint().

return self._process_response(response), _metadata_as_usage(response)

@asynccontextmanager
Expand Down Expand Up @@ -640,10 +641,7 @@ class _GeminiFunction(TypedDict):

def _function_from_abstract_tool(tool: ToolDefinition) -> _GeminiFunction:
json_schema = _GeminiJsonSchema(tool.parameters_json_schema).simplify()
f = _GeminiFunction(
name=tool.name,
description=tool.description,
)
f = _GeminiFunction(name=tool.name, description=tool.description)
if json_schema.get('properties'):
f['parameters'] = json_schema
return f
Expand Down Expand Up @@ -770,6 +768,7 @@ def simplify(self) -> dict[str, Any]:
def _simplify(self, schema: dict[str, Any], refs_stack: tuple[str, ...]) -> None:
schema.pop('title', None)
schema.pop('default', None)
schema.pop('$schema', None)
schema.pop('exclusiveMaximum', None)
schema.pop('exclusiveMinimum', None)
if ref := schema.pop('$ref', None):
Expand Down