feat: add LiteLLM as unified LLM provider gateway#5
Closed
RheagalFire wants to merge 3 commits into
Closed
Conversation
Owner
|
Hey I am so sorry I am seeing this message 2 weeks after it was posted. I will get to this ASAP. Thank you for the contribution. |
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
Adds
LiteLLMas a third LLM backend alongsideOpenAILLMandLMStudioLLM, enabling access to 100+ LLM providers (OpenAI, Anthropic, Google, AWS Bedrock, Azure, Groq, Mistral, Cohere, etc.) through the LiteLLM SDK.Changes
plugins/services/service_llm.pyLiteLLM(BaseLLM)class (~150 LOC):invoke(),stream(),chat_with_tools()with lazy litellm import,drop_params=True, image injection, tool call parsing, token usage tracking. Rate limit / auth errors checked by class name beforeis_context_limit_error()heuristic to prevent false positives. Updated_build_llm_from_profile()factory to handle"LiteLLM"class name.requirements.txtlitellm>=1.60,<1.85tests/test_litellm_llm.pyUsage
Add a LiteLLM profile in your config:
{ "llm_profiles": { "anthropic/claude-sonnet-4-6": { "llm_service_class": "LiteLLM", "llm_api_key": "ANTHROPIC_API_KEY", "llm_context_size": 200000 }, "openai/gpt-4o": { "llm_service_class": "LiteLLM", "llm_api_key": "OPENAI_API_KEY", "llm_context_size": 128000 } }, "default_llm_profile": "anthropic/claude-sonnet-4-6" }LiteLLM reads provider-specific env vars automatically (
ANTHROPIC_API_KEY,OPENAI_API_KEY, etc.) or you can passllm_api_keyin the profile config.Direct usage:
Any model string LiteLLM supports works:
Integration bug caught during deep-dive and fixed
is_context_limit_error()uses a heuristic that matches "tokens" + "limit" in error text. LiteLLM's rate limit messages (e.g., "Rate limit exceeded. Quota request exceeds the tokens limit.") contain both words, causing rate limits to be misclassified as context overflow. This would trigger the compact-and-retry path inconversation_loop.pyinstead of surfacing the actual error.Fix: check exception class name (
RateLimitError,AuthenticationError,NotFoundError) before the heuristic, so these deterministic errors short-circuit toprovider_errorinstead of triggering context compaction.Tests
Unit tests: 16/16 pass
Live E2E: Anthropic Claude Sonnet 4-6
Risk / Compatibility
OpenAILLMandLMStudioLLMuntouched.LiteLLMfollows the sameBaseLLMinterface:invoke(),stream(),chat_with_tools()all return the sameLLMResponsetype.litellmis a new dependency inrequirements.txt. Users who don't use it can ignore it._build_llm_from_profile()factory dispatches on"LiteLLM"class name, so existing profiles are unaffected.