[3.1-3.5] FAM-Edge 全链路 - API-Gateway/Video-Preprocessor/AI-Orchestrator/模型适配器(基类+Ollama+Gemini)/熔断器/JSON解析容错 + 配置

This commit is contained in:
ericwyuan
2026-08-19 22:25:38 +08:00
parent da6b1c8d39
commit cdd1f21d4c
20 changed files with 1384 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
"""
模型适配器基类 - 所有模型适配器的抽象基类
新增模型只需继承此类并实现 4 个方法:
1. health_check() -> bool
2. analyze_frames(frame_paths, frame_timestamps, known_members_context) -> Optional[str]
3. get_timeout() -> int
4. get_circuit_breaker() -> CircuitBreaker
"""
from abc import ABC, abstractmethod
from typing import List, Optional
class BaseModelAdapter(ABC):
"""所有模型适配器的抽象基类"""
def __init__(self, provider_name: str, config: dict):
self.provider_name = provider_name # 如 "ollama", "gemini"
self.config = config
@abstractmethod
def health_check(self) -> bool:
"""健康检查,返回 True/False"""
pass
@abstractmethod
def analyze_frames(self, frame_paths: List[str],
frame_timestamps: List[str],
known_members_context: str) -> Optional[str]:
"""视觉分析:输入帧图片路径 + 时间戳 + 成员清单,输出自然语言描述。
失败/超时返回 None。"""
pass
@abstractmethod
def get_timeout(self) -> int:
"""该模型的调用超时秒数"""
pass
@abstractmethod
def get_circuit_breaker(self):
"""返回该模型专属的熔断器实例"""
pass