Installation
pip install "rail-score-sdk[litellm]" litellm
Verwendung als Schutzmaßnahme
from rail_score_sdk.integrations import RAILGuardrail
import litellm
# Registrieren Sie RAIL als Schutzmaßnahme
rail_guardrail = RAILGuardrail(
api_key="YOUR_RAIL_API_KEY",
threshold=7.0,
mode="basic",
action="block", # "block" | "warn" | "regenerate"
)
litellm.callbacks = [rail_guardrail]
# Jetzt werden alle LiteLLM-Aufrufe automatisch bewertet
response = await litellm.acompletion(
model="gpt-4o",
messages=[{"role": "user", "content": "Erklären Sie Quantencomputing."}],
)
# Greifen Sie auf RAIL-Daten aus den Antwortmetadaten zu
print(response._hidden_params["rail_score"])
print(response._hidden_params["rail_threshold_met"])
Direkte Verwendung
from rail_score_sdk.integrations import RAILGuardrail
guardrail = RAILGuardrail(
api_key="YOUR_RAIL_API_KEY",
threshold=7.0,
)
result = await guardrail.async_post_call_success_hook(
data={"messages": [...]},
response=llm_response,
)
RAILGuardrail implementiert die LiteLLM CustomLogger-Schnittstelle, sodass es mit jedem von LiteLLM unterstützten Modell funktioniert, einschließlich lokaler Modelle über Ollama.