Repository navigation
feat(providers): gemini + ollama backends, fakes, and live smoke script (T04) - #5
Merged
Merged
Conversation
…pt (T04) - ChatBackend/EmbeddingBackend protocols, ChatResult/Usage, typed ProviderError (quota_exhausted | provider_unavailable), bounded 429 exponential backoff (max 5 retries, 1s..60s cap), L2 normalization, <=100-text batching, and prices.json (as_of 2026-11-16, per 9.8) - Gemini via google-genai (config-pinned answer/embedding models, RETRIEVAL_DOCUMENT/RETRIEVAL_QUERY task types); Ollama via httpx (qwen2.5:7b-instruct + nomic-embed-text), injectable transport - get_chat/get_embeddings factories read CALIPER_PROVIDER, GEMINI_API_KEY, OLLAMA_BASE_URL from env (11.2); 768-dim enforcement before any call - tests/fakes.py: scripted FakeChat (paraphrased-quote + refusal cases) and deterministic hash-based FakeEmbeddings (768-dim, correlated) - scripts/smoke.py: manual live smoke per backend + 429 backoff demo, exits nonzero with the 9 error envelope on failure - 30 new unit tests; pytest/ruff/mypy strict all green
google-genai's Models object holds only a weak reference to its Client: dropping the Client makes every request fail with 'Cannot send a request, as the client has been closed'. get_chat/get_embeddings and scripts/smoke.py now build a GeminiSession that owns the Client, and the Gemini backends store it (keepalive slot). Found by the live smoke run; proven by the gemini leg passing (chat + 768-dim normalized embed + cost + backoff demo).
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.
Task T04 from docs/ARCHITECTURE.md §14.2 (spec §7.2, §9.8, §15).
What
src/caliper/providers/:base.py(protocols,ProviderError,Usage/ChatResult,estimate_cost+prices.jsonwithas_of,l2_normalize, ≤100-text batching, bounded exponential backoff on 429 — max 5 retries thenquota_exhausted),gemini.py(google-genai; RETRIEVAL_DOCUMENT/QUERY; client-side L2 normalization of all 768-dim vectors),ollama.py(httpx;qwen2.5:7b-instruct/nomic-embed-text), factoriesget_chat(cfg)/get_embeddings(cfg)readingCALIPER_PROVIDER/GEMINI_API_KEY/OLLAMA_BASE_URLfrom env (§11.2). Model IDs/temperature/seed always come from config — never hardcoded.tests/fakes.py: the suite's only mocks per §15 — scriptedFakeChat(paraphrased-quote + refusal cases) and deterministic hash-basedFakeEmbeddings(768-dim, L2-normalized). Foundation for T09–T14.scripts/smoke.py: manual live smoke (§15 — human-run, never in CI): one chat + one 768-dim normalized embed per backend, cost estimate, 429 backoff demo, §9 envelope exit codes.tests/conftest.py: putstests/onsys.pathsofakes.pyis importable from every test dir (smallest mechanism; avoids touching T01-ownedpyproject.toml). Recorded in docs/TASKS.md Notes.Notable fix found by the live smoke
89e5423: google-genai'sModelsholds only a weak reference to itsClient— dropping the client fails every request ("client has been closed").GeminiSessionnow owns thegenai.Clientfor both factories and the smoke script. Without this the production ask path (T11/T12) would have broken on the first GC.Verification
uv run pytest97 passed (30 new; no network — retry/backoff via injectable sleep/transport, nopatch()anywhere);ruff check,ruff format --check,mypystrict all clean.gemini-3.5-flash-lite, embed OK 768-dim norm 1.000000, cost estimated, 429 backoff demo logged. Ollama leg deferred (Ollama not installed; user decision recorded in docs/TASKS.md) — re-runuv run python scripts/smoke.pyafterollama pull qwen2.5:7b-instruct+nomic-embed-text.gemini-3.5-flash-litefree-tier RPD in AI Studio; log in §18.Dependent tasks (per §14.4)
T05–T08 (ingest) consume
get_embeddings/iter_batches; T09–T12 consumeget_chatandtests/fakes.py; T14's cost metrics consumeestimate_cost/prices.json. Dependents: re-run tests after this merges.