refactor(fam-edge): 问答链路抽离到独立 ai-gateway 服务,fam-edge 改为转发客户端
原本嵌在 fam-edge 里的问答模型降级链(NVIDIA 文字模型 -> Gemini 非 flash 文字 模型 -> 本地 Ollama 兜底,含 key 轮换/熔断)跟视频分析业务无关,是通用能力, 抽成独立 ai-gateway 服务(OpenAI 兼容协议),除了 fam-edge 自己,别的项目也能 直接接入。 - qa.py 重写为 HTTP 转发客户端,调 ai-gateway 的 /v1/chat/completions,翻译回 原有 run_qa/run_qa_stream 契约,api_gateway.py 和 fam-core 调用方零改动 - 删除 model_adapters/ollama_adapter.py 及其测试(问答专用,视频分析不需要本地模型) - gemini_adapter.py / nvidia_adapter.py 移除 chat()/chat_stream() 及问答专用超时 (只保留视频分析用的 analyze_video) - app.py 移除 Ollama 预热逻辑(现在由 ai-gateway 自己负责) - config.yaml 移除 3 个问答专用 model 条目,新增 ai_gateway 客户端配置块 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -103,7 +103,16 @@ person_identifier:
|
||||
max_retries: 2
|
||||
retry_backoff_sec: 3
|
||||
|
||||
# 智能问答降级链(与视频分析独立):Gemini -> NVIDIA -> 本地 Ollama
|
||||
# 智能问答(2026-08-23 抽离到独立 ai-gateway 服务,OpenAI 兼容协议):
|
||||
# fam-edge 这边只是转发客户端,问答本体的模型降级链/key 轮换/熔断都在
|
||||
# ai-gateway 自己的 config.yaml 里配置,这里只填怎么连它。
|
||||
# token 走 .env AI_GATEWAY_TOKEN,跟 ai-gateway 侧配置的值必须一致。
|
||||
ai_gateway:
|
||||
base_url: "http://127.0.0.1:5100" # 同机部署,走本地回环,不走公网
|
||||
token: "${AI_GATEWAY_TOKEN}"
|
||||
timeout: 60
|
||||
|
||||
# 视频分析模型链
|
||||
models:
|
||||
- provider: "gemini"
|
||||
role: "vision"
|
||||
@@ -127,9 +136,6 @@ models:
|
||||
- "智能摄像头-3"
|
||||
- "智能摄像头-4"
|
||||
timeout: 600
|
||||
# 问答专用超时(跟上面视频分析的 timeout 分开):用户在等交互式回答,一个
|
||||
# key/模型卡住不该等 10 分钟,超时要短,快速降级到下一个 key/模型/provider
|
||||
chat_timeout: 20
|
||||
# 模型级独立超时(最终值,不参与编排层 ×2 放大)
|
||||
# gemini-flash-lite 实测 ~22-34s,按用户要求放宽至 8 分钟(480s),避免大视频/排队时过早切断
|
||||
model_timeouts:
|
||||
@@ -159,7 +165,6 @@ models:
|
||||
base_url: "https://integrate.api.nvidia.com/v1"
|
||||
api_key: "${NVIDIA_API_KEY}"
|
||||
timeout: 600
|
||||
chat_timeout: 20 # 问答专用超时,跟视频分析的 timeout 分开
|
||||
max_base64_mb: 20 # 超过此大小直接跳过 NVIDIA,不做注定失败的编码+上传
|
||||
switch_interval_sec: 5 # 模型切换间隔:一个失败后等待再试下一个(未来加模型时用)
|
||||
model_timeouts: # 模型级独立超时(最终值,不参与 ×2)
|
||||
@@ -169,75 +174,3 @@ models:
|
||||
threshold: 5
|
||||
cooldown: 300
|
||||
|
||||
# 问答专用 NVIDIA 文字模型链(2026-08-23 新增,跟上面视频分析用的 omni 模型
|
||||
# 完全独立):用户要求问答不用 flash/omni,优先找 NVIDIA 免费文字模型里上下文
|
||||
# 最大的几个。实测(2026-08-23)在当前账号可用、非 deprecated 的候选里:
|
||||
# nemotron-3-ultra-550b-a55b: 1M 上下文,561B,最强,free endpoint 已验证可调
|
||||
# nemotron-3-super-120b-a12b: 1M 上下文,124B,同为 Nemotron-3 系列备份
|
||||
# openai/gpt-oss-120b: 131K 上下文,117B,不同厂商备份(Nemotron 系列整体
|
||||
# 出问题时的多样性兜底)
|
||||
# 淘汰原因记录:meta/llama-3.1-70b-instruct、nvidia/llama-3.3-nemotron-
|
||||
# super-49b-v1.5 均已收到 "will be deprecated on 08/25/2026" 通知,不用;
|
||||
# nvidia/llama-3.1-nemotron-ultra-253b-v1、mistralai/mistral-large-2-instruct、
|
||||
# nvidia/nemotron-4-340b-instruct、moonshotai/kimi-k2.6 在 /v1/models 目录
|
||||
# 里能看到,但实测调用 chat.completions 返回 404 "Not found for account"
|
||||
# (免费层没有这些模型的调用权限,文档列出不代表能调)。
|
||||
- provider: "nvidia"
|
||||
role: "text"
|
||||
usage: "qa_primary"
|
||||
enabled: true
|
||||
model_name: "nvidia/nemotron-3-ultra-550b-a55b"
|
||||
fallback_models:
|
||||
- "nvidia/nemotron-3-super-120b-a12b"
|
||||
- "openai/gpt-oss-120b"
|
||||
base_url: "https://integrate.api.nvidia.com/v1"
|
||||
api_key: "${NVIDIA_API_KEY}"
|
||||
timeout: 600
|
||||
# 这几个都是"推理"模型,回答前会先输出一段思考过程再给最终答案,比普通模型
|
||||
# 更费 token/更慢,问答超时给宽松一点(不是简单文字模型那种 20s 就该出结果)
|
||||
chat_timeout: 45
|
||||
switch_interval_sec: 3
|
||||
circuit_breaker:
|
||||
enabled: true
|
||||
threshold: 5
|
||||
cooldown: 300
|
||||
|
||||
# 问答专用 Gemini 非 flash 文字模型(2026-08-23 新增):用户明确要求问答不用
|
||||
# flash,这里走 gemini-pro-latest(1M 上下文,跟 gemini-flash-latest 同样的
|
||||
# "-latest" 别名习惯,自动跟最新 pro 版本),失败再退 gemini-2.5-pro。
|
||||
# key 复用视频分析同一批(各自独立 Google Cloud 项目,配额互不影响)。
|
||||
- provider: "gemini"
|
||||
role: "text"
|
||||
usage: "qa_primary"
|
||||
enabled: true
|
||||
model_name: "gemini-pro-latest"
|
||||
fallback_models:
|
||||
- "gemini-2.5-pro"
|
||||
api_key: "${GEMINI_API_KEY}"
|
||||
extra_api_keys:
|
||||
- "${GEMINI_API_KEY_2}"
|
||||
- "${GEMINI_API_KEY_3}"
|
||||
- "${GEMINI_API_KEY_4}"
|
||||
key_labels:
|
||||
- "智能摄像头-1"
|
||||
- "智能摄像头-2"
|
||||
- "智能摄像头-3"
|
||||
- "智能摄像头-4"
|
||||
timeout: 60
|
||||
chat_timeout: 30
|
||||
circuit_breaker:
|
||||
enabled: true
|
||||
threshold: 5
|
||||
cooldown: 300
|
||||
|
||||
# 本地模型:纯文本 qwen2.5:7b,仅参与智能问答兜底
|
||||
- provider: "ollama"
|
||||
role: "text"
|
||||
usage: "qa_fallback"
|
||||
enabled: true
|
||||
model_name: "qwen2.5:7b"
|
||||
base_url: "http://localhost:11434"
|
||||
timeout: 120
|
||||
num_predict: 512
|
||||
circuit_breaker:
|
||||
enabled: false
|
||||
|
||||
Reference in New Issue
Block a user