Bladeren bron

智普问答新增你还可以问其它问题收缩

sunsheng 3 maanden geleden
bovenliggende
commit
0cb685d233
7 gewijzigde bestanden met toevoegingen van 104 en 8 verwijderingen
  1. 9 0
      README.md
  2. 16 0
      app/client/platforms/bigModel.ts
  3. 3 2
      app/client/platforms/deepSeek.ts
  4. 6 0
      app/command.ts
  5. 66 4
      app/components/chat.tsx
  6. 1 0
      app/store/chat.ts
  7. 3 2
      next.config.mjs

+ 9 - 0
README.md

@@ -122,3 +122,12 @@ sequenceDiagram
 1. **插件系统**: 支持功能模块动态扩展
 2. **配置中心**: 运行时配置热更新
 3. **多模型路由**: 根据请求自动路由到最优AI服务
+
+
+
+
+# 智普问答 可以访问的地址
+http://localhost:4000/#/knowledgeChat?showMenu=true&chatMode=LOCAL&appId=2924812721300312064
+
+常改文件---components/chat.tsx--->对应的是智普问答
+常改文件---components/DeepSeekChat.tsx--->对应的是deepSeek问答

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

@@ -158,8 +158,24 @@ export class BigModelApi implements LLMApi {
               sliceInfoPromise = (async () => {
                 try {
                   const res: any = await api.get(`deepseek/api/slice/search/${info.id}`);
+                  let allChunkNum = 0;
+                  delete res.data.code;
+                  const values1 = Object.keys(res.data).reduce((acc, knowledge_id) => {
+                  const docs = res.data[knowledge_id];
+                  const transformedDocs = docs.map((doc: any) =>{
+                    allChunkNum += doc.chunk_nums;
+                      return{
+                        knowledge_id,
+                        ...doc
+                      }
+                    });
+                    return acc.concat(transformedDocs);
+                  }, []);
+
                   const sliceInfo = {
+                    allChunkNum:allChunkNum,
                     ...res.data,
+                    doc: values1
                   };
                   delete sliceInfo.code;
                   useChatStore.getState().updateCurrentSession((session) => {

+ 3 - 2
app/client/platforms/deepSeek.ts

@@ -22,7 +22,8 @@ export class DeepSeekApi implements LLMApi {
   constructor() {
     // this.baseURL = 'http://192.168.3.209:18078';
     this.baseURL = '/deepseek-api';
-    this.apiPath = this.baseURL + '/vllm/ai/chat';
+    this.apiPath = this.baseURL + '/vllm/ai/chat';//线上地址
+    // this.apiPath = this.baseURL + '/vllm/chat'; // 测试地址 
   }
 
   async chat(options: ChatOptions) {
@@ -98,7 +99,7 @@ export class DeepSeekApi implements LLMApi {
         if (finished || controller.signal.aborted) {
           responseText += remainText;
           if (responseText?.length === 0) {
-            options.onError?.(new Error("请求已中止,请检查网络环境。"));
+            options.onError?.(new Error("请求已中止,请检查网络环境。-3-4"));
           }
           return;
         }

+ 6 - 0
app/command.ts

@@ -46,10 +46,16 @@ export const ChatCommandPrefix = /^[::]/;
 
 export function useChatCommand(commands: ChatCommands = {}) {
   function extract(userInput: string) {
+    // 匹配用户输入与聊天命令前缀
     const match = userInput.match(ChatCommandPrefix);
+
+    // 如果匹配成功
     if (match) {
+      // 返回用户输入去掉前缀的部分,并断言其类型为 ChatCommands 的键
       return userInput.slice(1) as keyof ChatCommands;
     }
+
+    // 如果匹配失败,直接返回用户输入,并断言其类型为 ChatCommands 的键
     return userInput as keyof ChatCommands;
   }
 

+ 66 - 4
app/components/chat.tsx

@@ -655,15 +655,74 @@ export function ChatActions(props: {
       setGuessList([]);
     }
   }, [props.isClickStop])
+  const [activeKey, setActiveKey]= useState('0'); // 控制手风琴是否展示
 
   return (
     <div className={styles["chat-input-actions"]}>
       {
+        props.sendStatus &&
+        <Collapse
+          accordion={true}
+          activeKey={activeKey}
+          onChange={(key)=>{setActiveKey(key[0])}}
+          bordered={false}
+          style={{ width: '100%',backgroundColor:'#fff' }}
+          expandIconPosition="end"
+          items={[
+            {
+              key: '1',
+              label:<span style={{ color: '#8096ca' }}>你还可以尝试提问:</span>,
+              children: <div style={{ color: '#8096ca', fontSize: 13, overflowX: 'auto' }}>
+                  {/* <div>
+                    你还可以尝试提问:
+                  </div> */}
+                  
+                  {
+                    guessList.length === 0 ?
+                      <Space style={{ margin: '10px 0' }}>
+                        <Skeleton.Button size="small" active={true} />
+                        <Skeleton.Button size="small" active={true} />
+                        <Skeleton.Button size="small" active={true} />
+                      </Space>
+                      :
+                      <div style={{ display: 'flex', margin: '10px 0', overflowX: 'auto' }}>
+                        {
+                          guessList.map((item, index) => {
+                            return (
+                              <div
+                                style={{
+                                  padding: '5px 10px',
+                                  background: '#f2f4f8',
+                                  borderRadius: 5,
+                                  margin: '0 10px 10px 0',
+                                  cursor: 'pointer',
+                                }}
+                                onClick={() => {
+                                  props.setUserInput(item);
+                                  props.doSubmit(item)
+                                  setActiveKey('')
+                                }}
+                                key={index}
+                              >
+                                {item}
+                              </div>
+                            )
+                          })
+                        }
+                      </div>
+                  }
+              </div>
+            }
+          ]}
+        />
+      }
+      {/* {
         props.sendStatus &&
         <div style={{ color: '#8096ca', fontSize: 13, overflowX: 'auto' }}>
           <div>
             你还可以尝试提问:
           </div>
+          
           {
             guessList.length === 0 ?
               <Space style={{ margin: '10px 0' }}>
@@ -698,7 +757,7 @@ export function ChatActions(props: {
               </div>
           }
         </div>
-      }
+      } */}
       {/* {couldStop && (
         <ChatAction
           onClick={stopAll}
@@ -1162,6 +1221,7 @@ function _Chat() {
 
   const doSubmit = (userInput: string) => {
     if (userInput.trim() === "") return;
+    
     const matchCommand = chatCommands.match(userInput);
     if (matchCommand.matched) {
       setUserInput("");
@@ -1170,6 +1230,7 @@ function _Chat() {
       return;
     }
     setIsLoading(true);
+    // debugger
     chatStore.onUserInput([], userInput, attachImages).then(() => setIsLoading(false));
     setAttachImages([]);
     localStorage.setItem(LAST_INPUT_KEY, userInput);
@@ -2019,9 +2080,10 @@ function _Chat() {
                               items={[
                                 {
                                   key: '1',
-                                  label: `查询到“${message.sliceInfo.doc.length}条”相关切片`,
+                                  // label: `查询到“${message.sliceInfo?.doc?.length}条”相关切片`,
+                                  label: `查询到${message.sliceInfo?.doc?.length}个问答共${message.sliceInfo?.allChunkNum}条切片`,
                                   children: <div>
-                                    {message.sliceInfo.doc.map((item, index) => {
+                                    {message.sliceInfo?.doc?.map((item, index) => {
                                       return <div
                                         style={{
                                           padding: 10,
@@ -2036,7 +2098,7 @@ function _Chat() {
                                         key={item.doc_id}
                                         onClick={() => {
                                           setDrawerData({
-                                            knowledge_id: message.sliceInfo!.knowledge_id,
+                                            knowledge_id: item!.knowledge_id,
                                             doc_name: item.doc_name,
                                             chunk_info: {
                                               doc_id: item.doc_id,

+ 1 - 0
app/store/chat.ts

@@ -42,6 +42,7 @@ export type ChatMessage = RequestMessage & {
   sliceInfo?: {
     knowledge_id: string,
     doc: any[],
+    allChunkNum?: number,
   },
   networkInfo?: {
     list: any[],

+ 3 - 2
next.config.mjs

@@ -92,7 +92,8 @@ if (mode !== "export") {
       },
       {
         source: "/bigmodel-api/:path*",
-        destination: "http://xia0miduo.gicp.net:8401/:path*",
+        // destination: "http://xia0miduo.gicp.net:8401/:path*",
+        destination: "http://192.168.3.123:8091/:path*",
       },
       {
         source: "/deepseek-api/:path*",
@@ -106,4 +107,4 @@ if (mode !== "export") {
   };
 }
 
-export default nextConfig;
+export default nextConfig;