feat: route LLM calls through LiteLLM for multi-provider support - #9
Open
prodmanpd wants to merge 3 commits into
Open
feat: route LLM calls through LiteLLM for multi-provider support#9prodmanpd wants to merge 3 commits into
prodmanpd wants to merge 3 commits into
Conversation
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.
Summary
Routes Cortex's LLM and embedding calls through the LiteLLM SDK instead of a hardcoded
anthropicclient and a hardcoded OpenAI embeddings path, so Cortex can run on any provider LiteLLM supports (Anthropic, OpenAI, Gemini, Bedrock, Vertex, Azure, Voyage, Cohere, or a LiteLLM proxy) via one interface.claude-opus-4-5) for generation, and the embedding provider selection (model2vec, openai, hash) is unchanged. Existing setups keep working with no config change.CORTEX_MODEL(for exampleopenai/gpt-4o,gemini/gemini-2.5-pro,bedrock/...); pick any embedding provider by settingCORTEX_EMBEDDING_PROVIDER=litellmand a provider prefixedCORTEX_EMBEDDING_MODEL(for examplevoyage/voyage-3,cohere/embed-english-v3.0,gemini/text-embedding-004). Credentials come from each provider's own env var.drop_params=Trueon every call, so one config works across providers that reject each other's params.Changes
ui.py:ask_cortex()now callslitellm.completion(...); model fromCORTEX_MODEL.ingest.py: extraction call now useslitellm.completion(...).backend/app/condense.py: condense call now useslitellm.completion(...)backend/app/extractor.py:_extract_with_claudenow useslitellm.completion(...)Embeddings
backend/app/embeddings.py: addslitellmas aCORTEX_EMBEDDING_PROVIDERoption backed bylitellm.embedding(new_litellm_embedding). model2vec, openai, and hash paths are untouched. Keeps the existing safety net: a dimension mismatch raises so retrieval degrades to the deterministic hash embedding (or fails in strict mode) rather than corrupting the vector index. OptionalCORTEX_LITELLM_BASE_URLandCORTEX_LITELLM_API_KEYpoint at a LiteLLM proxy.Packaging
requirements.txt,backend/requirements.txt: addlitellm>=1.89.0,<2.0.0Tests
1. Compile:
python -m py_compile ui.py ingest.py backend/app/condense.py backend/app/extractor.py backend/app/embeddings.pygives OK.2. Live call through a converted chat path (the exact
litellm.completionshape the four sites use, a system prompt plus a single user turn,drop_params=True), against a live model via a LiteLLM proxy:3. Embedding provider route (litellm stubbed, no network):
This confirms
CORTEX_EMBEDDING_PROVIDER=litellmroutes throughlitellm.embedding, forwards an output dimension only fortext-embedding-3models, and degrades to hash on a dimension mismatch so the index stays consistent.4. Pin resolves cleanly:
pip install "litellm>=1.89.0,<2.0.0"Risk and compatibility
ANTHROPIC_API_KEYandOPENAI_API_KEYsetups keep working.anthropicstays a dependency; the app no longer instantiates the Anthropic client directly.Example usage