Repository navigation
fix(py/google-genai): accept custom httpx clients in http_options - #6695
Closed
huangjeff5 wants to merge 3 commits into
Closed
huangjeff5 wants to merge 3 commits into
huangjeff5 wants to merge 3 commits into
Conversation
GoogleAI/VertexAI deep-copied the caller's HttpOptions, so a user httpx_client / httpx_async_client (RLock inside) raised "TypeError: cannot pickle '_thread.RLock' object" at construction. copy_http_options gives the copy fresh headers/client_args/extra_body/ retry_options and shares the transport clients by reference. Plugin setup and per-request base_url/api_version/location overrides still leave the caller's object untouched.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a copy_http_options helper function to safely copy HttpOptions while keeping transport clients (like httpx and aiohttp clients) shared, preventing deep-copy errors. This helper is integrated across Gemini, Veo, and Google GenAI models, and comprehensive tests are added. Feedback suggests making the copying of retry_options more robust by checking for the model_copy attribute to prevent potential AttributeErrors if a dictionary is passed instead of a model instance.
…ions-client # Conflicts: # py/packages/genkit-google-genai/src/genkit_google_genai/_models/_gemini.py
Contributor
Author
|
Superseded by #6826: GoogleAI/VertexAI now take http_client= directly instead of the SDK's HttpOptions. |
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.
GoogleAIandVertexAInow accept a caller-ownedhttpxclient inhttp_optionsand route every request through it. Previously, passing one crashed at plugin construction.google-genaisupportsHttpOptions(httpx_async_client=...)for proxies, mTLS, and custom transports. The plugin previously calledmodel_copy(deep=True)onhttp_optionsin three places so plugin-added headers would never mutate the caller's object, which attempted to pickle thehttpxclient's internal_thread.RLock.Decisions
copy_http_options()replaces the threemodel_copy(deep=True)calls in_google.py,_gemini.py, and_veo.py. It makes a shallow copy with freshheaders,client_args, andasync_client_argsdicts, deep-copies only the JSON-shapedextra_bodyandretry_options, and keepshttpx_client,httpx_async_client, andaiohttp_clientby reference. Sharing the client reference is safe becausegoogle-genaidoes not close caller-supplied clients when disposing of a per-request client.base_url,api_version, andlocationoverrides write to the copied container dicts, so a caller'sHttpOptionsinstance (which may be shared across plugin instances) is never mutated.