[已弃用]基于区域的路由
信息
此功能已弃用,请改用基于标签的路由
将特定客户路由到仅限欧盟的模型。
通过为客户指定 'allowed_model_region',LiteLLM 将过滤掉模型组中不在允许区域(即 'eu')内的任何模型。
1. 创建具有区域规范的客户
为此,请使用 litellm 的 'end-user' 对象。
通过在 openai 聊天完成/嵌入调用中向 litellm 传递 '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 'http://localhost: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
常见问题
如果该区域没有可用模型怎么办?
由于路由器会过滤掉不在指定区域内的模型,如果该区域没有可用模型,它将向用户返回错误。