Feat/add litellm provider#2909
Open
RheagalFire wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
1 issue found across 5 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="backend/chainlit/litellm/__init__.py">
<violation number="1" location="backend/chainlit/litellm/__init__.py:145">
P2: Synchronous LiteLLM callback unconditionally uses `asyncio.create_task`, which can fail with no running event loop and silently drop step logging.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Guard asyncio.create_task with get_running_loop check and fall back to asyncio.run when no event loop is running.
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
instrument_litellm()for automatic LLM step logging when using LiteLLM (100+ providers: Anthropic, AWS Bedrock, Google Vertex AI, Cohere, Mistral, Groq, TogetherAI, etc.)
instrument_openai()andinstrument_mistralai(). Users callcl.instrument_litellm()once, and alllitellm.completion()/litellm.acompletion()calls appear as LLM steps inthe Chainlit UI with model name, messages, response, token usage, and timing
Changes
backend/chainlit/litellm/__init__.py-instrument_litellm()function +ChainlitLogger(CustomLogger)that creates Chainlit Steps on each litellm completionbackend/chainlit/__init__.py- exportedinstrument_litellmvia__getattr__,TYPE_CHECKING, and__all__backend/pyproject.toml- addedlitellm>=1.55,<2.0to test dependenciesbackend/tests/litellm/__init__.py+test_litellm.py- 13 unit testsUsage
Set your provider's env var (ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, etc.) and every litellm.completion() / litellm.acompletion() call automatically appears as an LLM step in the Chainlit UI.
Testing
Live E2E against Azure AI Foundry via litellm.acompletion():
Content: 4
Model: claude-sonnet-4-6
Messages: 2
Completion: {'role': 'assistant', 'content': '4'}
Tokens: 28 input, 5 output
Duration: 3.07s
ALL E2E PASSED
All pre-commit hooks pass (lint, format, type check).
Risk / Compatibility
Summary by cubic
Adds
instrument_litellm()to automatically loglitellmcompletions as LLM steps in Chainlit. Captures model, messages, tokens, and timing, and safely handles datetime timestamps and sync contexts without a running event loop.New Features
litellmviaCustomLoggerto create LLM steps.chainlit.instrument_litellm; opt-in and idempotent.Dependencies
litellm>=1.55,<2.0to test dependencies.Written for commit 900263c. Summary will update on new commits.