Skip to content

Commit ec36353

Browse files
fix(main.py): fix retries being multiplied when using openai sdk (BerriAI#7221)
* fix(main.py): fix retries being multiplied when using openai sdk Closes BerriAI#7130 * docs(prompt_management.md): add langfuse prompt management doc * feat(team_endpoints.py): allow teams to add their own models Enables teams to call their own finetuned models via the proxy * test: add better enforcement check testing for `/model/new` now that teams can add their own models * docs(team_model_add.md): tutorial for allowing teams to add their own models * test: fix test
1 parent 8060c5c commit ec36353

16 files changed

+2440
-1541
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import Image from '@theme/IdealImage';
2+
3+
# Prompt Management
4+
5+
LiteLLM supports using [Langfuse](https://langfuse.com/docs/prompts/get-started) for prompt management on the proxy.
6+
7+
## Quick Start
8+
9+
1. Add Langfuse as a 'callback' in your config.yaml
10+
11+
```yaml
12+
model_list:
13+
- model_name: gpt-3.5-turbo
14+
litellm_params:
15+
model: azure/chatgpt-v-2
16+
api_key: os.environ/AZURE_API_KEY
17+
api_base: os.environ/AZURE_API_BASE
18+
19+
litellm_settings:
20+
callbacks: ["langfuse"] # 👈 KEY CHANGE
21+
```
22+
23+
2. Start the proxy
24+
25+
```bash
26+
litellm-proxy --config config.yaml
27+
```
28+
29+
3. Test it!
30+
31+
```bash
32+
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
33+
-H 'Content-Type: application/json' \
34+
-H 'Authorization: Bearer sk-1234' \
35+
-d '{
36+
"model": "gpt-4",
37+
"messages": [
38+
{
39+
"role": "user",
40+
"content": "THIS WILL BE IGNORED"
41+
}
42+
],
43+
"metadata": {
44+
"langfuse_prompt_id": "value",
45+
"langfuse_prompt_variables": { # [OPTIONAL]
46+
"key": "value"
47+
}
48+
}
49+
}'
50+
```
51+
52+
## What is 'langfuse_prompt_id'?
53+
54+
- `langfuse_prompt_id`: The ID of the prompt that will be used for the request.
55+
56+
<Image img={require('../../img/langfuse_prompt_id.png')} />
57+
58+
## What will the formatted prompt look like?
59+
60+
### `/chat/completions` messages
61+
62+
The message will be added to the start of the prompt.
63+
64+
- if the Langfuse prompt is a list, it will be added to the start of the messages list (assuming it's an OpenAI compatible message).
65+
66+
- if the Langfuse prompt is a string, it will be added as a system message.
67+
68+
```python
69+
if isinstance(compiled_prompt, list):
70+
data["messages"] = compiled_prompt + data["messages"]
71+
else:
72+
data["messages"] = [
73+
{"role": "system", "content": compiled_prompt}
74+
] + data["messages"]
75+
```
76+
77+
### `/completions` messages
78+
79+
The message will be added to the start of the prompt.
80+
81+
```python
82+
data["prompt"] = compiled_prompt + "\n" + data["prompt"]
83+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Allow Teams to Add Models
2+
3+
Allow team to add a their own models/key for that project - so any OpenAI call they make uses their OpenAI key.
4+
5+
Useful for teams that want to call their own finetuned models.
6+
7+
## Specify Team ID in `/model/add` endpoint
8+
9+
10+
```bash
11+
curl -L -X POST 'http://0.0.0.0:4000/model/new' \
12+
-H 'Authorization: Bearer sk-******2ql3-sm28WU0tTAmA' \ # 👈 Team API Key (has same 'team_id' as below)
13+
-H 'Content-Type: application/json' \
14+
-d '{
15+
"model_name": "my-team-model", # 👈 Call LiteLLM with this model name
16+
"litellm_params": {
17+
"model": "openai/gpt-4o",
18+
"custom_llm_provider": "openai",
19+
"api_key": "******ccb07",
20+
"api_base": "https://my-endpoint-sweden-berri992.openai.azure.com",
21+
"api_version": "2023-12-01-preview"
22+
},
23+
"model_info": {
24+
"team_id": "e59e2671-a064-436a-a0fa-16ae96e5a0a1" # 👈 Specify the team ID it belongs to
25+
}
26+
}'
27+
28+
```
29+
30+
## Test it!
31+
32+
```bash
33+
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
34+
-H 'Content-Type: application/json' \
35+
-H 'Authorization: Bearer sk-******2ql3-sm28WU0tTAmA' \ # 👈 Team API Key
36+
-d '{
37+
"model": "my-team-model", # 👈 team model name
38+
"messages": [
39+
{
40+
"role": "user",
41+
"content": "What's the weather like in Boston today?"
42+
}
43+
]
44+
}'
45+
46+
```
47+
48+
## Debugging
49+
50+
### 'model_name' not found
51+
52+
Check if model alias exists in team table.
53+
54+
```bash
55+
curl -L -X GET 'http://localhost:4000/team/info?team_id=e59e2671-a064-436a-a0fa-16ae96e5a0a1' \
56+
-H 'Authorization: Bearer sk-******2ql3-sm28WU0tTAmA' \
57+
```
58+
59+
**Expected Response:**
60+
61+
```json
62+
{
63+
{
64+
"team_id": "e59e2671-a064-436a-a0fa-16ae96e5a0a1",
65+
"team_info": {
66+
...,
67+
"litellm_model_table": {
68+
"model_aliases": {
69+
"my-team-model": # 👈 public model name "model_name_e59e2671-a064-436a-a0fa-16ae96e5a0a1_e81c9286-2195-4bd9-81e1-cf393788a1a0" 👈 internally generated model name (used to ensure uniqueness)
70+
},
71+
"created_by": "default_user_id",
72+
"updated_by": "default_user_id"
73+
}
74+
},
75+
}
76+
```
77+
92.9 KB
Loading

0 commit comments

Comments
 (0)