Prompt Management
Führen Sie Experimente durch oder ändern Sie das spezifische Modell (z. B. von gpt-4o zu gpt4o-mini Finetune) aus Ihrem Prompt-Verwaltungstool (z. B. Langfuse), anstatt Änderungen in der Anwendung vorzunehmen.
| Unterstützte Integrationen | Link |
|---|---|
| Langfuse | Erste Schritte |
| Humanloop | Erste Schritte |
Schnellstart
- SDK
- PROXY
import os
import litellm
os.environ["LANGFUSE_PUBLIC_KEY"] = "public_key" # [OPTIONAL] set here or in `.completion`
os.environ["LANGFUSE_SECRET_KEY"] = "secret_key" # [OPTIONAL] set here or in `.completion`
litellm.set_verbose = True # see raw request to provider
resp = litellm.completion(
model="langfuse/gpt-3.5-turbo",
prompt_id="test-chat-prompt",
prompt_variables={"user_message": "this is used"}, # [OPTIONAL]
messages=[{"role": "user", "content": "<IGNORED>"}],
)
- Konfigurieren Sie config.yaml
model_list:
- model_name: my-langfuse-model
litellm_params:
model: langfuse/openai-model
prompt_id: "<langfuse_prompt_id>"
api_key: os.environ/OPENAI_API_KEY
- model_name: openai-model
litellm_params:
model: openai/gpt-3.5-turbo
api_key: os.environ/OPENAI_API_KEY
- Starten Sie den Proxy
litellm --config config.yaml --detailed_debug
- Testen Sie es!
- CURL
- OpenAI Python SDK
curl -L -X POST 'http://0.0.0.0:4000/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"model": "my-langfuse-model",
"messages": [
{
"role": "user",
"content": "THIS WILL BE IGNORED"
}
],
"prompt_variables": {
"key": "this is used"
}
}'
import openai
client = openai.OpenAI(
api_key="anything",
base_url="http://0.0.0.0:4000"
)
# request sent to model set on litellm proxy, `litellm --model`
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages = [
{
"role": "user",
"content": "this is a test request, write a short poem"
}
],
extra_body={
"prompt_variables": { # [OPTIONAL]
"key": "this is used"
}
}
)
print(response)
Erwartete Protokolle
POST Request Sent from LiteLLM:
curl -X POST \
https://api.openai.com/v1/ \
-d '{'model': 'gpt-3.5-turbo', 'messages': <YOUR LANGFUSE PROMPT TEMPLATE>}'
Modell festlegen
Setzen Sie das Modell auf LiteLLM
Sie können langfuse/<litellm_model_name> verwenden
- SDK
- PROXY
litellm.completion(
model="langfuse/gpt-3.5-turbo", # or `langfuse/anthropic/claude-3-5-sonnet`
...
)
model_list:
- model_name: gpt-3.5-turbo
litellm_params:
model: langfuse/gpt-3.5-turbo # OR langfuse/anthropic/claude-3-5-sonnet
prompt_id: <langfuse_prompt_id>
api_key: os.environ/OPENAI_API_KEY
Setzen Sie das Modell in Langfuse
Wenn das Modell in der Langfuse-Konfiguration angegeben ist, wird es verwendet.
model_list:
- model_name: gpt-3.5-turbo
litellm_params:
model: azure/chatgpt-v-2
api_key: os.environ/AZURE_API_KEY
api_base: os.environ/AZURE_API_BASE
Was ist 'prompt_variables'?
prompt_variables: Ein Wörterbuch von Variablen, die Teile des Prompts ersetzen.
Was ist 'prompt_id'?
prompt_id: Die ID des Prompts, der für die Anfrage verwendet wird.
Wie wird der formatierte Prompt aussehen?
/chat/completions Nachrichten
Das vom Client gesendete Feld messages wird ignoriert.
Der Langfuse-Prompt ersetzt das Feld messages.
Um Teile des Prompts zu ersetzen, verwenden Sie das Feld prompt_variables. Sehen Sie, wie Prompt-Variablen verwendet werden
Wenn der Langfuse-Prompt eine Zeichenkette ist, wird er als Benutzernachricht gesendet (nicht alle Anbieter unterstützen Systemnachrichten).
Wenn der Langfuse-Prompt eine Liste ist, wird er unverändert gesendet (Langfuse-Chat-Prompts sind OpenAI-kompatibel).
Architekturübersicht
API-Referenz
Dies sind die Parameter, die Sie an die Funktion litellm.completion im SDK und litellm_params in config.yaml übergeben können.
prompt_id: str # required
prompt_variables: Optional[dict] # optional
langfuse_public_key: Optional[str] # optional
langfuse_secret: Optional[str] # optional
langfuse_secret_key: Optional[str] # optional
langfuse_host: Optional[str] # optional