Browse Source

历史记录流式添加思考过程

zhangwl 1 month ago
parent
commit
8c84601ae9
2 changed files with 10 additions and 3 deletions
  1. 1 1
      chat-ai-ui-main/src/components/ChatInput.vue
  2. 9 2
      chat-ai-ui-main/src/stores/chat.ts

+ 1 - 1
chat-ai-ui-main/src/components/ChatInput.vue

@@ -32,7 +32,7 @@ const sendMessage = () => {
   // 检查消息是否为空,如果为空则直接返回
   if (!message.value.trim()) return;
   // 触发send事件,传递消息和相关参数
-  emit('send', message.value, model.value, temperature.value, maxTokens.value, stream.value);
+  emit('send', message.value, stream.value);
   // 清空消息输入框
   message.value = '';
 };

+ 9 - 2
chat-ai-ui-main/src/stores/chat.ts

@@ -6,6 +6,8 @@ import { useUserStore } from './user';
 interface FormattedMessage {
   role: 'user' | 'assistant';
   content: string;
+  thinking?: string | null;
+  searching?: string | null;
 }
 
 interface Message {
@@ -48,7 +50,12 @@ export const useChatStore = defineStore('chat', () => {
           role: msg.role,
           content: msg.content,
           displayContent: msg.content,
-          ...blankMeta(),
+          thinkingContent: msg.thinking || '',
+          thinkingDisplayContent: msg.thinking || '',
+          isThinkingCollapsed: true,
+          searchingItems: msg.searching ? [msg.searching] : [],
+          phase: 'done' as const,
+          isStreaming: false,
         }));
     } catch (error) {
       console.error('Error loading chat history: ', error);
@@ -56,7 +63,7 @@ export const useChatStore = defineStore('chat', () => {
   };
 
   const sendMessage = async (message: string, stream: boolean) => {
-    if (!message.trim() || !userStore.userId) return;
+    if (!message.trim() || !userStore.userId || isLoading.value) return;
 
     messages.value.push({ role: 'user', content: message, displayContent: message, ...blankMeta() });
     isLoading.value = true;