Repository navigation
Conversation
Add google and google-vertex providers to config set, with Vertex AI project/location fields. Vertex needs neither an API key nor a base URL; the Gemini API key is read from GEMINI_API_KEY/GOOGLE_API_KEY.
Agent loops run on pydantic-ai's GoogleModel so Gemini 3 thought signatures survive tool-call turns; one-shot calls use the sync google-genai client. Gemini runs record a priced cost_usd.
config validate probes Google access without sending a Gemini key to an OpenAI endpoint; config show lists the Vertex project and location.
The inline create_client(...).models.get() let Python garbage-collect the Client before the request completed, closing the httpx transport.
Same GC issue as check_access: the client created by _client_for() was used inline, so Python could collect it before the HTTP request completed.
- Switching from google/google-vertex to another provider resets the auto-set Gemini fallback model to glm-4p5 unless --fallback-model is given. - call_google reuses one sync genai client per credential set instead of building a client per call; agent-loop models still get a fresh client. - The non-top-tier cluster model hint now names current model families.
Collaborator
|
Thanks @albertsikkema-elix, nice work! I pushed two small commits to your branch to fix minor points. |
Contributor
Author
|
Thanks, glad to help! |
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.
Closes #138.
google(Gemini API / AI Studio) andgoogle-vertex(Vertex AI) as native providers, using the
google-genaiSDKdirectly instead of routing through the OpenAI-compatible shim
round-tripped correctly via pydantic-ai's GoogleModel
$0.32-$22.75 per repo in a four-repo trial)
Changes
New module:
codewiki/src/be/google_provider.pycreate_client(): builds agenai.Clientfor either provider(API key for
google, ADC forgoogle-vertex)create_google_model(): wraps the client in pydantic-ai'sGoogleModelviaGoogleProvider(client=...)(works on bothpydantic-ai 1.x and 2.x)
call_google(): sync one-shot completions (callers run inside anactive event loop, so async
model_request_syncwould deadlock)check_access(): credential validation against the model metadataendpoint
genai-pricesthrough pydantic-ai'sModelResponse.cost()Config changes:
codewiki/src/config.py:google_project,google_locationfields
codewiki/cli/models/config.py: serialization, validation,is_complete()updatescodewiki/cli/config_manager.py: Google-aware validation gating(no API key required for Vertex, no base URL for either)
codewiki/cli/commands/config.py:--provider google|google-vertex,--google-project,--google-locationoptions;config showandconfig validatebranches for Google providersIntegration:
codewiki/src/be/backend.py:GOOGLE_PROVIDERSset,is_google_provider(),needs_api_key(),needs_base_url()codewiki/src/be/llm_services.py: Google branch increate_main_model/create_fallback_model/call_llmcodewiki/src/be/pydantic_ai_backend.py:_run_usage_with_cost()for Google agent-loop cost tracking
pyproject.toml:google-genaidependencyDocs:
guides/providers.md,guides/cli-reference.md,guides/development.md,README.md,CHANGELOG.mdTest results
17 new tests across two files:
tests/test_google_config.py(11 tests): provider config,validation, serialization,
is_complete(),needs_api_key(),needs_base_url()tests/test_google_provider.py(6 tests): model normalisation,client creation,
call_googleusage extraction, cost trackingAll 332 tests pass (existing + new). No changes to existing test
files.
Live tested on Vertex AI (
google-vertex,gemini-3.8-flash,euandgloballocations) against real repositories.Breaking changes
None. Existing providers (openai, anthropic, bedrock) are unaffected.
The
google-genaidependency is new but optional at runtime fornon-Google providers.
Notes for reviewers
GoogleProvider(client=genai.Client(...))is used instead ofGoogleProvider(vertexai=True)because the latter only exists inpydantic-ai 1.x; the client form works on both 1.x and 2.x.
create_client()toprevent the SDK from switching to Express Mode.
created inline) to prevent Python GC from closing the underlying
httpx client mid-request.
trial.shis included for testing convenience but can be excludedfrom the merge if preferred.