feat: add LiteLLM provider with /v1/models discovery - #220
Open
prodmanpd wants to merge 1 commit 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
Adds LiteLLM as a first class provider (
provider: "litellm"), so one endpoint reaches 100+ models (OpenAI, Anthropic, Gemini, Bedrock, Vertex, Azure, Groq, and more) through a self hosted LiteLLM proxy.A LiteLLM proxy speaks the OpenAI compatible wire format, so, per this repo's own design ("adding a wire format is one new adapter"), the adapter reuses
OpenAIChatModel's translation and only changes the defaults. The value overprovider: "openai"plus a manualbaseUrlis a self describing provider:http://localhost:4000), and/v1/modelsauto discovery (listLiteLLMModels) so callers can enumerate whatever models the proxy is configured to serve instead of hardcoding a model id.Changes
src/ai/llm/litellm.ts(new):LiteLLMChatModel extends OpenAIChatModel(default proxy base URL andlitellm:<model>label) andlistLiteLLMModels()which callsGET /v1/modelsand returns the available model ids.src/ai/llm/factory.ts:ProviderKindgains"litellm";createChatModelbuilds aLiteLLMChatModel.src/ai/providers.ts: default model for thelitellmprovider.test/litellm-adapter.test.tsTests
Types:
npx tsc -p tsconfig.json --noEmitis clean.Tests:
npm test(repo runner): 840 passed, 0 failed (4 new litellm tests plus no regressions).The new tests assert: the adapter forwards the provider prefixed model and temperature and reuses the OpenAI translation;
listLiteLLMModelsmaps/v1/modelsto ids; and the factory wiresprovider: "litellm".Usage
Or via env:
GRAFT_PROVIDER=litellm,GRAFT_MODEL=anthropic/claude-3-5-sonnet,GRAFT_BASE_URL=http://localhost:4000.