Repository navigation
fix(py/google-genai): built-in + function tools, media URL validation, context cache, and timeout floor - #117
Open
huangjeff5 wants to merge 7 commits into
Open
huangjeff5 wants to merge 7 commits into
huangjeff5 wants to merge 7 commits into
Conversation
…s, and raise FAILED_PRECONDITION without a Vertex project Locks the response and error shapes callers will read after 1.0. - Candidate metadata: groundingMetadata, urlContextMetadata, citationMetadata, logprobsResult, safetyRatings, avgLogprobs, finishMessage and tokenCount land at custom['candidates'][i] for one-shot and streamed calls; promptFeedback stays at custom['promptFeedback']. Streamed logprobs and citations concatenate, grounding merges key by key, safetyRatings update per category. ModelResponse.finish_message carries candidate 0's finishMessage. - Streamed final message: adjacent text and reasoning fragments merge into one Part each; a fragment with a thought signature closes its block and keeps the signature. Chunks still stream unchanged. - thoughtSignature round-trips on text, media, executableCode and codeExecutionResult parts. fileData in a reply becomes a media part, a signature-only part becomes signed empty text, and the Language/Outcome enums in custom are wire strings. A malformed signature is INVALID_ARGUMENT. Gemma history drops reasoning parts and signatures, and messages left empty are skipped. - VertexAI with no project (regional, multi-region, or a per-request override) raises GenkitError FAILED_PRECONDITION at call time instead of google-genai's bare ValueError, which Retry treated as transient. Multi-region no longer raises ValueError at construction.
…ntext cache, and timeout floor Bug fixes and edge-case hardening split out of #50. No response-shape or config-schema changes beyond the custom.geminiToolCall and custom.geminiToolResponse parts that only appear once built-in and function tools can share a turn. - Built-in tools next to function tools: on the Gemini API, turns that mix google_search, url_context, code_execution or file_search with function declarations set toolConfig.includeServerSideToolInvocations. The server-side toolCall/toolResponse parts round-trip as custom.geminiToolCall/geminiToolResponse with their signature. google-genai AFC is disabled whenever tools are sent. - Media: data: URIs with no ',' or bad base64 raise INVALID_ARGUMENT; non-base64 data: URIs are percent-decoded. file://, local paths and scheme-less strings raise INVALID_ARGUMENT without echoing the value. gzip/deflate downloads are decoded with the 20MB cap applied after decoding. The caller's content_type beats a generic served type. Tool-response media errors propagate instead of being skipped. - Context cache: no model allowlist; context_cache=False ignores metadata['cache'] markers; built-in tools on a cached request raise INVALID_ARGUMENT upfront. - Timeouts: on the Gemini API, X-Server-Timeout is floored at 10s while httpx keeps the shorter local deadline. Interactions drop the synthetic floor header. Case-variant custom headers replace instead of concatenating. - Request building skips parts with no Gemini field (Part.data), and dict config reads camelCase api_version/base_url/location.
…out floor and server-side tool flag Keyless GoogleAI() (#49) has no plugin client, so self._client.vertexai raised AttributeError on a context.secrets call that mixed built-in and function tools or set a timeout. _is_vertex() falls back to the plugin kwargs.
…alescing, and Vertex project
- Sum logProbabilitySum and tokenCount across stream chunks; token-weight avgLogprobs.
- Join coalesced stream fragments once per run instead of per fragment.
- Decode URL-safe and unpadded thought signatures; drop undecodable ones with a warning.
- Restore ADC project pickup for VertexAI(api_key=..., location=<multi-region>).
- Route Veo and Virtual Try-On per-request clients through the shared builder.
- README: custom is {} when Gemini sends no metadata.
# Conflicts: # packages/genkit-google-genai/src/genkit_google_genai/_google.py # packages/genkit-google-genai/tests/vertexai_location_test.py
…o HEAD # Conflicts: # packages/genkit-google-genai/tests/part_converter_test.py
# Conflicts: # packages/genkit-google-genai/src/genkit_google_genai/_models/_gemini.py # packages/genkit-google-genai/src/genkit_google_genai/_models/_utils.py # packages/genkit-google-genai/tests/part_converter_fidelity_test.py # packages/genkit-google-genai/tests/part_converter_test.py # packages/genkit-google-genai/tests/vertexai_project_test.py
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug fixes and edge-case hardening split out of #50, stacked on it. Built-in tools now work next to
@ai.tool()functions on Gemini 3, bad media URLs fail before the call instead of in Gemini's 400, context caching works on current model IDs, and shorttimeoutvalues stop 400ing on the Gemini API.Main Changes
google_searchplus@ai.tool()) failed with a 400, andextra=couldn't work around it because the field is plugin-managed. Turns that mixgoogle_search,url_context,code_execution, orfile_searchwith function declarations now settoolConfig.includeServerSideToolInvocations=Trueon the Gemini API (Vertex AI has no such field). The server-sidetoolCall/toolResponseparts come back ascustom.geminiToolCall/custom.geminiToolResponse(JS parity) so the next turn can send them back unchanged. google-genai's automatic function calling is disabled whenever tools are sent, since Genkit runs tools itself.file://URIs, and raw base64 went to Gemini asfileDataand came back in a 400 with the value echoed; adata:URI with no,raised a rawValueError. These now raiseINVALID_ARGUMENTnaming the fix (data:URI or uploaded file URI) without the value. Downloads accept gzip/deflate with the 20 MB cap applied after decoding, so a small body can't expand past it. The caller'scontent_typebeats a generic servedapplication/octet-stream, which object stores often send and Gemini rejects.context_cache=False: Previously, caching was limited to a hardcoded list of three model IDs (two retired), andGeminiConfig.context_cachewas read and dropped. The allowlist is gone (the API rejects models that can't cache),Falseignoresmetadata['cache']markers for the call, and built-in tools on a cached request raiseINVALID_ARGUMENTupfront, as function tools already did.GoogleAIstop 400ing: Previously,timeout=5sentX-Server-Timeout: 5, and the Gemini API answers 400 to anything under 10 instead of timing out. The header is now floored at 10 while httpx keeps the exact local deadline, so a 5s timeout succeeds or fails withDEADLINE_EXCEEDEDafter 5s. Vertex AI accepts shorter values and is unchanged; Interactions models drop the synthetic floor so long runs aren't capped.Breaking changes
None.
custom.geminiToolCall/custom.geminiToolResponseparts only appear on turns that 400ed before this change.Cross-SDK
The server-side tool parts use the JS plugin's
custom.geminiToolCall/custom.geminiToolResponsekeys. No changes needed in JS, Go, or Dart.