Просмотр исходного кода

feat: 支持知识库文件分析功能

新增知识库文件ID处理逻辑,在AI聊天请求中传递文件ID参数,添加文件分析提示词,实现读取并结合知识库内容回答问题的能力
lsc 6 дней назад
Родитель
Сommit
b447016c00

+ 32 - 14
src/components/CollapsibleToolbar/componets/aiChat.vue

@@ -223,6 +223,8 @@ import message from '@/utils/message'
 import AiWeb from './aiWeb.vue'
 import katex from 'katex'
 import 'katex/dist/katex.min.css'
+import fileidArray from './fileid.js'
+
 
 interface ChatMessage {
   uid?: string
@@ -681,16 +683,20 @@ const sendAction = async (action: string) => {
   let prompt = ''
   let agentid = agentid2.value
   const imgUrls = []
-
+  const fileid = []
+  if (lang.lang === 'hk') {
+    fileid.push(...fileidArray)
+  }
 
   if (gType.value === 'trigger_tool_recommend') {
     agentid = agentid3.value
     imgUrls.push(...allImgContents)
+
     prompt = `
   #课程标题(course_title): ${props.courseTitle || ''}
   #当前页面内容(all_pages_content): ${allTextContents.length > 0 ? allTextContents.join('\n') : '无文本内容'}
-  ${imgUrls.length ?  '识别图片内容' : ''}
-  #query: ${action}
+  ${imgUrls.length ? '识别图片内容' : ''}
+  #query: ${action} ${fileid.length > 0 ? `可以分析并读取知识库有用的内容结合一下再回答` : ''}
   `
   }
   else if (gType.value === 'trigger_batch_tool') {
@@ -699,8 +705,8 @@ const sendAction = async (action: string) => {
     prompt = `
   #课程标题(course_title): ${props.courseTitle || ''}
   #当前页面内容(all_pages_content): ${allTextContents.length > 0 ? allTextContents.join('\n') : '无文本内容'}
-  ${imgUrls.length ?  '识别图片内容' : ''}
-  #query: ${action}
+  ${imgUrls.length ? '识别图片内容' : ''}
+  #query: ${action} ${fileid.length > 0 ? `可以分析并读取知识库有用的内容结合一下再回答` : ''}
   `
   }
   else {
@@ -708,8 +714,8 @@ const sendAction = async (action: string) => {
     prompt = `
   #课程标题(course_title): ${props.courseTitle || ''}
   #当前页面内容(current_page_content): ${textContents.length > 0 ? textContents.join('\n') : '无文本内容'}
-  ${imgUrls.length ?  '识别图片内容' : ''}
-  #query: ${action}
+  ${imgUrls.length ? '识别图片内容' : ''}
+  #query: ${action} ${fileid.length > 0 ? `可以分析并读取知识库有用的内容结合一下再回答` : ''}
   `
   }
 
@@ -721,7 +727,7 @@ const sendAction = async (action: string) => {
       console.log('loadingDots.value', loadingDots.value)
       console.log('messages.value.at(-1).aiContent', messages.value.at(-1).aiContent)
     }, 500)
-    const result = chat_no_stream(prompt, agentid, props.userid || '', lang.lang, undefined, imgUrls)
+    const result = chat_no_stream(prompt, agentid, props.userid || '', lang.lang, undefined, imgUrls, fileid)
     streamController.value = result
     console.log(result)
     const content = await result.promise
@@ -753,7 +759,7 @@ const sendAction = async (action: string) => {
   }
   else if (gType.value === 'generate_interactive_web') {
     agentid = agentid5.value
-    const result = chat_no_stream(prompt, agentid, props.userid || '', lang.lang, undefined, imgUrls)
+    const result = chat_no_stream(prompt, agentid, props.userid || '', lang.lang, undefined, imgUrls, fileid)
     streamController.value = result
     console.log(result)
     const content = await result.promise
@@ -783,7 +789,14 @@ const sendAction = async (action: string) => {
     // })
     return
   }
-  
+  if (messages.value.at(-1).sourceFiles?.map(file => file.id).filter(Boolean).length) {
+    try {
+      fileid.push(...messages.value.at(-1).sourceFiles?.map(file => file.id).filter(Boolean))
+    }
+    catch (error) {
+      console.log('error', error)
+    }
+  }
   chat_stream(prompt, agentid, props.userid || '', lang.lang, (event) => {
     if (event.type === 'message') {
       messages.value.at(-1).aiContent = md.render(katexZ(event.data))
@@ -797,7 +810,7 @@ const sendAction = async (action: string) => {
       chatLoading.value = false
       prevChatResult()
     }
-  }, session_name.value, messages.value.at(-1).sourceFiles?.map(file => file.id).filter(Boolean), undefined, imgUrls).then(controller => {
+  }, session_name.value, fileid, undefined, imgUrls).then(controller => {
     streamController.value = controller
   }).catch(err => {
     chatLoading.value = false
@@ -1112,6 +1125,11 @@ const createTool = async (array: any[], tool: any, index: number, slide: any) =>
     type = 84
   }
   
+  const fileid = []
+  if (lang.lang === 'hk') {
+    fileid.push(...fileidArray)
+  }
+
   const textContents = slide?.elements
     .filter((element: any) => element.type === 'text' || (element.type === 'shape' && element.text && element.text.content))
     .map((textElement: any) => {
@@ -1135,10 +1153,10 @@ const createTool = async (array: any[], tool: any, index: number, slide: any) =>
   const prompt = `
       #课程标题(course_title): ${props.courseTitle || ''}
       #当前页面内容(current_page_content): ${textContents.length > 0 ? textContents.join('\n') : '无文本内容'}
-      ${imgContents.length ?  '识别图片内容' : ''}
-      #query: ${action}
+      ${imgContents.length ? '识别图片内容' : ''}
+      #query: ${action} ${fileid.length > 0 ? `可以分析并读取知识库有用的内容结合一下再回答` : ''}
       `
-  const result = chat_no_stream(prompt, agentid2.value, props.userid || '', lang.lang, undefined, imgUrls)
+  const result = chat_no_stream(prompt, agentid2.value, props.userid || '', lang.lang, undefined, imgContents, fileid)
   console.log(result)
   const content = await result.promise
   console.log('👶 创建工具:', content)

+ 44 - 0
src/components/CollapsibleToolbar/componets/fileid.js

@@ -0,0 +1,44 @@
+const fileidArray = [
+  'ff332c18-8e17-4152-9f4a-6097ab8ba503',
+  '3b683b2b-68b5-447f-97c3-4e860a7c742b',
+  'ff97d7e1-616f-4fe8-8f28-964aeab02461',
+  '7d638083-243c-4955-9804-98146c488a2c',
+  '665e6ef1-7f2c-4e5e-9911-78d95c2538cf',
+  '79616b63-f53f-4429-9e73-910c973e4d5b',
+  '457e95af-71ab-490e-82ee-3fcadefc26c2',
+  'bc864a50-f923-4a76-b308-d2321908e2a2',
+  '19975ac5-ead3-4e9d-8ed2-762947034599',
+  '0c374a99-b85c-4cf8-9e3c-5b2ff3dd940e',
+  '1c778456-13d5-45b5-9219-d40b3cfb67a4',
+  '6a20c057-872c-4dfc-bc21-c2591b1c92f8',
+  '0e465997-2fe5-4c13-9f55-9c79b575be5e',
+  '9fe03dc2-7a08-4051-8697-04db98c337f4',
+  '130fbaff-b7c6-4a71-8182-c01fe325b71a',
+  '7ff9f72a-66c5-418b-8540-d377179bd62b',
+  '690c7f32-aabd-4db4-ac1b-24d45dcb12c1',
+  '182dc584-39cb-41ae-bd23-03aafcf9558d',
+  'c2c270a8-03a2-4fc8-829d-5152db15b227',
+  'a36a1742-d27f-4a33-b538-8049ca0a5ee6',
+  '5c957c4f-5acb-4efb-87b0-21dbd04505ed',
+  '49fee839-2934-4833-9b9e-34a18c37fdd4',
+  '79608139-b78f-4459-8cf8-bb7c5083d1d6',
+  '6cfa1561-8c87-448c-971c-eab90c94209a',
+  '42b49057-7e65-4b3d-be38-c063f8a2101a',
+  'aae8e21a-2699-4ce5-a30f-c867f6af2582',
+  '13fb4c32-1989-49ed-84af-f6dc3db00e3e',
+  '45f831de-176e-4cb5-8d9f-6100fd799848',
+  'd009de6b-b1e9-46a2-8daf-b243bebc85ec',
+  'da979f7f-34d3-4a27-8245-c6bf2233529c',
+  '12b32418-cb29-4c0f-a15e-f9a4790d17ba',
+  '58f21a64-0574-4eea-83dc-d673c480ede0',
+  'b0d5a127-024d-4654-86cb-fc695be4b7f9',
+  '15d60f02-6034-494e-9f1a-fdf8b165e145',
+  'dd21167e-824d-4fd1-a0a5-f5c663a0ac73',
+  '37987beb-4165-49ab-bfd8-2762ebdce757',
+  '01917ed8-0359-4751-a767-1a24d13b7d32',
+  '513eb6ee-3955-44be-b453-a2076ddf17fa',
+  '8f035f7e-b71b-4524-9078-f1f5a4a93c28',
+  'ce739e17-8744-48ac-83c1-0927eb381912'
+]
+
+export default fileidArray

+ 4 - 3
src/tools/aiChat.ts

@@ -38,7 +38,7 @@ const DEFAULT_PARAMS: Omit<ChatParams, 'message' | 'uid' | 'stream'> = {
   tts_language: 'zh-CN'
 }
 
-export const chat_no_stream = (msg: string, agentId: string, userId: string, language: string, session_name?: string, imgUrls: string[] = []): { promise: Promise<string>; abort: () => void } => {
+export const chat_no_stream = (msg: string, agentId: string, userId: string, language: string, session_name?: string, imgUrls: string[] = [], fileid: string[] = []): { promise: Promise<string>; abort: () => void } => {
   const source = cancelToken.source()
   
   const promise = (async () => {
@@ -58,7 +58,8 @@ export const chat_no_stream = (msg: string, agentId: string, userId: string, lan
       userId: userId,
       tts_language: getTtsLanguage(language),
       session_name: session_name || uuidv4(),
-      image_urls: imgUrls
+      image_urls: imgUrls,
+      file_ids: fileid || []
     }
 
     try {
@@ -107,7 +108,7 @@ export const chat_stream = async (
   session_name?: string,
   file_ids?: Array<string>,
   model?: string,
-  imgUrls: string[] = []
+  imgUrls?: Array<string>,
 ): Promise<{ abort: () => void }> => {
   const agentData = await getAgentModel(agentId)
   const params: ChatParams = {

+ 0 - 1
src/views/lang/cn.json

@@ -802,7 +802,6 @@
   "ssManualCreate": "手动创建",
   "ssBackToRecommend": "返回推荐",
   "ssTopicDiscussion": "话题讨论",
-  "ssArticleReading": "文章朗读",
   "ssArticleClassSummary": "AI 班级总结",
   "ssArticleRefresh": "刷新",
   "ssArticleGenerate": "生成",

+ 0 - 1
src/views/lang/en.json

@@ -803,7 +803,6 @@
   "ssManualCreate": "Manual Create",
   "ssBackToRecommend": "Back to Recommend",
   "ssTopicDiscussion": "Topic Discussion",
-  "ssArticleReading": "Article Reading",
   "ssArticleClassSummary": "AI class summary",
   "ssArticleRefresh": "Refresh",
   "ssArticleGenerate": "Generate",

+ 0 - 1
src/views/lang/hk.json

@@ -803,7 +803,6 @@
   "ssManualCreate": "手動創建",
   "ssBackToRecommend": "返回推薦",
   "ssTopicDiscussion": "話題討論",
-  "ssArticleReading": "文章朗讀",
   "ssArticleClassSummary": "AI 班級總結",
   "ssArticleRefresh": "重新整理",
   "ssArticleGenerate": "產生",