feat: support image inputs in assistant tests
This commit is contained in:
@@ -34,12 +34,11 @@ from services.tool_policy import policy_for_tool
|
||||
from services.vision import (
|
||||
VISION_TOOL_NAME,
|
||||
analyze_image_with_vision_model,
|
||||
config_with_main_llm_as_vision,
|
||||
config_with_vision_resource,
|
||||
image_data_uri,
|
||||
image_frame_from_jpeg,
|
||||
image_jpeg_bytes,
|
||||
resolve_vision_question,
|
||||
resolve_vision_input,
|
||||
vision_system_hint,
|
||||
vision_tool_schema_parts,
|
||||
)
|
||||
@@ -151,30 +150,6 @@ def _require(value: str, label: str) -> str:
|
||||
raise ValueError(f"缺少模型资源配置: {label}")
|
||||
|
||||
|
||||
def _vision_uses_main_llm(cfg: AssistantConfig) -> bool:
|
||||
"""模型自己支持图片时,沿用 Pipecat 的同上下文视觉工具路径。"""
|
||||
return not cfg.vision_model_resource_id and cfg.llm_support_image_input
|
||||
|
||||
|
||||
def _workflow_vision_uses_main_llm(
|
||||
cfg: AssistantConfig,
|
||||
scope: dict[str, Any],
|
||||
) -> bool:
|
||||
"""Resolve native versus auxiliary vision for the active Workflow Agent."""
|
||||
if not scope.get("enabled"):
|
||||
raise ValueError("当前 Workflow Agent 节点未启用视觉能力")
|
||||
if scope.get("vision_model_resource_id"):
|
||||
return False
|
||||
|
||||
llm_resource_id = str(scope.get("llm_resource_id") or "")
|
||||
resource = cfg.workflow_model_resources.get(llm_resource_id)
|
||||
if not resource:
|
||||
raise ValueError(f"当前 Workflow Agent 的 LLM 资源未加载:{llm_resource_id}")
|
||||
if not resource.support_image_input:
|
||||
raise ValueError("当前 Workflow Agent 的 LLM 不支持图片输入")
|
||||
return True
|
||||
|
||||
|
||||
def _multimodal_user_input_frame(
|
||||
image_frame: UserImageRawFrame,
|
||||
prompt_text: str,
|
||||
@@ -485,7 +460,7 @@ async def run_pipeline(
|
||||
vision_native_mode = (
|
||||
vision_enabled
|
||||
and cfg.type != "workflow"
|
||||
and _vision_uses_main_llm(cfg)
|
||||
and resolve_vision_input(cfg).native
|
||||
)
|
||||
vision_state: dict[str, str | None] = {"client_id": None}
|
||||
workflow_vision_scope: dict[str, Any] = {
|
||||
@@ -497,9 +472,9 @@ async def run_pipeline(
|
||||
}
|
||||
|
||||
def active_vision_uses_main_llm() -> bool:
|
||||
if cfg.type == "workflow":
|
||||
return _workflow_vision_uses_main_llm(cfg, workflow_vision_scope)
|
||||
return vision_native_mode
|
||||
if cfg.type != "workflow":
|
||||
return vision_native_mode
|
||||
return resolve_vision_input(cfg, workflow_vision_scope).native
|
||||
vision_description, vision_properties, vision_required = vision_tool_schema_parts(
|
||||
cfg.vision_prompt_mode,
|
||||
cfg.vision_prompt,
|
||||
@@ -609,29 +584,8 @@ async def run_pipeline(
|
||||
workflow_vision_function = None
|
||||
|
||||
def active_vision_config() -> AssistantConfig:
|
||||
if cfg.type != "workflow":
|
||||
return cfg
|
||||
if not workflow_vision_scope.get("enabled"):
|
||||
raise ValueError("当前 Workflow Agent 节点未启用视觉能力")
|
||||
vision_resource_id = str(
|
||||
workflow_vision_scope.get("vision_model_resource_id") or ""
|
||||
)
|
||||
llm_resource_id = str(workflow_vision_scope.get("llm_resource_id") or "")
|
||||
resource_id = vision_resource_id or llm_resource_id
|
||||
resource = cfg.workflow_model_resources.get(resource_id)
|
||||
if resource:
|
||||
result = config_with_vision_resource(cfg, resource)
|
||||
elif not vision_resource_id:
|
||||
result = config_with_main_llm_as_vision(cfg)
|
||||
else:
|
||||
raise ValueError(f"视觉模型资源未加载:{vision_resource_id}")
|
||||
result.vision_prompt_mode = str(
|
||||
workflow_vision_scope.get("vision_prompt_mode") or "runtime"
|
||||
)
|
||||
result.vision_prompt = str(
|
||||
workflow_vision_scope.get("vision_prompt") or ""
|
||||
).strip()
|
||||
return result
|
||||
scope = workflow_vision_scope if cfg.type == "workflow" else None
|
||||
return resolve_vision_input(cfg, scope).config
|
||||
|
||||
if cfg.type == "workflow" and vision_enabled:
|
||||
async def native_flow_fetch_user_image(params: FunctionCallParams) -> None:
|
||||
|
||||
Reference in New Issue
Block a user