feat: add LiteLLM engine for 100+ LLM providers - #73
Conversation
|
cc @zhudotexe |
|
@zhudotexe do you have any update on this PR? |
|
Thanks for the PR. I haven't had the time to review it as I'm currently on vacation. Could you add E2E tests in the same vein as the other API-based models (https://github.com/zhudotexe/kani/blob/main/tests/e2e/conftest.py#L466)? The main thing to look out for is to replace the underlying HTTP transport with the |
| :param api_key: The API key for the provider. If not set, litellm reads from environment | ||
| variables (e.g. ``ANTHROPIC_API_KEY``). |
There was a problem hiding this comment.
Is this handled by the litellm SDK?
| self.retry = retry | ||
| self.hyperparams = hyperparams | ||
|
|
||
| litellm.num_retries = retry |
There was a problem hiding this comment.
Is there a way to set this per-request rather than globally? We don't want to step on the user's toes if they're using litellm elsewhere in their application.
| ] | ||
|
|
||
| litellm = [ | ||
| "litellm>=1.80.0,<1.87.0", |
There was a problem hiding this comment.
| "litellm>=1.80.0,<1.87.0", | |
| "litellm>=1.80.0,<2.0.0", |
We can allow a generous upper bound unless we're using any unstable APIs (which we shouldn't be)
|
Another consideration: How does LiteLLM handle messages with embedded reasoning/multimodal content? Seems like this impl doesn't handle those especially, but I'm not sure if that's a LiteLLM limitation or not. |
Summary
Adds a
LiteLLMEnginethat gives kani users access to 100+ LLM providers (OpenAI, Anthropic, Azure, Bedrock, Vertex AI, Groq, Ollama, etc.) through the LiteLLM Python SDK.Changes
kani/engines/litellm/-- new engine packageengine.py--LiteLLMEngineextendingBaseEnginewithpredict(),stream(),prompt_len()__init__.py-- exportsLiteLLMEnginepyproject.toml-- addedlitellm = ["litellm>=1.80.0,<1.87.0"]optional dependencyTests
Live E2E against Azure Foundry (Anthropic Claude Sonnet 4.6):
Lint:
blackandisortpass clean.Example usage
Implementation details
ChatMessageto OpenAI-format dicts for litellmAIFunctionto OpenAI tool specs, parsesToolCallfrom responses)stream()with incremental content and tool call assemblylitellm.token_counter()with fallback estimationdrop_params=Trueby default for cross-provider compatibilityRisk / Compatibility
litellmis an optional dependency (pip install kani[litellm])