feat: add LiteLLM as unified LLM provider gateway - #134
Conversation
|
cc @zh-plus |
|
Thanks for putting this together — LiteLLM support is a great addition to the project! The branch looks like it needs a rebase onto current master before merging, as the diff includes some unrelated changes from branch divergence. On the implementation itself, a few suggestions: 1. Missing non-retryable error types. It would be nice to add 2. The 3. if proxy:
logger.warning(
"LiteLLMBot does not support per-instance proxy. "
"Set HTTP_PROXY/HTTPS_PROXY environment variables instead."
)4. Everything else looks clean. |
2effaef to
2ffd3e6
Compare
|
Thanks for the detailed review! Pushed fixes addressing all 4 points:
|
| def _get_sleep_time(error): | ||
| qualname = type(error).__name__ | ||
| if qualname == "RateLimitError": | ||
| return random.randint(30, 60) |
Summary
Adds
LiteLLMBotas a fourth chatbot provider alongsideGPTBot,ClaudeBot, andGeminiBot, enabling access to 100+ LLM providers (OpenAI, Anthropic, Google, AWS Bedrock, Azure, Groq, Mistral, Cohere, etc.) through a singlelitellm:model prefix.Supersedes PR #12 (ishaan-jaff, Aug 2023, closed). The original was closed because "the translation prompt is only compatible with OpenAI's models" -- that limitation no longer applies since the repo now has native Anthropic and Google support. This PR builds on the current multi-provider architecture.
Changes
openlrc/chatbot.pyLiteLLMBot(ChatBot)class (120 LOC): lazy litellm import,drop_params=True, temperature/top_p conflict guard, retry with provider-specific exception handling, fee tracking via OpenAI-format usage. Updatedroute_chatbot()to handle"litellm:"prefix. Updatedprovider2chatbotdict.openlrc/models.pyModelProvider.LITELLMenum value andDefaultLiteLLMModelInfofallback class for unknown LiteLLM-routed models.pyproject.tomllitellm = ["litellm>=1.60,<1.85"]optional dependency.tests/test_litellm_bot.pyUsage
Install:
pip install "openlrc[litellm]"Set the credential for whatever backing provider you want:
Use the
litellm:prefix when specifying the model:Direct chatbot usage:
Prior art
ChatBotarchitecture that was added since then.Tests
Unit tests: 24 passed, 5 skipped (pre-existing live API skips)
Lint: ruff check + format clean
Live E2E: Anthropic Claude Sonnet 4-6
Edge cases handled
drop_params=Truedoes not catch this (both are individually valid). Fix: only forwardtop_pwhentemperatureis at its default (1.0).""instead of crashing whenresponse.choices[0].message.contentisNone.AuthenticationErrorandBadRequestErrorraise immediately; only transient errors (rate limit, timeout, 5xx) are retried with backoff.response.usage.prompt_tokens/completion_tokensfrom LiteLLM's normalized response.litellmis imported inside_create_chat()only, so users who don't installopenlrc[litellm]are unaffected.