-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat: add feature to make silent calls #19544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8c2769
feat: add feature to make silent calls
Harshit28j 31c83f1
add test or silent feat
Harshit28j 7b47286
add docs for silent feat
Harshit28j 1cacaf3
fix lint issues and UI logs
Harshit28j b875cd8
add docs of ab testing and deep copy
Harshit28j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import Tabs from '@theme/Tabs'; | ||
| import TabItem from '@theme/TabItem'; | ||
|
|
||
| # A/B Testing - Traffic Mirroring | ||
|
|
||
| Traffic mirroring allows you to "mimic" production traffic to a secondary (silent) model for evaluation purposes. The silent model's response is gathered in the background and does not affect the latency or result of the primary request. | ||
|
|
||
| This is useful for: | ||
| - Testing a new model's performance on production prompts before switching. | ||
| - Comparing costs and latency between different providers. | ||
| - Debugging issues by mirroring traffic to a more verbose model. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| To enable traffic mirroring, add `silent_model` to the `litellm_params` of a deployment. | ||
|
|
||
| <Tabs> | ||
| <TabItem value="sdk" label="SDK"> | ||
|
|
||
| ```python | ||
| from litellm import Router | ||
|
|
||
| model_list = [ | ||
| { | ||
| "model_name": "gpt-3.5-turbo", | ||
| "litellm_params": { | ||
| "model": "azure/chatgpt-v-2", | ||
| "api_key": "...", | ||
| "silent_model": "gpt-4" # 👈 Mirror traffic to gpt-4 | ||
| }, | ||
| }, | ||
| { | ||
| "model_name": "gpt-4", | ||
| "litellm_params": { | ||
| "model": "openai/gpt-4", | ||
| "api_key": "..." | ||
| }, | ||
| } | ||
| ] | ||
|
|
||
| router = Router(model_list=model_list) | ||
|
|
||
| # The request to "gpt-3.5-turbo" will trigger a background call to "gpt-4" | ||
| response = await router.acompletion( | ||
| model="gpt-3.5-turbo", | ||
| messages=[{"role": "user", "content": "How does traffic mirroring work?"}] | ||
| ) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="proxy" label="Proxy"> | ||
|
|
||
| Add `silent_model` to your `config.yaml`: | ||
|
|
||
| ```yaml | ||
| model_list: | ||
| - model_name: primary-model | ||
| litellm_params: | ||
| model: azure/gpt-35-turbo | ||
| api_key: os.environ/AZURE_API_KEY | ||
| silent_model: evaluation-model # 👈 Mirror traffic here | ||
| - model_name: evaluation-model | ||
| litellm_params: | ||
| model: openai/gpt-4o | ||
| api_key: os.environ/OPENAI_API_KEY | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## How it works | ||
| 1. **Request Received**: A request is made to a model group (e.g. `primary-model`). | ||
| 2. **Deployment Picked**: LiteLLM picks a deployment from the group. | ||
| 3. **Primary Call**: LiteLLM makes the call to the primary deployment. | ||
| 4. **Mirroring**: If `silent_model` is present, LiteLLM triggers a background call to that model. | ||
| - For **Sync** calls: Uses a shared thread pool. | ||
| - For **Async** calls: Uses `asyncio.create_task`. | ||
| 5. **Isolation**: The background call uses a `deepcopy` of the original request parameters and sets `metadata["is_silent_experiment"] = True`. It also strips out logging IDs to prevent collisions in usage tracking. | ||
|
|
||
| ## Key Features | ||
| - **Latency Isolation**: The primary request returns as soon as it's ready. The background (silent) call does not block. | ||
| - **Unified Logging**: Background calls are processed via the Router, meaning they are automatically logged to your configured observability tools (Langfuse, S3, etc.). | ||
| - **Evaluation**: Use the `is_silent_experiment: True` flag in your logs to filter and compare results between the primary and mirrored calls. | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this interface feels incorrect. in the litellm_params i shouldn't be referencing router model_names (different heirarchies)
wouldn't it make more sense for this to be a router setting similar to model_group_alias?