Guardrails.ai
Verwenden Sie Guardrails.ai, um Überprüfungen zu LLM-Ausgaben hinzuzufügen.
Voraussetzungen
- Guardrails AI Server einrichten. Schnellstart
Verwendung
- Konfigurieren Sie config.yaml
model_list:
- model_name: gpt-3.5-turbo
litellm_params:
model: gpt-3.5-turbo
api_key: os.environ/OPENAI_API_KEY
guardrails:
- guardrail_name: "guardrails_ai-guard"
litellm_params:
guardrail: guardrails_ai
guard_name: "gibberish_guard" # 👈 Guardrail AI guard name
mode: "post_call"
api_base: os.environ/GUARDRAILS_AI_API_BASE # 👈 Guardrails AI API Base. Defaults to "http://0.0.0.0:8000"
- LiteLLM Gateway starten
litellm --config config.yaml --detailed_debug
- Testanfrage
Langchain, OpenAI SDK Anwendungsbeispiele
curl -i https://:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-npnwjPQciVRok5yNZgKmFQ" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{"role": "user", "content": "hi my email is ishaan@berri.ai"}
],
"guardrails": ["guardrails_ai-guard"]
}'
✨ Guardrails pro Projekt steuern (API-Schlüssel)
Info
✨ Dies ist eine exklusive Enterprise-Funktion Kontaktieren Sie uns für eine kostenlose Testversion
Verwenden Sie dies, um zu steuern, welche Guardrails pro Projekt ausgeführt werden. In diesem Tutorial möchten wir nur die folgenden Guardrails für 1 Projekt (API-Schlüssel) ausführen
guardrails: ["aporia-pre-guard", "aporia-post-guard"]
Schritt 1 Schlüssel mit Guardrail-Einstellungen erstellen
- /key/generate
- /key/update
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-D '{
"guardrails": ["guardrails_ai-guard"]
}
}'
curl --location 'http://0.0.0.0:4000/key/update' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data '{
"key": "sk-jNm1Zar7XfNdZXp49Z1kSQ",
"guardrails": ["guardrails_ai-guard"]
}
}'
Schritt 2 Mit neuem Schlüssel testen
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Authorization: Bearer sk-jNm1Zar7XfNdZXp49Z1kSQ' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "my email is ishaan@berri.ai"
}
]
}'