图片上传识别功能

This commit is contained in:
renjianbo
2026-04-13 22:52:36 +08:00
parent df4fab1e6e
commit 63b54116a5
13 changed files with 708 additions and 17 deletions

View File

@@ -97,6 +97,31 @@ def _user_id_from_input(input_data: Optional[Dict[str, Any]]) -> Optional[str]:
return None
def _extract_attachments(input_data: Optional[Dict[str, Any]]) -> List[Dict[str, Any]]:
if not input_data:
return []
raw = input_data.get("attachments")
if not isinstance(raw, list):
return []
out: List[Dict[str, Any]] = []
for item in raw:
if not isinstance(item, dict):
continue
rel = str(item.get("relative_path") or "").strip()
name = str(item.get("filename") or "").strip()
if not rel:
continue
content_type = str(item.get("content_type") or "").strip() or None
out.append(
{
"relative_path": rel,
"filename": name or rel.rsplit("/", 1)[-1],
"content_type": content_type,
}
)
return out
def fetch_agent_preview_chat_turns(
db: Session,
agent_id: str,
@@ -149,6 +174,7 @@ def fetch_agent_preview_chat_turns(
"created_at": ex.created_at,
"user_text": user_text or "(无文本)",
"agent_text": agent_text or "(无输出)",
"attachments": _extract_attachments(inp),
}
)
return out