代理服务器集成
LiteLLM 也可以用作 OpenAI 兼容的代理服务器,允许您通过统一的 API 将请求路由到不同的模型。启动代理服务器
首先,安装 LiteLLM 并启用代理支持:使用代理
LiteLLMOpenAI 类使用 OpenAI 兼容接口连接到 LiteLLM 代理:
配置选项
LiteLLMOpenAI 类接受以下参数:
示例
请在食谱中查看这些示例:代理示例
在此查看更多示例 here。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
使用 LiteLLM 和 Agno 进行 OpenAI 兼容代理服务器集成。
pip install 'litellm[proxy]'
litellm --model gpt-4o --host 10.10.10.10 --port 4000
LiteLLMOpenAI 类使用 OpenAI 兼容接口连接到 LiteLLM 代理:
from agno.agent import Agent
from agno.models.litellm import LiteLLMOpenAI
agent = Agent(
model=LiteLLMOpenAI(
id="gpt-4o", # 要使用的模型 ID
),
markdown=True,
)
agent.print_response("写一个两句话的恐怖故事")
LiteLLMOpenAI 类接受以下参数:
| 参数 | 类型 | 描述 | 默认值 |
|---|---|---|---|
id | str | 模型标识符 | ”gpt-4o” |
name | str | 模型的显示名称 | ”LiteLLM” |
provider | str | 提供商名称 | ”LiteLLM” |
api_key | str | API 密钥(回退到 LITELLM_API_KEY 环境变量) | None |
base_url | str | LiteLLM 代理服务器的 URL | ”http://0.0.0.0:4000” |