feat: add LiteLLM as AI gateway provider#157
Open
RheagalFire wants to merge 1 commit intohydropix:mainfrom
Open
feat: add LiteLLM as AI gateway provider#157RheagalFire wants to merge 1 commit intohydropix:mainfrom
RheagalFire wants to merge 1 commit intohydropix:mainfrom
Conversation
Author
|
cc @hydropix |
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
anthropic/claude-sonnet-4-6,bedrock/anthropic.claude-v2)Motivation
TranslateBooksWithLLMs already supports 7 providers through individual implementations. LiteLLM adds a unified gateway that handles provider-specific API differences, parameter translation, and authentication —
letting users access any of 100+ providers without needing a separate adapter implementation for each.
Changes
src/core/llm/providers/litellm.py— NewLiteLLMProviderextendingLLMProviderABC withgenerate(), retry logic with transient error detection, and context overflow handlingsrc/core/llm/factory.py— Added"litellm"case tocreate_llm_provider()factoryrequirements.txt— Added commented optionallitellm>=1.65,<1.85dependencytests/unit/test_litellm_provider.py— 4 unit tests covering completion dispatch, credential forwarding, system prompt handling, and factory integrationTests
1. Unit tests:
pytest tests/unit/test_litellm_provider.py -vtests/unit/test_litellm_provider.py::test_generate_calls_acompletion PASSED
tests/unit/test_litellm_provider.py::test_generate_omits_blank_credentials PASSED
tests/unit/test_litellm_provider.py::test_generate_forwards_system_prompt PASSED
tests/unit/test_litellm_provider.py::test_factory_creates_litellm_provider PASSED
4 passed in 0.12s
Risk / Compatibility
litellmis optional — not added to core requirementsgenerate()to avoid import errors when not installeddrop_params=Trueby default for cross-provider kwarg compatibilityExample usage
Or via CLI: set LLM_PROVIDER=litellm and MODEL=anthropic/claude-sonnet-4-6 in your .env.