소스 검색

线上deepseek聊天

S0025136190 7 달 전
부모
커밋
1b9064788a
4개의 변경된 파일120개의 추가작업 그리고 20개의 파일을 삭제
  1. 12 2
      app/client/platforms/bigModel.ts
  2. 57 6
      app/components/chat.tsx
  3. 47 12
      app/components/sidebar.tsx
  4. 4 0
      app/store/chat.ts

+ 12 - 2
app/client/platforms/bigModel.ts

@@ -20,8 +20,13 @@ export class BigModelApi implements LLMApi {
   public apiPath: string;
 
   constructor() {
+    const status = useChatStore.getState().deepSeekStatus;
     this.baseURL = '/bigmodel-api';
-    this.apiPath = this.baseURL + '/bigmodel/api/model-api/sse-invoke';
+    if(status === 'LOCAL'){
+      this.apiPath = this.baseURL + '/bigmodel/api/model-api/sse-invoke';
+    }else{
+      this.apiPath = this.baseURL + '/takai/api/chat';
+    }
     // 本地流式调用
     // this.apiPath = '  http://xia0miduo.gicp.net:8091' + '/bigmodel/api/model-api/sse-invoke';
   }
@@ -179,7 +184,12 @@ export class BigModelApi implements LLMApi {
               }
             });
           }
-          await api.post('bigmodel/api/dialog/save', data);
+          const status = useChatStore.getState().deepSeekStatus;
+          if(status === 'LOCAL'){
+            await api.post('bigmodel/api/dialog/save', data);
+          }else{
+            await api.post('takai/api/dialog/save', data);
+          }
         },
         onerror(e) {
           options.onError?.(e);

+ 57 - 6
app/components/chat.tsx

@@ -620,7 +620,13 @@ export function ChatActions(props: {
           }
         ]
       }
