瀏覽代碼

修复提示词

李富豪 11 月之前
父節點
當前提交
34e6ab9170
共有 4 個文件被更改,包括 38 次插入14 次删除
  1. 13 0
      app/client/platforms/bigModel.ts
  2. 4 7
      app/components/chat.tsx
  3. 17 0
      app/components/sidebar.tsx
  4. 4 7
      app/store/chat.ts

+ 13 - 0
app/client/platforms/bigModel.ts

@@ -22,6 +22,8 @@ export class BigModelApi implements LLMApi {
   constructor() {
     this.baseURL = '/bigmodel-api';
     this.apiPath = this.baseURL + '/bigmodel/api/model-api/sse-invoke';
+    // 本地流式调用
+    // this.apiPath = '  http://xia0miduo.gicp.net:8091' + '/bigmodel/api/model-api/sse-invoke';
   }
 
   async chat(options: ChatOptions) {
@@ -166,6 +168,17 @@ export class BigModelApi implements LLMApi {
               content: item.content,
             })),
           };
+          const messages = session.messages.slice();
+          const backList = messages.reverse();
+          const record = backList.find(item => item.content && item.role === 'assistant');
+          if (record) {
+            useChatStore.setState({
+              message: {
+                content: record.content as string,
+                role: record.role,
+              }
+            });
+          }
           await api.post('bigmodel/api/dialog/save', data);
         },
         onerror(e) {

+ 4 - 7
app/components/chat.tsx

@@ -609,7 +609,7 @@ export function ChatActions(props: {
     }
   }, [chatStore, currentModel, models]);
 
-  const fetchGuessList = async (record: ChatMessage) => {
+  const fetchGuessList = async (record: { content: string; role: string }) => {
     try {
       const data = {
         appId: session.appId,
@@ -629,13 +629,10 @@ export function ChatActions(props: {
 
   useEffect(() => {
     setGuessList([]);
-    const messages = session.messages.slice();
-    const backList = messages.reverse();
-    const item = backList.find(item => item.content && item.role === 'assistant')
-    if (item) {
-      fetchGuessList(item)
+    if (chatStore.message.content) {
+      fetchGuessList(chatStore.message);
     }
-  }, [session.messages.length]);
+  }, [chatStore.message]);
 
   return (
     <div className={styles["chat-input-actions"]}>

+ 17 - 0
app/components/sidebar.tsx

@@ -345,6 +345,12 @@ export const SideBar = (props: { className?: string }) => {
               chatStore.updateCurrentSession((value) => {
                 value.appId = globalStore.selectedAppId;
               });
+              useChatStore.setState({
+                message: {
+                  content: '',
+                  role: 'assistant',
+                }
+              });
               if (getType() === 'bigModel') {
                 navigate({ pathname: '/newChat' });
               } else {
@@ -383,6 +389,17 @@ export const SideBar = (props: { className?: string }) => {
             value.id = session.id;
             value.messages = list;
           });
+          const messages = session.messages.slice();
+          const backList = messages.reverse();
+          const record = backList.find((item: any) => item.content && item.role === 'assistant');
+          if (record) {
+            useChatStore.setState({
+              message: {
+                content: record.content as string,
+                role: record.role,
+              }
+            });
+          }
           if (getType() === 'bigModel') {
             navigate({ pathname: '/newChat' });
           } else {

+ 4 - 7
app/store/chat.ts

@@ -169,6 +169,10 @@ const DEFAULT_CHAT_STATE = {
   model: 'BigModel' as 'BigModel' | 'DeepSeek',
   sessions: [createEmptySession()],
   currentSessionIndex: 0,
+  message: {
+    content: '',
+    role: 'assistant',
+  },
 };
 
 export const useChatStore = createPersistStore(
@@ -620,13 +624,6 @@ export const useChatStore = createPersistStore(
 
         const lastSummarizeIndex = session.messages.length;
 
-        console.log(
-          "[Chat History] ",
-          toBeSummarizedMsgs,
-          historyMsgLength,
-          modelConfig.compressMessageLengthThreshold,
-        );
-
         if (
           historyMsgLength > modelConfig.compressMessageLengthThreshold &&
           modelConfig.sendMemory