Parcourir la source

聊天记录增加文件

李富豪 il y a 7 mois
Parent
commit
8e9eba1919
5 fichiers modifiés avec 483 ajouts et 437 suppressions
  1. 1 0
      app/client/api.ts
  2. 42 8
      app/components/DeepSeekChat.tsx
  3. 14 5
      app/components/sidebar.tsx
  4. 2 0
      app/store/chat.ts
  5. 424 424
      yarn.lock

+ 1 - 0
app/client/api.ts

@@ -36,6 +36,7 @@ export interface RequestMessage {
   content: string | MultimodalContent[];
   document?: {
     id: string,
+    name: string,
     url: string,
   }
 }

+ 42 - 8
app/components/DeepSeekChat.tsx

@@ -84,7 +84,7 @@ import { getClientConfig } from "../config/client";
 import { useAllModels } from "../utils/hooks";
 import { nanoid } from "nanoid";
 import { message, Upload, UploadProps } from "antd";
-import { PaperClipOutlined, SendOutlined } from '@ant-design/icons';
+import { PaperClipOutlined, SendOutlined, FileOutlined, FilePdfOutlined, FileTextOutlined, FileWordOutlined } from '@ant-design/icons';
 
 export function createMessage(override: Partial<ChatMessage>): ChatMessage {
   return {
@@ -1315,6 +1315,37 @@ function _Chat() {
     accept: ['.pdf', '.txt', '.doc', '.docx'].join(','),
   };
 
+  interface FileIconProps {
+    fileName: string;
+  }
+
+  const FileIcon: React.FC<FileIconProps> = (props: FileIconProps) => {
+    const style = {
+      fontSize: '30px',
+      color: '#3875f6',
+    }
+
+    let icon = <FileOutlined style={style} />
+    if (props.fileName) {
+      const suffix = props.fileName.split('.').pop() || '';
+      switch (suffix) {
+        case 'pdf':
+          icon = <FilePdfOutlined style={style} />
+          break;
+        case 'txt':
+          icon = <FileTextOutlined style={style} />
+          break;
+        case 'doc':
+        case 'docx':
+          icon = <FileWordOutlined style={style} />
+          break;
+        default:
+          break;
+      }
+    }
+    return icon;
+  }
+
   return (
     <div className={styles.chat} key={session.id}>
       {
@@ -1362,7 +1393,7 @@ function _Chat() {
                     isUser ? styles["chat-message-user"] : styles["chat-message"]
                   }
                 >
-                  <div className={styles["chat-message-container"]} style={{ display: 'flex', flexDirection: 'row' }}>
+                  <div className={styles["chat-message-container"]} style={{ display: 'flex', flexDirection: isUser ? 'column' : 'row' }}>
                     <div className={styles["chat-message-header"]}>
                       <div className={styles["chat-message-avatar"]}>
                         {isUser ? null : (
@@ -1370,12 +1401,15 @@ function _Chat() {
                         )}
                       </div>
                     </div>
-                    {/* {
-                      isUser && message.document && message.document.url &&
-                      <div>
-                        {message.document.url}
-                      </div>
-                    } */}
+                    {
+                      isUser && message.document && message.document.id &&
+                      <a style={{ padding: '10px', background: '#f7f7f7', borderRadius: '10px', textDecoration: 'none', color: '#24292f', display: 'flex', alignItems: 'center' }} href={message.document.url} target="_blank">
+                        <FileIcon fileName={message.document.name} />
+                        <div style={{ marginLeft: 10 }}>
+                          {message.document.name}
+                        </div>
+                      </a>
+                    }
                     {/* {showTyping && (
                       <div className={styles["chat-message-status"]}>
                         正在输入…

+ 14 - 5
app/components/sidebar.tsx

@@ -218,7 +218,6 @@ export const SideBar = (props: { className?: string }) => {
   // 获取聊天列表
   const fetchChatList = async (chatMode?: 'ONLINE' | 'LOCAL') => {
     try {
-      console.log('fetchChatList', chatMode);
       let url = '';
       if (getType() === 'bigModel') {
         const appId = globalStore.selectedAppId;
@@ -333,8 +332,10 @@ export const SideBar = (props: { className?: string }) => {
   }
 
   useEffect(() => {
-    if (globalStore.selectedAppId) {
-      fetchChatList(chatStore.chatMode);
+    if (getType() === 'bigModel') {
+      if (globalStore.selectedAppId) {
+        fetchChatList(chatStore.chatMode);
+      }
     }
   }, [globalStore.selectedAppId]);
 
@@ -419,12 +420,20 @@ export const SideBar = (props: { className?: string }) => {
             url = `/bigmodel/api/dialog/detail/${key}`;
           }
           const res = await api.get(url);
+
+          // const document = {
+          //   id: "6e90c1c5-20ed-11f0-bcfc-22114d043191",
+          //   name: "ISHIGURO WEB EDI.pdf",
+          //   url: "http://xia0miduo.gicp.net:9000/papbtest///chatFiles/6e90c1c5-20ed-11f0-bcfc-22114d043191_ISHIGURO WEB EDI.pdf"
+          // }
+
           const list = res.data.map(((item: any) => {
             return {
-              content: item.content,
-              date: item.create_time,
               id: item.did,
               role: item.type,
+              date: item.create_time,
+              content: item.content,
+              document: item.document ? item.document : undefined,
             }
           }))
           const session = {

+ 2 - 0
app/store/chat.ts

@@ -360,11 +360,13 @@ export const useChatStore = createPersistStore(
 
         const document = {
           id: '',
+          name: '',
           url: '',
         }
 
         if (fileList.length) {
           document.id = fileList[0].documentId;
+          document.name = fileList[0].name;
           document.url = fileList[0].url;
         }
 

Fichier diff supprimé car celui-ci est trop grand
+ 424 - 424
yarn.lock


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff