Explorar el Código

增加中断聊天功能

李富豪 hace 7 meses
padre
commit
5f84f7db01

+ 5 - 1
app/client/platforms/deepSeek.ts

@@ -22,6 +22,7 @@ export class DeepSeekApi implements LLMApi {
   constructor() {
     this.baseURL = '/deepseek-api';
     this.apiPath = this.baseURL + '/vllm/ai/chat';
+    // this.apiPath = 'http://192.168.3.209:18078' + '/vllm/ai/chat';
   }
 
   async chat(options: ChatOptions) {
@@ -56,9 +57,12 @@ export class DeepSeekApi implements LLMApi {
       });
     }
 
+    const isDeepThink = useChatStore.getState().isDeepThink;
+
     // 参数
     const params = {
-      model: 'DeepSeek-R1-Distill-Llama-70B',
+      // model: 'DeepSeek-R1-Distill-Qwen-14B',
+      model: isDeepThink ? 'DeepSeek-R1-Distill-Llama-70B' : 'Qwen2-72B',
       messages: userMessages,
       stream: true,
       document_id: (item && item.document) ? item.document.id : undefined,

+ 54 - 10
app/components/DeepSeekChat.tsx

@@ -20,6 +20,7 @@ import CancelIcon from "../icons/cancel.svg";
 import SizeIcon from "../icons/size.svg";
 import avatar from "../icons/aiIcon.png";
 import sdsk from "../icons/sdsk.png";
+import sdsk_selected from "../icons/sdsk_selected.png";
 import hlw from "../icons/hlw.png";
 
 import {
@@ -882,7 +883,6 @@ function _Chat() {
     setUserInput("");
     setPromptHints([]);
     if (!isMobileScreen) inputRef.current?.focus();
-    setFileList([]);
     setAutoScroll(true);
   };
 
@@ -1346,6 +1346,16 @@ function _Chat() {
     return icon;
   }
 
+  const [isDeepThink, setIsDeepThink] = useState<boolean>(chatStore.isDeepThink);
+
+  // 切换聊天窗口后清理上传文件信息
+  useEffect(() => {
+    setFileList([])
+  }, [chatStore.currentSession()])
+
+  const couldStop = ChatControllerPool.hasPending();
+  const stopAll = () => ChatControllerPool.stopAll();
+
   return (
     <div className={styles.chat} key={session.id}>
       {
@@ -1472,7 +1482,6 @@ function _Chat() {
           })}
         </>
       </div>
-
       <div className={styles["chat-input-panel"]}>
         <ChatActions
           setUserInput={setUserInput}
@@ -1489,7 +1498,6 @@ function _Chat() {
               setPromptHints([]);
               return;
             }
-
             inputRef.current?.focus();
             setUserInput("/");
             onSearch("");
@@ -1558,9 +1566,25 @@ function _Chat() {
         <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 10 }}>
           <div style={{ display: 'flex', alignItems: 'center' }}>
             <div
-              style={{ padding: '0 10px', height: 30, borderRadius: 30, fontSize: 12, background: '#f3f4f6', display: 'flex', justifyContent: 'center', alignItems: 'center', marginRight: 20 }}
+              style={{
+                padding: '0 10px',
+                height: 30,
+                borderRadius: 30,
+                fontSize: 12,
+                display: 'flex',
+                justifyContent: 'center',
+                alignItems: 'center',
+                marginRight: 20,
+                cursor: 'pointer',
+                background: isDeepThink ? '#dee9fc' : '#f3f4f6',
+                color: isDeepThink ? '#3875f6' : '#000000',
+              }}
+              onClick={() => {
+                setIsDeepThink(!isDeepThink);
+                chatStore.setIsDeepThink(!isDeepThink);
+              }}
             >
-              <img src={sdsk.src} style={{ height: 23 }} />
+              <img src={isDeepThink ? sdsk_selected.src : sdsk.src} style={{ height: 23 }} />
               <div style={{ marginLeft: 5 }}>
                 深度思考(R1)
               </div>
@@ -1613,12 +1637,32 @@ function _Chat() {
             </div>
             <div
               style={{
-                width: 35, height: 35, borderRadius: '50%', background: '#4357d2', display: 'flex', justifyContent: 'center', alignItems: 'center', cursor: 'pointer'
+                width: 35,
+                height: 35,
+                borderRadius: '50%',
+                background: '#4357d2',
+                display: 'flex',
+                justifyContent: 'center',
+                alignItems: 'center',
+                cursor: 'pointer',
+              }}
+              onClick={() => {
+                if (couldStop) {
+                  stopAll();
+                } else {
+                  doSubmit(userInput);
+                }
               }}
-              onClick={() => doSubmit(userInput)}
             >
-              <div style={{ transform: 'rotate(-45deg)', padding: '0px 0px 3px 5px' }}>
-                <SendOutlined style={{ color: '#FFFFFF' }} />
+              {
+                couldStop ?
+                  <div style={{ width: 13, height: 13, background: '#FFFFFF', borderRadius: 2 }}></div>
+                  :
+                  <div style={{ transform: 'rotate(-45deg)', padding: '0px 0px 3px 5px' }}>
+                    <SendOutlined style={{ color: '#FFFFFF' }} />
+                  </div>
+              }
+              <div>
               </div>
             </div>
           </div>
@@ -1641,7 +1685,7 @@ function _Chat() {
           />
         )
       }
-    </div >
+    </div>
   );
 }
 

BIN
app/icons/sdsk_selected.png


+ 4 - 0
app/store/chat.ts

@@ -172,6 +172,7 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
 const DEFAULT_CHAT_STATE = {
   model: 'BigModel' as 'BigModel' | 'DeepSeek',
   chatMode: 'ONLINE' as 'ONLINE' | 'LOCAL',
+  isDeepThink: true,
   sessions: [createEmptySession()],
   currentSessionIndex: 0,
   message: {
@@ -196,6 +197,9 @@ export const useChatStore = createPersistStore(
       setChatMode(mode: 'ONLINE' | 'LOCAL') {
         set({ chatMode: mode });
       },
+      setIsDeepThink(status: boolean) {
+        set({ isDeepThink: status });
+      },
       clearSessions() {
         set(() => ({
           sessions: [createEmptySession()],