From 410227aaf27ee91930f1b12ca57ba28bf82afb49 Mon Sep 17 00:00:00 2001 From: JianFeeeee <109188060+JianFeeeee@users.noreply.github.com> Date: Sat, 11 Apr 2026 23:07:45 +0800 Subject: [PATCH] Fix: Correct API call with system prompt and tools --- graph_memory_tui/services/chat_service.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/graph_memory_tui/services/chat_service.py b/graph_memory_tui/services/chat_service.py index 6bf1b74..fc96f43 100644 --- a/graph_memory_tui/services/chat_service.py +++ b/graph_memory_tui/services/chat_service.py @@ -188,6 +188,7 @@ class ChatService: def process_stream(): # 构建完整的消息列表 messages = [ + {"role": "system", "content": self._client.system_prompt}, {"role": "user", "content": user_input}, assistant_message ] @@ -195,8 +196,10 @@ class ChatService: # 调用API response = self._client.client.chat.completions.create( - model=self._client.tools[0]["function"]["name"] if self._client.tools else "deepseek-chat", + model="deepseek-chat", messages=messages, + tools=self._client.tools, + tool_choice="auto", stream=True ) @@ -204,6 +207,12 @@ class ChatService: delta = chunk.choices[0].delta if delta.content: yield {"content_delta": delta.content} + + # 处理可能的工具调用 + if delta.tool_calls: + # 如果还有工具调用,说明AI想继续调用工具 + # 但我们限制只调用一次,所以忽略 + pass for result in await loop.run_in_executor(None, lambda: list(process_stream())): yield result