feat: add LiteLLM as LLM provider#64
Open
RheagalFire wants to merge 1 commit into
Open
Conversation
Author
|
cc @melih-unsal |
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
LiteLLMChatModelfor agents/RAG) and the chains layer (viacreate_llm()factory)provider="litellm"toDemoGPT()or usingLiteLLMChatModeldirectlyChanges
demogpt_agenthub/llms/litellm.py-- newLiteLLMChatModelextending bothBaseChatModel(LangChain runnable) andBaseLLM, callslitellm.completion()withdrop_params=Truedemogpt_agenthub/llms/__init__.py-- exportLiteLLMChatModel(lazy import, no breakage if litellm not installed)demogpt/chains/_llm_factory.py-- shared factory that createsLiteLLMChatModelwhenprovider="litellm",ChatOpenAIotherwisedemogpt/chains/chains.py--Chains.setLlm()andChains.getModel()use factory, acceptproviderparamdemogpt/chains/task_chains.py--TaskChains.setLlm()uses factory, acceptsproviderparamdemogpt/chains/task_chains_seperate.py-- samedemogpt/model.py--DemoGPT.__init__()acceptsproviderparam, passes through to all chain classespyproject.toml-- addlitellm>=1.80.0,<1.87.0as optional dependency (pip install demogpt[litellm])Tests
1. Live E2E: LiteLLMChatModel.run() (Azure Foundry -> Claude Sonnet 4.6)
2. Live E2E: LangChain pipe compatibility (used by agents)
3. Live E2E: Chains factory path
Example usage
Agenthub (agents, RAG):
Main DemoGPT app:
Supported model formats (LiteLLM convention):
anthropic/claude-sonnet-4-20250514-- Anthropicbedrock/anthropic.claude-sonnet-4-20250514-v1:0-- AWS Bedrockvertex_ai/gemini-2.5-flash-- Google Vertexazure_ai/claude-sonnet-4-6-- Azure AI Foundrygroq/llama-3.3-70b-versatile-- Groqollama/llama3-- Local OllamaRisk / Compatibility
LiteLLMChatModelfollows the exact same dual-inheritance pattern asOpenAIChatModel(ChatOpenAI, BaseLLM), just swapping the LangChain base for a customBaseChatModelthat calls litellm SDKproviderparameter defaults toNone, preserving existing OpenAI behaviorlitellmis an optional dependency -- existing users without it are unaffected (lazy import with try/except)drop_params=Trueensures unsupported params are silently dropped per provider