feat: 工具调用改为独立 SSE 事件并以中文状态条展示

This commit is contained in:
2026-09-20 11:45:00 +08:00
parent 9b240b35a9
commit de0bbb1a9c
9 changed files with 179 additions and 19 deletions
+6 -5
View File
@@ -10,7 +10,7 @@ from application.llm_settings_service import LlmRuntimeService
from application.memory_service import MemoryService
from application.session_service import SessionService
from config.settings import Settings
from domain.models import Actor, ChatMessage, MessageRole
from domain.models import Actor, ChatMessage, MessageRole, StreamEvent
from domain.ports import ChatStreamer, MessageRepository, SessionRepository
@@ -44,7 +44,7 @@ class ChatService:
async def stream_chat(
self, actor: Actor, thread_id: str, content: str
) -> AsyncIterator[str]:
) -> AsyncIterator[StreamEvent]:
text = (content or "").strip()
if not text:
raise ValueError("消息不能为空")
@@ -85,7 +85,7 @@ class ChatService:
await self._session_repo.update(session)
parts: list[str] = []
async for chunk in self._streamer.stream_reply(
async for event in self._streamer.stream_reply(
llm=llm,
history=history,
user_text=text,
@@ -93,8 +93,9 @@ class ChatService:
memory_count=memory_count,
memory_just_saved=just_saved,
):
parts.append(chunk)
yield chunk
if event.kind == "token" and event.text:
parts.append(event.text)
yield event
full = "".join(parts).strip() or "(模型未返回内容)"
a_seq = await self._messages.next_seq(actor.company_id, actor.user_id, thread_id)