Repository navigation
feat(llm): reach every provider LiteLLM supports through one adapter - #99
Open
aditya-drizz wants to merge 1 commit into
Open
aditya-drizz wants to merge 1 commit into
aditya-drizz wants to merge 1 commit into
Conversation
The factory could only build Gemini; naming any other provider raised
NotImplementedError, so LLMConfiguration's provider field was inert.
Adds a gateway adapter rather than one adapter per vendor. LiteLLM already
normalises authentication, endpoints and request shape across providers, so
the only work left is translating between Fathom's neutral types and the
OpenAI-style contract it exposes -- written once, and every provider it
supports comes with it.
Gemini keeps its native adapter. It is the tuned default and uses
provider-specific controls (thinking level, media resolution) that have no
gateway equivalent; those are logged as dropped when a gateway run is
configured with them, so a quality change is attributable rather than
invisible.
Four translations carry the weight:
prompt parts text and raw image bytes become OpenAI content blocks,
with the media type read from the payload's magic bytes
history a model turn carrying tool calls becomes an assistant
message, its arguments re-encoded as JSON
tools declarations are already {name, description, parameters},
so each is wrapped in the tool envelope
tool calls the return path, and the one that matters most --
ToolResponseParser reads .name and .args and expects a
mapping, while the gateway returns a JSON string
That last one reuses FunctionCallPart rather than introducing a type. A
call whose arguments will not parse is dropped with a warning instead of
raising, so one malformed call cannot discard an otherwise usable response.
Cost is deliberately absent from the reported metrics. The gateway prices
from its own table, which drifts from the provider invoice most on image
and cached tokens -- and every step of a run carries a screenshot.
litellm is an optional `gateway` extra, matching the existing per-provider
pattern, so installing Fathom for Gemini alone does not pull it in.
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.
Third of three PRs adding model selection to DrizzAI. This is the one that makes the other two live.
Why
LLMConfigurationhas carriedprovider,modelandapi_keysince it was written, and its docstring says "Supports any backend (Gemini, OpenAI, Anthropic) via provider field." But the factory was:So the field was inert. Naming anything else raised.
One adapter, not one per vendor
LiteLLM already normalises auth, endpoints and request shape across providers. What it cannot do is bridge Fathom's own neutral types to the OpenAI-style contract it exposes — that join is ours, and it's the same join for every provider. Writing it once means Anthropic, OpenAI, Azure and Bedrock all arrive together.
Gemini keeps its native adapter. It's the tuned default and uses
thinking_level/media_resolution, which have no gateway equivalent. When a gateway run is configured with them they're logged as dropped, so a quality change is attributable rather than invisible.The four translations
{name, description, parameters}, so each is wrapped in the envelopeThat last row is where this breaks if it's going to.
ToolResponseParserreads.nameand.argsand expects a mapping; the gateway returns arguments as a JSON string. The industry write-ups on gateway adoption flag exactly this — "a tool call that parsed end to end on the native SDK can come back in a shape your downstream parser does not expect."It reuses
FunctionCallPartrather than introducing a type, since that already has.nameand.argsand is Pydantic. A call whose arguments won't parse is dropped with a warning, not raised — one malformed call shouldn't discard an otherwise usable response.Two deliberate omissions
No cost metric. The gateway prices from its own table, which drifts from the provider invoice — worst on image and cached tokens, and every step of a run carries a screenshot. Reporting a number that doesn't match the bill is worse than reporting none.
prewarmis a no-op. It exists to populate Gemini's context cache. There's no gateway equivalent, and issuing a throwaway request to imitate one would cost a call and buy nothing. Documented in the method rather than left to look like an oversight.Keys
api_keyis forwarded when set, omitted when not — in which case LiteLLM reads the ambient provider environment. That's how the Gemini path already gets its credentials, so end-to-end testing needs an env var on the crawler worker, not key storage.Per-org encrypted keys are a separate, larger piece. The research on this is blunt: "BYOK is a sales-driven re-architecture that ripples through cost attribution, security incident response, observability, rate limiting, model-version pinning, and on-call accountability." Worth doing after the experiment says the swap works, not before.
The plumbing is testable and tested. What isn't knowable from code review is whether Fathom's prompts — written and tuned against Gemini — produce answers of the same quality on Claude or GPT. Note
src/fathom/core/prompts/gemini.pyalready exists, so the team has met provider-specific prompting before.Suggested next step before flipping the desktop flag: take a handful of crawler intents that pass on Gemini, run them on Claude and GPT, compare completion rate and step count. One day, and it's the only way to get that answer.
Tests
tests/integration/adapters/llm/test_gateway.py— 21 new. Model qualification and double-prefix, text/image content blocks, empty image rejected, system instruction ordering, history role mapping, tool envelope wrapping, tool-call name/args translation from both string and mapping, one bad call not discarding good ones, structured-output/tools conflict, usage without cost, no-choices rejection, retry succeeds and is bounded, key forwarded and omitted, lifecycle no-ops, derive.mainbefore this branch and are unaffected —test_ask_user_timeout_closes_step_and_terminatesandtest_adapter_passes_fathom_serde_with_allowed_modules.python -m governancereports one NEW finding, which is also present on cleanmain(AuditColumnsuses@dataclass) and is not from this change.