feat(agents): 图片附件 + 修两个真 bug(版本 2.5.0 → 2.5.1)
老板要求「图片附件功能加上,其他的先不做」。
QwenPaw 侧格式(实测确认后再动手):{"type":"image","image_url":"<data-URI>"
—— 塞纯红 64×64 PNG 的 data URI,模型正确答出「红色」。
改动:
- app/adapters/qwenpaw_engine.py:放行图片内容块,并同时支持两种写法 ——
AgentScope 原生 image 与 OpenAI 风格 image_url(前端发的是后者);
新增 _image_url();缺 url 的块跳过;audio/video/file 仍忽略
- views/Agents.vue:对话输入区加附件按钮(pickImage 复用现有浏览器内压缩,最多 4 张)
+ 待发缩略图可删 + 消息气泡内渲染图片;允许「只发图不带字」
- lib/agents.ts:content 放宽为 string | any[]
- i18n 新增 4 键,中英对称 879/879
修掉两个真 bug(本轮才暴露):
1. image_url 写法被忽略 —— 分支只认 type=="image",而前端发 image_url
→ 图片会静默丢失(功能等于没做)。测试用例抓出来的。
2. /agents/{slug}/chat 500 —— 上轮加计量打标时 log.info(..., rounds) 写在
rounds = ... 之前,UnboundLocalError → 端点 500。已加回归用例
test_agent_chat_endpoint_source_order 固化(这类声明顺序错误跑不出来)。
上线实测:两张图(红+蓝)→ 模型答「红色,蓝色」顺序正确,system_suffix 同时生效,
usage wjd/24112 tokens/缓存 2048;浏览器路径也验证过(上传→缩略图→发送→渲染→无 JS 错误)。
已知引擎侧行为(非网关问题):QwenPaw SSE 只有 text 事件、无独立 reasoning 通道,
模型有时把思考写进正文;且上下文会污染视觉判断(同图脏上下文答「白色」、干净会话答「蓝色」)。
测试 218 → 219 全过。
This commit is contained in:
1 parent
e12403fa15
commit
18ba405b64
9 files changed
+230
-16
No files matched your search
@@ -343,12 +343,13 @@ def install(app: FastAPI, *, store: AgentStore,
|
||||
|
||||
p = a.params or {}
|
||||
suffix = str(p.get("system_suffix") or "")
|
||||
# 第四十轮(计量打标):让日志能一眼看出"这次调用是网关的智能体发出的",
|
||||
# 与管理员在「对话」页直接聊区分开。明细(谁/哪个智能体/多少 token)落 agent_runs。
|
||||
log.info("agent chat: slug=%s account=%s session=%s rounds=%d",
|
||||
slug, account, session_id, rounds)
|
||||
started = time.time()
|
||||
rounds = len([m for m in messages if isinstance(m, dict) and m.get("role") == "user"])
|
||||
# 计量打标:让日志能一眼看出"这次调用是网关的智能体发出的",
|
||||
# 与管理员在「对话」页直接聊区分开。明细(谁/哪个智能体/多少 token)落 agent_runs。
|
||||
# 注意:这行必须在 rounds 赋值**之后**(曾因前置引用 rounds 导致 500)。
|
||||
log.info("agent chat: slug=%s account=%s session=%s rounds=%d",
|
||||
slug, account, session_id, rounds)
|
||||
tool_count = 0
|
||||
total_tokens = 0
|
||||
status = "ok"
|
||||
|
||||
Reference in new issue
Block a user