feat(gemini): Gemini provider Phase 1 — basic generateContent chat#1605
Merged
feat(gemini): Gemini provider Phase 1 — basic generateContent chat#1605
Conversation
13 tasks
#1593) New GeminiProvider in crates/zeph-llm/src/gemini.rs: - POST to generateContent with x-goog-api-key header (not ?key= query param) - System prompt extracted to systemInstruction top-level field - Role::Assistant mapped to "model" role - Consecutive same-role message merging (Gemini requires strict alternation) - First-message guard: prepend empty user turn if contents[0] is "model" - JSON serialized once before retry loop (not per-attempt) - HTTP 429 and 503 retried via shared send_with_retry() - context_window() per model family (gemini-2.0-flash/2.5-pro/1.5-pro → 1M/2M tokens) - last_usage() populated from usageMetadata in response - debug_request_json() serializes actual request payload Integration: - ProviderKind::Gemini, GeminiConfig (api_key, model, max_tokens, base_url) - [llm.gemini] TOML config section with commented defaults in config/default.toml - ZEPH_GEMINI_API_KEY vault key resolution - AnyProvider::Gemini and SubProvider::Gemini variants wired in all match blocks - Bootstrap provider.rs: all 4 creation functions + build_orchestrator - --init wizard: Gemini option in provider selection with api_key prompt - instructions.rs: Gemini → AGENTS.md detection path Also fix send_with_retry() to retry HTTP 503 (SERVICE_UNAVAILABLE) alongside 429, benefiting all providers. 128 new tests (5032 → 5160), including 3 wiremock end-to-end HTTP tests. Closes #1593. Part of epic #1592.
72f82f3 to
b4a4ede
Compare
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 #1593. Part of epic #1592.
Summary
GeminiProviderincrates/zeph-llm/src/gemini.rs— basicgenerateContentchat via Google Gemini APIx-goog-api-keyheader (not?key=URL query param — avoids key leakage in DEBUG logs)systemInstructiontop-level field;Role::Assistant→"model"roleuser/modelalternation)contents[0].role == "model", a synthetic empty user turn is prependedbase_url,model(defaultgemini-2.0-flash),max_tokenssend_with_retry()ProviderKind::Gemini,[llm.gemini]config section,ZEPH_GEMINI_API_KEYvault key--initwizard updated with Gemini provider optionsend_with_retry()to retry HTTP 503 alongside 429 (benefits all providers)Test plan
LlmError::OtherRESOURCE_EXHAUSTED→LlmError::RateLimitedusageMetadata→last_usage()populatedcargo +nightly fmt --check: passcargo clippy --workspace --features full -- -D warnings: 0 warningscargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins: 5160 passed