Zum Hauptinhalt springen

Anbieterspezifisches Wildcard-Routing

Alle Modelle eines Anbieters weiterleiten

Verwenden Sie dies, wenn Sie alle Modelle eines bestimmten Anbieters weiterleiten möchten, ohne sie in der config.yaml zu definieren

Schritt 1. Definieren Sie anbieterspezifisches Routing​

from litellm import Router

router = Router(
model_list=[
{
"model_name": "anthropic/*",
"litellm_params": {
"model": "anthropic/*",
"api_key": os.environ["ANTHROPIC_API_KEY"]
}
},
{
"model_name": "groq/*",
"litellm_params": {
"model": "groq/*",
"api_key": os.environ["GROQ_API_KEY"]
}
},
{
"model_name": "fo::*:static::*", # all requests matching this pattern will be routed to this deployment, example: model="fo::hi::static::hi" will be routed to deployment: "openai/fo::*:static::*"
"litellm_params": {
"model": "openai/fo::*:static::*",
"api_key": os.environ["OPENAI_API_KEY"]
}
}
]
)

[Nur Proxy]Schritt 2 - Führen Sie den liteLLM-Proxy aus​

$ litellm --config /path/to/config.yaml

Schritt 3 - Testen Sie es​

from litellm import Router

router = Router(model_list=...)

# Test with `anthropic/` - all models with `anthropic/` prefix will get routed to `anthropic/*`
resp = completion(model="anthropic/claude-3-sonnet-20240229", messages=[{"role": "user", "content": "Hello, Claude!"}])
print(resp)

# Test with `groq/` - all models with `groq/` prefix will get routed to `groq/*`
resp = completion(model="groq/llama3-8b-8192", messages=[{"role": "user", "content": "Hello, Groq!"}])
print(resp)

# Test with `fo::*::static::*` - all requests matching this pattern will be routed to `openai/fo::*:static::*`
resp = completion(model="fo::hi::static::hi", messages=[{"role": "user", "content": "Hello, Claude!"}])
print(resp)

[Nur Proxy] Wildcard-Modellzugriff steuern​