[任务5] 重构方案:用 OpenWebUI + LiteLLM 替换 One-API + MySQL
技术栈简化: - 前端:One-API 网页管理 → OpenWebUI 极简界面(WEBUI_AUTH=False 无需登录,自动连接 LiteLLM) - 网关:One-API(数据库驱动)→ LiteLLM(纯 YAML 配置驱动) - 数据存储:MySQL(持久化) → LiteLLM 无状态(配置即代码) 配置简化: - 不需要注册账号、不需要点网页添加渠道 - 所有 5 个渠道的定义、模型映射、优先级、Failover 规则写在 litellm-config.yaml - API Key 填在 .env(占位符在 config.yaml 中引用) - 用户体验:打开网页 → 输入问题 → 自动用最合适的模型回答 已部署到 NAS,openwebui 正在初始化数据库(首次启动需要 1-2 分钟)
This commit is contained in:
97
litellm-config.yaml
Normal file
97
litellm-config.yaml
Normal file
@@ -0,0 +1,97 @@
|
||||
# LiteLLM 网关配置文件
|
||||
# 所有渠道和模型优先级、Failover 规则在此定义
|
||||
# API Key 通过环境变量注入,见 .env 文件
|
||||
|
||||
model_list:
|
||||
# 聚合模型1: auto-vision (图文混合问答)
|
||||
# 按优先级依次尝试: Gemini(1) → NVIDIA(1) → OpenRouter(2) → Mistral(3)
|
||||
# (Groq 不支持视觉,故不在此列表)
|
||||
- model_name: auto-vision
|
||||
litellm_params:
|
||||
model: gemini/gemini-flash-latest
|
||||
api_key: ${GEMINI_API_KEY}
|
||||
api_base: https://generativelanguage.googleapis.com/v1beta
|
||||
fallbacks:
|
||||
- nvidia-nim-vision
|
||||
- openrouter-vision
|
||||
- mistral-vision
|
||||
tpm_limit: 10000
|
||||
rpm_limit: 100
|
||||
|
||||
- model_name: nvidia-nim-vision
|
||||
litellm_params:
|
||||
model: openai/meta/llama-3.2-11b-vision-instruct
|
||||
api_key: ${NVIDIA_API_KEY}
|
||||
api_base: https://integrate.api.nvidia.com/v1
|
||||
|
||||
- model_name: openrouter-vision
|
||||
litellm_params:
|
||||
model: openrouter/google/gemini-2.0-flash-exp:free
|
||||
api_key: ${OPENROUTER_API_KEY}
|
||||
api_base: https://openrouter.ai/api/v1
|
||||
|
||||
- model_name: mistral-vision
|
||||
litellm_params:
|
||||
model: openai/pixtral-12b-2409
|
||||
api_key: ${MISTRAL_API_KEY}
|
||||
api_base: https://api.mistral.ai/v1
|
||||
|
||||
# 聚合模型2: auto-text (纯文本问答)
|
||||
# 按优先级依次尝试: Gemini(1) → NVIDIA(1) → OpenRouter(2) → Groq(2) → Mistral(3)
|
||||
- model_name: auto-text
|
||||
litellm_params:
|
||||
model: gemini/gemini-flash-latest
|
||||
api_key: ${GEMINI_API_KEY}
|
||||
api_base: https://generativelanguage.googleapis.com/v1beta
|
||||
fallbacks:
|
||||
- nvidia-nim-text
|
||||
- openrouter-text
|
||||
- groq-text
|
||||
- mistral-text
|
||||
tpm_limit: 10000
|
||||
rpm_limit: 100
|
||||
|
||||
- model_name: nvidia-nim-text
|
||||
litellm_params:
|
||||
model: openai/meta/llama-3.2-11b-vision-instruct
|
||||
api_key: ${NVIDIA_API_KEY}
|
||||
api_base: https://integrate.api.nvidia.com/v1
|
||||
|
||||
- model_name: openrouter-text
|
||||
litellm_params:
|
||||
model: openrouter/google/gemini-2.0-flash-exp:free
|
||||
api_key: ${OPENROUTER_API_KEY}
|
||||
api_base: https://openrouter.ai/api/v1
|
||||
|
||||
- model_name: groq-text
|
||||
litellm_params:
|
||||
model: openai/llama-3.3-70b-versatile
|
||||
api_key: ${GROQ_API_KEY}
|
||||
api_base: https://api.groq.com/openai/v1
|
||||
|
||||
- model_name: mistral-text
|
||||
litellm_params:
|
||||
model: openai/mistral-small-latest
|
||||
api_key: ${MISTRAL_API_KEY}
|
||||
api_base: https://api.mistral.ai/v1
|
||||
|
||||
# 网关全局配置
|
||||
router_settings:
|
||||
enable_cooldowns: true
|
||||
cooldown_threshold: 5 # 连续失败 5 次进入冷却
|
||||
cooldown_duration: 600 # 冷却期 10 分钟
|
||||
enable_retry: true
|
||||
max_retries: 2 # 最多重试 2 次
|
||||
|
||||
# 日志级别
|
||||
logging:
|
||||
level: INFO
|
||||
|
||||
# Fallback 行为
|
||||
# 上游错误(429/5xx/timeout)时自动切换到下一个渠道
|
||||
fallback_error_codes:
|
||||
- 429
|
||||
- 502
|
||||
- 503
|
||||
- 504
|
||||
- timeout
|
||||
Reference in New Issue
Block a user