Преглед изворни кода

修复聊天切片异常问题

李富豪 пре 6 месеци
родитељ
комит
539bf666b5
1 измењених фајлова са 29 додато и 33 уклоњено
  1. 29 33
      app/client/platforms/bigModel.ts

+ 29 - 33
app/client/platforms/bigModel.ts

@@ -21,6 +21,7 @@ export class BigModelApi implements LLMApi {
 
   constructor() {
     const chatMode = useChatStore.getState().chatMode;
+    // this.baseURL = 'http://xia0miduo.gicp.net:8401';
     this.baseURL = '/bigmodel-api';
     if (chatMode === 'LOCAL') {
       this.apiPath = this.baseURL + '/deepseek/api/chat';
@@ -108,8 +109,6 @@ export class BigModelApi implements LLMApi {
       };
 
       controller.signal.onabort = finish;
-
-      let start = true;
       let sliceInfoPromise: Promise<void> | null = null;
 
       fetchEventSource(chatPath, {
@@ -151,7 +150,34 @@ export class BigModelApi implements LLMApi {
         onmessage: async (msg) => {
           const info = JSON.parse(msg.data);
           if (info.event === 'finish') {
-            start = true;
+            const chatMode = useChatStore.getState().chatMode;
+            if (chatMode === 'LOCAL') {// 切片
+              sliceInfoPromise = (async () => {
+                try {
+                  const res: any = await api.get(`deepseek/api/slice/search/${info.id}`);
+                  const sliceInfo = {
+                    ...res.data,
+                  };
+                  delete sliceInfo.code;
+                  useChatStore.getState().updateCurrentSession((session) => {
+                    session.messages = session.messages.map((item, index) => {
+                      if (index === session.messages.length - 1 && item.role !== 'user') {
+                        return {
+                          ...item,
+                          sliceInfo: sliceInfo,
+                        };
+                      } else {
+                        return {
+                          ...item,
+                        }
+                      }
+                    });
+                  });
+                } catch (error) {
+                  console.error(error);
+                }
+              })();
+            }
             return finish();
           }
 
@@ -167,36 +193,6 @@ export class BigModelApi implements LLMApi {
           } else {
             remainText += currentData;
           }
-
-          const chatMode = useChatStore.getState().chatMode;
-          if (chatMode === 'LOCAL' && start) {// 切片
-            start = false;
-            sliceInfoPromise = (async () => {
-              try {
-                const res: any = await api.get(`deepseek/api/slice/search/${info.id}`);
-                const sliceInfo = {
-                  ...res.data,
-                };
-                delete sliceInfo.code;
-                useChatStore.getState().updateCurrentSession((session) => {
-                  session.messages = session.messages.map((item, index) => {
-                    if (index === session.messages.length - 1 && item.role !== 'user') {
-                      return {
-                        ...item,
-                        sliceInfo: sliceInfo,
-                      };
-                    } else {
-                      return {
-                        ...item,
-                      }
-                    }
-                  });
-                });
-              } catch (error) {
-                console.error(error);
-              }
-            })();
-          }
         },
         async onclose() {
           finish();