Files
xiaoyin-gateway/data/gateway.yaml
T
api-gateway 4507dc4b8e fix: 模型级强制参数(kimi-k2.7-code 锁 temperature=1)+ 测速超时/错误文案
- config: ModelInfo.params + MODEL_PARAM_KEYS 白名单 + _parse_model_params(写错即 ConfigError)
- adapters: _forced_params 在 payload 组装后强制覆盖;_learn_from_upstream_error 按上游 400
  要求修正并重发一次(非原样重试);流式已吐内容则不重发
- main: /v1/models 暴露 params;探针超时 15s→30s;_speedtest_error_text 说清超时/上游原文
- settings: 面板保存保留手写 models[].params(原先会被静默清掉)
- gateway.yaml: kimi-k2.7-code params.temperature=1
- 前端: Models 挂锁+参数固定标签;Chat 温度 chip 挂锁+抽屉提示;新增 lock 图标;中英对称
- tests: +10 → 168 passed / 0 failed
2026-09-18 12:18:10 +08:00

229 lines
11 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AI 网关配置文件(data/ 目录)
# 供应商:Agnes / 火山方舟 Coding / OpenCode Go(订阅编程模型)
# 密钥统一走 token_env 指向的环境变量(本机见 data/.env),不再在 yaml 存明文
# 端口默认 8808
#
# 说明:本文件是项目的**唯一配置文件**(run.py 默认读取;GATEWAY_CONFIG 可覆盖)。
providers:
agnes:
name: "Agnes AI"
base_url: "https://api.agnes-ai.cn/v1"
auth:
token_env: "AGNES_API_KEY"
extra_headers: {}
# 图像 / 视频端点(Agnes 非标准,走自有路径)
media:
image_endpoint: "/images/generations"
image_default_size: "1K" # 图像默认档位(Agnes: 1K/2K/3K/4K)
video_create_endpoint: "/videos"
video_poll_base: "https://api.agnes-ai.cn"
video_poll_path: "/agnesapi"
video_model_name: "agnes-video-2.5-flash"
models:
- id: "agnes-3.0-flash"
display_name: "Agnes 3.0 Flash"
type: "text"
# 第十三轮: Agnes 3.0 Flash 文档「输入模态:文本、图像 URL」→ 支持视觉(对话带图)。
# 实测 data:image/png;base64,... 也能识别。带图请求走路由别名时会被排到链首。
vision: true
- id: "agnes-2.5-flash"
display_name: "Agnes 2.5 Flash"
type: "text"
# Agnes 2.5 Flash(2.0 升级版):OpenAI 兼容 /v1/chat/completions,支持图像 URL 输入与工具调用,
# 上下文 512K / 最大输出 65.5K;当前定价暂免(¥0/百万)。参见官方文档 agnes-25-flash。
vision: true
- id: "agnes-image-2.5-flash"
display_name: "Agnes Image 2.5 Flash"
type: "image"
- id: "agnes-video-2.5-flash"
display_name: "Agnes Video 2.5 Flash"
type: "video"
volc_engine:
name: "火山方舟 Coding Plan"
base_url: "https://ark.cn-beijing.volces.com/api/coding/v3"
auth:
token_env: "VOLC_API_KEY"
extra_headers: {}
media: {}
models:
- id: "ark-code-latest"
display_name: "火山方舟 ark-code-latest"
type: "text"
opencode:
name: "OpenCode Go"
base_url: "https://opencode.ai/zen/go/v1"
auth:
token_env: "OPENCODE_API_KEY"
# OpenCode Go 是每月订阅编程模型入口。官方硬性要求每个 /chat/completions
# 带 x-opencode-session(缺失直接 400 MissingSessionID),并建议用专属 UA
# 而非通用库名(实测 UA 不敏感,会话头才是必需)。适配器据此开关在
# 每次请求动态注入 UUID 会话头(不能放静态 extra_headers——会被 _get_adapter 缓存冻结)。
requires_session_header: true
extra_headers:
User-Agent: "api-gateway/2.4.0 (jakon opencode-go)"
# 无媒体能力(纯文本编程模型;图像/视频不走本供应商)
media: {}
models:
# ── OpenAI 兼容 /v1/chat/completions 线(全部经真实 key 实测 200)──
- id: "glm-5.3-flash"
display_name: "GLM-5.3-Flash"
type: "text"
- id: "glm-5.3"
display_name: "GLM-5.3"
type: "text"
- id: "glm-5.2"
display_name: "GLM-5.2"
type: "text"
- id: "glm-5.1"
display_name: "GLM-5.1"
type: "text"
- id: "kimi-k3"
display_name: "Kimi K3"
type: "text"
- id: "kimi-k2.7-code"
display_name: "Kimi K2.7 Code"
type: "text"
# 上游硬约束:该模型**只接受 temperature=1**,传 0 / 0.7 等一律 400
# "invalid temperature: only 1 is allowed for this model"。
# 写死后网关无论收到什么温度都按 1 发(前端温度滑块、API 传参、一键测速探针
# 统一生效);客户端不传 temperature 时也会显式按 1 发送,与上游默认值一致。
params:
temperature: 1
- id: "kimi-k2.6"
display_name: "Kimi K2.6"
type: "text"
- id: "longcat-2.0"
display_name: "LongCat 2.0"
type: "text"
- id: "deepseek-v4-pro"
display_name: "DeepSeek V4 Pro"
type: "text"
- id: "deepseek-v4-flash"
display_name: "DeepSeek V4 Flash"
type: "text"
- id: "deepseek-flash"
display_name: "DeepSeek Flash"
type: "text"
- id: "deepseek-v4.1-flash"
display_name: "DeepSeek V4.1 Flash"
type: "text"
- id: "deepseek-v4-flash-vision-exp"
display_name: "DeepSeek V4 Flash Vision Exp"
type: "text"
vision: true # 官方标 Vision,支持图像转 token 输入(带图请求可走路由链首)
- id: "mimo-v2.5"
display_name: "MiMo V2.5"
type: "text"
- id: "mimo-v2.5-pro"
display_name: "MiMo V2.5 Pro"
type: "text"
- id: "hy4-preview"
display_name: "Hy4 Preview"
type: "text"
- id: "hy3"
display_name: "Hy3"
type: "text"
server:
host: "127.0.0.1"
port: 8808
timeout: 120
retry: 3 # 直接用模型 id(不走路由)时重试 3 次(含首次);路由别名用各自 route.retry(默认1)
# ── 运维开关 ──
health_auth: false # /health/* 是否也需鉴权(默认否,留给探活)
hot_reload: true # 监听 gateway.yaml mtime 自动重载(改配置免重启)
hot_reload_interval: 15 # 重载检查间隔(秒)
metrics_enabled: true # 记录调用指标(/metrics)
rate_limit_rps: null # 全局单 user QPS 上限(null=不限;供应商级用 provider.rate_limit_rps)
max_body_size: 2000000 # 请求体字节上限(防 DDoS,约 2MB)
cors_origins: ["*"] # CORS 允许来源(生产收紧为具体域名)
graceful_shutdown: 30 # 优雅关闭等待在途请求的秒数
# ── 防滥用 / 安全 ──
batch_max_concurrency: 16 # /batch 并发上限(客户端 max_concurrency 会被钳到此值)
batch_max_items: 64 # /batch 单次最大条目数(超出返回 400)
webhook_allow_private: false # 视频 callback_url 是否允许指向内网/回环(SSRF 防护,默认禁)
docs_enabled: false # FastAPI 文档(/docs、/openapi.json)是否开放(安全默认关)
auth_fail_limit_per_min: 20 # 同一来源 IP 每分钟鉴权失败上限,超过 → 429(防暴力枚举)
# ── 供应商熔断(Circuit Breaker) ──────────────────────
# 某供应商连续/滑动窗口失败达到 failure_threshold 就熔断 cooldown 秒,
# 期间直接跳过(不再白等),让 fallback 快速切到健康供应商。
circuit:
enabled: true
failure_threshold: 3 # 连续失败 3 次即熔断
cooldown: 30 # 熔断持续 30 秒
window: 10 # 滑动窗口
# ── 可观测性 ───────────────────────────────────────────
observability:
log_level: "INFO"
log_json: false # true = 结构化 JSON 行日志(接 ELK/CloudWatch)
access_log_maxlen: 500 # 访问日志环形缓冲长度
# ── 定价(用于 /v1 响应里估算成本,人民币/百万 token) ─
# 不配则该模型 estimated_cost_cny 不返回(不影响调用)。
pricing:
per_model:
agnes-3.0-flash: { input: 0.35, output: 1.00 }
agnes-2.5-flash: { input: 0, output: 0 } # 文档现价暂免(输入/输出/缓存命中均 ¥0/百万)
ark-code-latest: { input: 0.50, output: 2.00 }
# ── 媒体下载代理白名单(第十七轮)────────────────────────
# 生成的图片/视频挂在第三方 CDN 上且不带 CORS 头,浏览器里既 fetch 不到 blob、
# 跨域 <a download> 也不生效(只会打开新标签页)。所以由网关代拉一次并加上
# Content-Disposition: attachment,前端「下载」按钮才真的能存文件。
# 安全:这是网关唯一一个服务端主动出网的接口 —— 只有这里列出的域名(含其子域)
# 允许被代下载,且解析出来的 IP 必须是公网地址;列表为空 = 该功能整体关闭。
# 换了供应商/换了 CDN 域名时,往这里加一条即可(如 volc 的 tos-*.volces.com)。
download:
allowed_hosts:
- "cos-platform-outputs.agnes-ai.cn" # Agnes 图像/视频产物 CDN
max_bytes: 67108864 # 单文件上限 64MB
# ── 网关入口鉴权 ─────────────────────────────────────
# 账号与 API Key 全部由页面管理,存在 data/users.json(见 app/users.py):
# 管理员在「用户管理」页建账号,各账号在「设置 → 我的 API Key」自助铸 Key。
# 本文件里**不再有任何用户/密钥**,只有一个运维开关:
# auth.session_ttl_minutes —— 网页登录签发的会话有效期(分钟,默认 1440 = 24h)
# 第十八轮: 删掉了这里残留的旧 `auth.enabled/users/key` 死配置(含一把明文 wjd- Key)。
# 那些键早已不再被 config.py 读取(只读 session_ttl_minutes),
# 那把 Key 在 users.json 里也不存在 → 认不了任何入口,但会让"yaml 里没有明文凭证"的说法失真。
auth:
session_ttl_minutes: 1440
# ── 路由别名 + 按优先级 fallback ──────────────────────
# model 填别名(如 wjd),按数组顺序逐个尝试:
# 第 1 个失败/超时/重试耗尽 → 第 2 个 … 全失败才 502。
# 每个路由可设 timeout(单模型超时秒)、retry(切下一个前该模型重试次数)。
# 优先级从左到右(第一个最高)。老板决策:wjd 链路 = 全部文本模型(已含 OpenCode Go 17 个)。
routes:
wjd:
timeout: 60 # 单模型 60s 没出结果就切下一个(避免 20×120s 挂死)
retry: 1 # 每个模型只试 1 次,失败立即切下一个
# 注意(老板决策):wjd 链路 = 全部文本模型;新增/现有文本模型都必须加进这里。
models:
# 供应商按「默认主力」在前,其余按供应商分组;运行时仍按可用性+速度实时重排。
- "ark-code-latest" # 1) 火山方舟
- "agnes-3.0-flash" # 2) Agnes 3.0
- "agnes-2.5-flash" # 3) Agnes 2.5
# ── 4) OpenCode Go(17 个文本模型,全进 wjd)──
- "glm-5.3-flash" # 4.1) GLM-5.3-Flash
- "glm-5.3" # 4.2) GLM-5.3
- "glm-5.2" # 4.3) GLM-5.2
- "glm-5.1" # 4.4) GLM-5.1
- "kimi-k3" # 4.5) Kimi K3
- "kimi-k2.7-code" # 4.6) Kimi K2.7 Code
- "kimi-k2.6" # 4.7) Kimi K2.6
- "longcat-2.0" # 4.8) LongCat 2.0
- "deepseek-v4-pro" # 4.9) DeepSeek V4 Pro
- "deepseek-v4-flash" # 4.10) DeepSeek V4 Flash
- "deepseek-flash" # 4.11) DeepSeek Flash
- "deepseek-v4.1-flash" # 4.12) DeepSeek V4.1 Flash
- "deepseek-v4-flash-vision-exp" # 4.13) DeepSeek V4 Flash Vision Exp
- "mimo-v2.5" # 4.14) MiMo V2.5
- "mimo-v2.5-pro" # 4.15) MiMo V2.5 Pro
- "hy4-preview" # 4.16) Hy4 Preview
- "hy3" # 4.17) Hy3