浏览代码

智普问题修复

sunsheng 3 月之前
父节点
当前提交
6c9fc4480e
共有 7 个文件被更改,包括 113 次插入10 次删除
  1. 1 1
      .gitignore
  2. 27 0
      README.md
  3. 17 2
      app/client/platforms/bigModel.ts
  4. 2 2
      app/client/platforms/deepSeek.ts
  5. 64 4
      app/components/chat.tsx
  6. 1 1
      app/components/home.tsx
  7. 1 0
      app/store/chat.ts

+ 1 - 1
.gitignore

@@ -4,7 +4,7 @@
 /node_modules
 /.pnp
 .pnp.js
-
+local.md
 # testing
 /coverage
 

+ 27 - 0
README.md

@@ -122,3 +122,30 @@ sequenceDiagram
 1. **插件系统**: 支持功能模块动态扩展
 2. **配置中心**: 运行时配置热更新
 3. **多模型路由**: 根据请求自动路由到最优AI服务
+
+# 智普问答 可以访问的地址
+http://localhost:4000/#/knowledgeChat?showMenu=true&chatMode=LOCAL&appId=2924812721300312064
+http://localhost:4000/#/knowledgeChat?showMenu=false&chatMode=LOCAL&appId=2924812721300312064
+
+常改文件---components/chat.tsx--->对应的是智普问答
+常改文件---components/DeepSeekChat.tsx--->对应的是deepSeek问答
+
+本地调试需要改变文件
+1、app/client/platforms/deepSeek.ts
+    this.apiPath = this.baseURL + '/vllm/ai/chat';//线上地址
+    this.apiPath = this.baseURL + '/vllm/chat'; // 测试地址
+2、 destination: "http://xia0miduo.gicp.net:8401/:path*",----这一步可以改也可以不改
+        // destination: "http://xia0miduo.gicp.net:8401/:path*",
+        destination: "http://192.168.3.123:8091/:path*",
+3、app/components/home.tsx 
+    toUninLogin方法下增加 return 禁止跳转到首页
+    如下:
+    const toUninLogin = async (originUrl:string, fullUrl:string) => {
+    // return ----- 这里
+    //测试环境
+    //const loginUrl = 'https://esctest.sribs.com.cn/esc-sso/oauth2.0/authorize?client_id=e97f94cf93761f4d69e8&response_type=code';
+    //生产环境
+    const loginUrl = 'http://esc.sribs.com.cn:8080/esc-sso/oauth2.0/authorize?client_id=e97f94cf93761f4d69e8&response_type=code';
+    const externalLoginUrl = loginUrl + `&redirect_uri=${encodeURIComponent(originUrl)}&state=${encodeURIComponent(fullUrl)}`;
+    location.replace(externalLoginUrl);
+  }

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

@@ -152,7 +152,7 @@ export class BigModelApi implements LLMApi {
         },
         onmessage: async (msg) => {
           const info = JSON.parse(msg.data);
-          if (info.event === 'finish') {
+          if (info.event === 'finish') { // 完成
             const chatMode = useChatStore.getState().chatMode;
             if (chatMode === 'LOCAL') {// 切片
               useChatStore.getState().updateCurrentSession((se) => {
@@ -161,8 +161,23 @@ 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) => {
@@ -190,7 +205,7 @@ export class BigModelApi implements LLMApi {
           // 获取当前的数据
           const currentData = info.data;
           const formatStart = '```think';
-          const formatEnd = 'think```';
+          const formatEnd = 'think```'; 
 
           if (currentData?.startsWith(formatStart)) {
             remainText += currentData.replace(formatStart, '```think\n');

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

@@ -22,8 +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/chat'; // 测试地址 
+    this.apiPath = this.baseURL + '/vllm/ai/chat';//线上地址
+  // this.apiPath = this.baseURL + '/vllm/chat'; // 测试地址 
   }
 
   async chat(options: ChatOptions) {

+ 64 - 4
app/components/chat.tsx

@@ -678,10 +678,69 @@ 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>
@@ -721,7 +780,7 @@ export function ChatActions(props: {
               </div>
           }
         </div>
-      }
+      } */}
       {/* {couldStop && (
         <ChatAction
           onClick={stopAll}
@@ -2042,9 +2101,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,
@@ -2059,7 +2119,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 - 1
app/components/home.tsx

@@ -366,7 +366,7 @@ export function Home() {
   }
 
   const toUninLogin = async (originUrl:string, fullUrl:string) => {
-    return
+    // return
     //测试环境
     //const loginUrl = 'https://esctest.sribs.com.cn/esc-sso/oauth2.0/authorize?client_id=e97f94cf93761f4d69e8&response_type=code';
     //生产环境

+ 1 - 0
app/store/chat.ts

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