Add vision model support and related configurations in Assistant

- Introduce new fields in AssistantConfig, schemas, and database models to support vision capabilities, including `vision_enabled` and `vision_model_resource_id`.
- Enhance validation logic in routes to ensure proper handling of vision models and their requirements.
- Update the AssistantPage and related frontend components to include options for enabling vision understanding and selecting appropriate vision models.
- Modify database seed scripts to include vision-related data for assistants, ensuring consistent setup.
- Refactor related functions to integrate vision model handling in the audio-visual processing pipeline.
This commit is contained in:
Xin Wang
2026-07-07 21:50:15 +08:00
parent c51a70e134
commit 5f71bf1681
10 changed files with 180 additions and 41 deletions

View File

@@ -74,6 +74,16 @@ async def _resolve_config(offer: SignalingOffer) -> AssistantConfig:
raise ValueError("offer 缺少 assistant_id 或 inline_config")
def _apply_vision_model(cfg: AssistantConfig) -> None:
cfg.model = cfg.vision_model
cfg.llm_interface_type = cfg.vision_llm_interface_type
cfg.llm_values = cfg.vision_llm_values
cfg.llm_secrets = cfg.vision_llm_secrets
cfg.llm_support_image_input = cfg.vision_llm_support_image_input
cfg.llm_api_key = cfg.vision_llm_api_key
cfg.llm_base_url = cfg.vision_llm_base_url
async def _handle_offer(websocket, payload, peers):
from pipecat.transports.smallwebrtc.connection import SmallWebRTCConnection
from services.pipecat.pipeline import run_pipeline
@@ -87,8 +97,13 @@ async def _handle_offer(websocket, payload, peers):
await pc.renegotiate(sdp=offer.sdp, type=offer.type, restart_pc=False)
else:
cfg = await _resolve_config(offer) # 解析放在建连前,配置错就别建连
if offer.vision_enabled and not cfg.llm_support_image_input:
raise ValueError("当前大语言模型不支持图片输入,请在模型资源中选择支持图片输入的 LLM")
vision_enabled = offer.vision_enabled or cfg.vision_enabled
if vision_enabled:
if not cfg.vision_llm_support_image_input:
raise ValueError(
"当前视觉模型不支持图片输入,请在模型资源中选择支持图片输入的 LLM"
)
_apply_vision_model(cfg)
pc = SmallWebRTCConnection(ice_servers=aiortc_ice_servers())
if pc_id:
pc._pc_id = pc_id
@@ -102,10 +117,10 @@ async def _handle_offer(websocket, payload, peers):
# 后台跑管线:WebRTC transport + 解析出的运行时配置
transport = build_webrtc_transport(
pc,
video_in_enabled=offer.vision_enabled,
video_in_enabled=vision_enabled,
)
asyncio.create_task(
run_pipeline(transport, cfg, vision_enabled=offer.vision_enabled)
run_pipeline(transport, cfg, vision_enabled=vision_enabled)
)
answer = pc.get_answer()