-      const res = await api.post('/bigmodel/api/async/completions', data);
+      let url = '';
+      if (chatStore.deepSeekStatus === 'LOCAL') {
+        url = '/bigmodel/api/async/completions';
+      } else {
+        url = '/takai/api/async/completions';
+      }
+      const res = await api.post(url, data);
       setGuessList(res.data);
     } catch (error) {
       console.error(error);
@@ -972,8 +978,6 @@ function _Chat() {
     { leading: true, trailing: true },
   );
 
-  const [loading, setLoading] = useState<boolean>(false);
-
   type AppList = {
     label: string,
     value: string,
@@ -986,12 +990,30 @@ function _Chat() {
   type QuestionList = string[];
   const [questionList, setQuestionList] = useState<QuestionList>([]);
   const location = useLocation();
+  const [loading, setLoading] = useState<boolean>(false);
+
+  const fruits = [
+    { id: 'ONLINE', name: '线上' },
+    { id: 'LOCAL', name: '本地' },
+  ];
+
+  const [selectedFruit, setSelectedFruit] = React.useState(chatStore.deepSeekStatus); // 默认选中
+
+  useEffect(() => {
+  }, []);
 
   // 获取应用列表
   const fetchApplicationList = async () => {
     setLoading(true);
     try {
-      const res = await api.get('/bigmodel/api/application/list');
+      let url = null;
+      console.log('selectedFruit', selectedFruit);
+      if (selectedFruit === 'LOCAL') {
+        url = '/bigmodel/api/application/list';
+      } else {
+        url = '/takai/api/application/list';
+      }
+      const res = await api.get(url);
       const list = res.data.filter((item: any) => item.appId !== '1234567890123456789').map((item: any) => {
         return {
           label: item.name,
@@ -1027,7 +1049,13 @@ function _Chat() {
   // 获取预设问题列表
   const fetchDefaultQuestion = async (appId: string) => {
     try {
-      const res = await api.get(`/bigmodel/api/presets/${appId}`);
+      let url = null;
+      if (selectedFruit === 'LOCAL') {
+        url = '/bigmodel/api/presets';
+      } else {
+        url = '/takai/api/presets';
+      }
+      const res = await api.get(url + `/${appId}`);
       setQuestionList(res.data);
     } catch (error) {
       console.error(error);
@@ -1048,7 +1076,11 @@ function _Chat() {
     if (appValue) {
       fetchDefaultQuestion(appValue);
     }
-  }, [appValue])
+  }, [appValue, chatStore.deepSeekStatus])
+
+  useEffect(() => {
+    fetchApplicationList();
+  }, [chatStore.deepSeekStatus])
 
   const [inputRows, setInputRows] = useState(2);
   const measure = useDebouncedCallback(
@@ -1599,6 +1631,25 @@ function _Chat() {
                 null
             }
           </div>
+
+
+
+        </div>
+        <div>
+          <Select
+            style={{ width: '200', height: 38, marginRight: 5 }}
+            value={selectedFruit}
+            onChange={(value: "ONLINE" | "LOCAL") => {
+              setSelectedFruit(value);
+              chatStore.setDeepSeekStatus(value);
+            }}
+          >
+            {fruits.map(fruit => (
+              <Select.Option key={fruit.id} value={fruit.id}>
+                {fruit.name}
+              </Select.Option>
+            ))}
+          </Select>
         </div>
         <div className="window-actions">
           <div className="window-action-button">

+ 47 - 12
app/components/sidebar.tsx

@@ -205,7 +205,6 @@ export const SideBar = (props: { className?: string }) => {
   const [menuList, setMenuList] = useState([])
   const [modalOpen, setModalOpen] = useState(false)
   const [form] = Form.useForm();
-
   const getType = (): 'bigModel' | 'deepSeek' => {
     if (['/knowledgeChat', '/newChat'].includes(location.pathname)) {
       return 'bigModel';
@@ -217,7 +216,7 @@ export const SideBar = (props: { className?: string }) => {
   }
 
   // 获取聊天列表
-  const fetchChatList = async () => {
+  const fetchChatList = async (deepSeekStatus?:'ONLINE' | 'LOCAL') => {
     try {
       let appId = '';
       if (getType() === 'bigModel') {
@@ -225,7 +224,16 @@ export const SideBar = (props: { className?: string }) => {
       } else {
         appId = '1881269958412521255';
       }
-      const res = await api.get(`/bigmodel/api/dialog/list/${appId}`);
+
+      let url = '';
+      if (deepSeekStatus) {
+        if (deepSeekStatus==='LOCAL') {
+          url = `/bigmodel/api/dialog/list/${appId}`;
+        }else{
+          url = `/takai/api/dialog/list/${appId}`;
+        }
+      }
+      const res = await api.get(url);
       const list = res.data.map((item: any) => {
         return {
           ...item,
@@ -266,8 +274,13 @@ export const SideBar = (props: { className?: string }) => {
                 label: (
                   <a onClick={async () => {
                     try {
-                      await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
-                      await fetchChatList()
+                      if(deepSeekStatus === 'LOCAL'){
+                        await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
+                        await fetchChatList();
+                      }else{
+                        await api.delete(`/takai/api/dialog/del/${child.key}`);
+                        await fetchChatList(deepSeekStatus);
+                      }
                       chatStore.clearSessions();
                       useChatStore.setState({
                         message: {
@@ -320,6 +333,10 @@ export const SideBar = (props: { className?: string }) => {
     });
   }, []);
 
+  useEffect(() => {
+    fetchChatList(chatStore.deepSeekStatus);
+  }, [chatStore.deepSeekStatus]);
+
   return (
     <SideBarContainer
       onDragStart={onDragStart}
@@ -358,7 +375,11 @@ export const SideBar = (props: { className?: string }) => {
               } else {
                 navigate({ pathname: '/newDeepseekChat' });
               }
-              await fetchChatList()
+              if(chatStore.deepSeekStatus === 'LOCAL'){
+                await fetchChatList();
+              }else{
+                await fetchChatList(chatStore.deepSeekStatus);
+              }
             }}
           >
             新建对话
@@ -368,7 +389,13 @@ export const SideBar = (props: { className?: string }) => {
       <Menu
         style={{ border: 'none' }}
         onClick={async ({ key }) => {
-          const res = await api.get(`/bigmodel/api/dialog/detail/${key}`);
+          let url = ``;
+          if(chatStore.deepSeekStatus === 'LOCAL'){
+            url = `/bigmodel/api/dialog/detail/${key}`;
+          }else{
+            url = `/takai/api/dialog/detail/${key}`;
+          }
+          const res = await api.get(url);
           const list = res.data.map(((item: any) => {
             return {
               content: item.content,
@@ -409,11 +436,19 @@ export const SideBar = (props: { className?: string }) => {
           form.validateFields().then(async (values) => {
             setModalOpen(false);
             try {
-              await api.put('/bigmodel/api/dialog/update', {
-                id: values.dialogId,
-                dialogName: values.dialogName
-              });
-              await fetchChatList()
+              if(chatStore.deepSeekStatus === 'LOCAL'){
+                await api.put(`/bigmodel/api/dialog/update`, {
+                  id: values.dialogId,
+                  dialogName: values.dialogName
+                });
+                await fetchChatList();
+              }else{
+                await api.put(`/takai/api/dialog/update`, {
+                  id: values.dialogId,
+                  dialogName: values.dialogName
+                });
+                await fetchChatList(chatStore.deepSeekStatus);
+              }
               chatStore.updateCurrentSession((value) => {
                 value.topic = values.dialogName;
               });

+ 4 - 0
app/store/chat.ts

@@ -167,6 +167,7 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
 
 const DEFAULT_CHAT_STATE = {
   model: 'BigModel' as 'BigModel' | 'DeepSeek',
+  deepSeekStatus: 'ONLINE' as 'ONLINE' | 'LOCAL',
   sessions: [createEmptySession()],
   currentSessionIndex: 0,
   message: {
@@ -188,6 +189,9 @@ export const useChatStore = createPersistStore(
       setModel(model: 'BigModel' | 'DeepSeek') {
         set({ model: model });
       },
+      setDeepSeekStatus(status: 'ONLINE' | 'LOCAL') {
+        set({ deepSeekStatus: status });
+      },
       clearSessions() {
         set(() => ({
           sessions: [createEmptySession()],