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:
ericwyuan
2026-08-23 14:12:01 +08:00
parent 9dff19e6ac
commit 5caeb299a4
12 changed files with 310 additions and 614 deletions

View File

@@ -37,11 +37,9 @@ class BaseModelAdapter(ABC):
def __init__(self, provider_name: str, config: dict):
self.provider_name = provider_name # 如 "ollama", "gemini"
self.config = config
# 角色: vision=视觉分析, text=智能问答; 默认 vision
# 角色: vision=视觉分析, text=智能问答(问答链路已抽离到 ai-gateway
# 这里目前只有 vision 在用text 角色留给尚未清理的旧 person_service
self.role = config.get('role', 'vision')
# usage: 纯文档/编排层筛选用的标记(如 "qa_primary"/"qa_fallback"
# 不影响本适配器自身行为QAOrchestrator 据此挑选参与问答链路的适配器。
self.usage = config.get('usage', '')
# 模型调用统计回调(由编排层注入):
# hook(provider, model, started_at, duration_sec, success, error)
self.model_call_hook = None