[已弃用] 基于区域的路由
信息
此功能已弃用,请改用 基于标签的路由 (Tag Based Routing)
将特定客户路由至仅限欧盟(eu-only)的模型。
通过为客户指定 'allowed_model_region',LiteLLM 将过滤掉模型组中不在允许区域(即 'eu')内的任何模型。
1. 创建带有区域规范的客户
为此,请使用 litellm 的 'end-user' 对象。
通过在 openai 聊天补全/嵌入调用中传递 'user' 参数,可以跟踪/识别最终用户。
curl -X POST --location 'http://0.0.0.0:4000/end_user/new' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data '{
"user_id" : "ishaan-jaff-45",
"allowed_model_region": "eu", # 👈 SPECIFY ALLOWED REGION='eu'
}'
2. 将欧盟模型添加到模型组
将欧盟模型添加到模型组。使用 'region_name' 参数为每个模型指定区域。
支持的区域为 'eu' 和 'us'。
model_list:
- model_name: gpt-3.5-turbo
litellm_params:
model: azure/gpt-35-turbo # 👈 EU azure model
api_base: https://my-endpoint-europe-berri-992.openai.azure.com/
api_key: os.environ/AZURE_EUROPE_API_KEY
region_name: "eu"
- model_name: gpt-3.5-turbo
litellm_params:
model: azure/chatgpt-v-2
api_base: https://openai-gpt-4-test-v-1.openai.azure.com/
api_version: "2023-05-15"
api_key: os.environ/AZURE_API_KEY
region_name: "us"
router_settings:
enable_pre_call_checks: true # 👈 IMPORTANT
启动代理
litellm --config /path/to/config.yaml
3. 测试它!
向代理发起简单的聊天补全调用。在响应头中,你应该能看到返回的 API base。
curl -X POST --location 'https://:4000/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-1234' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "user",
"content": "what is the meaning of the universe? 1234"
}],
"user": "ishaan-jaff-45" # 👈 USER ID
}
'
响应头中的预期 API Base
x-litellm-api-base: "https://my-endpoint-europe-berri-992.openai.azure.com/"
x-litellm-model-region: "eu" # 👈 CONFIRMS REGION-BASED ROUTING WORKED
常见问题解答
如果该区域没有可用模型会怎样?
由于路由器会过滤掉不在指定区域内的模型,因此如果该区域没有可用模型,它会向用户返回错误。