Feat/add litellm provider - #53
Open
prodmanpd wants to merge 4 commits into
Open
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
Add LiteLLM as a provider with a native SDK code path, giving users direct access to 100+ LLM providers (Anthropic, Google, Azure, Bedrock, Groq, Ollama, and more) for document translation without needing an OpenAI-compatible proxy.
Changes
docutranslate/agents/agent.py- Added_call_litellm_sync()and_call_litellm_async()methods that uselitellm.completion()/litellm.acompletion()instead of raw httpx POST. All 4 HTTP call sites patched (send, send_async, _continue_fetch, _continue_fetch_async) to route through litellm whenprovider == "litellm"docutranslate/agents/provider/provider.py- Added"litellm"toProviderTypedocutranslate/agents/thinking/thinking_factory.py- Added thinking mode delegation by model name for litellmtests/test_litellm_provider.py- 8 unit testsImplementation details
When
--provider litellmis set, the Agent bypasses raw httpx and calls litellm's SDK directly:drop_params=Truesilently handles cross-provider parameter incompatibilities (e.g.frequency_penaltyrejected by Anthropic,response_formatrejected by some providers)litellm.acompletion()used for async path so concurrent translation batches workANTHROPIC_API_KEY,OPENAI_API_KEY, etc.)qwen-plusgets Qwen'senable_thinking,gemini-2.5-flashgets Google'sreasoning_effort)model_dump()'d to dict so existing token counting and response parsing works unchangedTests
8 unit tests covering provider detection, thinking mode delegation, and type system.
Full regression: 64 passed (56 existing + 8 new), 0 failures.
Example usage
Risk / Compatibility
provider == "litellm"litellmis imported lazily inside the method bodies