From 609fdaf71f420fb7181fc5cca0036967e04c2109 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Sat, 19 Sep 2026 22:48:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20aichat=20=E6=94=B9=E7=94=A8=20tdesign?= =?UTF-8?q?=20chat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/agent/infrastructure/llm_factory.py | 28 +- apps/web/apps/web-antd/package.json | 7 +- .../web-antd/src/views/agent/chat/index.vue | 261 +-- .../web-antd/src/views/agent/chat/markdown.ts | 21 - apps/web/patches/ant-design-x-vue@1.6.0.patch | 38 - apps/web/pnpm-lock.yaml | 1734 ++++++++++++++++- apps/web/pnpm-workspace.yaml | 4 - 7 files changed, 1782 insertions(+), 311 deletions(-) delete mode 100644 apps/web/apps/web-antd/src/views/agent/chat/markdown.ts delete mode 100644 apps/web/patches/ant-design-x-vue@1.6.0.patch diff --git a/apps/agent/infrastructure/llm_factory.py b/apps/agent/infrastructure/llm_factory.py index b06226d7..7f2cf3e4 100644 --- a/apps/agent/infrastructure/llm_factory.py +++ b/apps/agent/infrastructure/llm_factory.py @@ -59,20 +59,28 @@ class OpenAICompatibleStreamer(ChatStreamer): yield text return - # 工具轮:先非流式执行 tool_calls,最后一轮流式输出正文 + # 工具轮:每轮用 astream 边生成边推 token;出现 tool_call 再执行工具后继续 bound = model.bind_tools(tools) tool_map = {t.name: t for t in tools if getattr(t, "name", None)} for _ in range(5): - ai = await bound.ainvoke(messages) - messages.append(ai) - tool_calls = getattr(ai, "tool_calls", None) or [] + gathered = None + saw_tool = False + async for chunk in bound.astream(messages): + gathered = chunk if gathered is None else gathered + chunk + if getattr(chunk, "tool_call_chunks", None) or getattr(chunk, "tool_calls", None): + saw_tool = True + continue + if saw_tool: + continue + text = _chunk_text(getattr(chunk, "content", None)) + if text: + yield text + if gathered is None: + yield "(模型未返回内容)" + return + messages.append(gathered) + tool_calls = getattr(gathered, "tool_calls", None) or [] if not tool_calls: - content = ai.content if isinstance(ai.content, str) else _chunk_text(ai.content) - if content: - # 按小段 yield,便于前端渐进展示 - step = 24 - for i in range(0, len(content), step): - yield content[i : i + step] return yield f"\n[调用工具: {', '.join(tc.get('name', '?') for tc in tool_calls)}]\n" diff --git a/apps/web/apps/web-antd/package.json b/apps/web/apps/web-antd/package.json index 50e392e6..2ffd4f25 100644 --- a/apps/web/apps/web-antd/package.json +++ b/apps/web/apps/web-antd/package.json @@ -26,6 +26,7 @@ "#/*": "./src/*" }, "dependencies": { + "@tdesign-vue-next/chat": "^0.7.0", "@vben/access": "workspace:*", "@vben/common-ui": "workspace:*", "@vben/constants": "workspace:*", @@ -42,20 +43,16 @@ "@vben/utils": "workspace:*", "@vueuse/core": "catalog:", "ant-design-vue": "catalog:", - "ant-design-x-vue": "^1.6.0", "dayjs": "catalog:", - "dompurify": "^3.4.15", - "marked": "^18.0.13", "papaparse": "^5.4.1", "pinia": "catalog:", "spark-md5": "^3.0.2", + "tdesign-vue-next": "^1.20.8", "vue": "catalog:", "vue-router": "catalog:", "vue-waterfall-plugin-next": "^3.0.0" }, "devDependencies": { - "@types/dompurify": "^3.2.0", - "@types/marked": "^6.0.0", "@types/papaparse": "^5.3.14", "@types/spark-md5": "^3.0.5" } diff --git a/apps/web/apps/web-antd/src/views/agent/chat/index.vue b/apps/web/apps/web-antd/src/views/agent/chat/index.vue index 8a5a0029..5e049aed 100644 --- a/apps/web/apps/web-antd/src/views/agent/chat/index.vue +++ b/apps/web/apps/web-antd/src/views/agent/chat/index.vue @@ -1,19 +1,8 @@