Browse Source

feat(aiChat): 新增两个快捷功能并完善生成逻辑

1. 新增ssAiChatQuickAction8/9多语言文案和快捷操作入口
2. 完善generate函数,新增生成图片和文件上传功能
3. 修复generate_photo类型名称不一致问题
4. 新增图片生成代理ID和相关调用逻辑
lsc 4 hours ago
parent
commit
aa056d9893

+ 61 - 4
src/components/CollapsibleToolbar/componets/aiChat.vue

@@ -294,6 +294,8 @@ const quickActions = [
   lang.ssAiChatQuickAction6,
   lang.ssAiChatQuickAction7,
   lang.ssAiChatQuickAction4,
+  lang.ssAiChatQuickAction8,
+  lang.ssAiChatQuickAction9,
 ]
 
 // 监听输入变化,当输入"/"时显示快捷操作
@@ -473,7 +475,7 @@ const sendAction = async (action: string) => {
       gType.value = 'chat'
     }
 
-    // generate_qa // generate_choice_question // generate_photo // generate_poll
+    // generate_qa // generate_choice_question // generate_take_photo // generate_poll
     if (gType.value !== 'chat' && gType.value !== 'generate_interactive_web' && gType.value !== 'trigger_batch_tool') {
       messages.value.at(-1).jsonData = {
         gType: gType.value,
@@ -769,7 +771,7 @@ const sendAction = async (action: string) => {
 import useCreateElement from '@/hooks/useCreateElement'
 import useSlideHandler from '@/hooks/useSlideHandler'
 const { createSlide } = useSlideHandler()
-const { createFrameElement } = useCreateElement()
+const { createFrameElement, createImageElement } = useCreateElement()
 
 
 const katexZ = (str) => {
@@ -826,7 +828,7 @@ const setUrl = () => {
   return url
 }
 
-const generate = (message: ChatMessage) => {
+const generate = async (message: ChatMessage) => {
   if (message.gLoading || message.jsonData?.isGenerate) {
     return
   }
@@ -894,7 +896,7 @@ const generate = (message: ChatMessage) => {
       })
     })
   }
-  else if (message.jsonData?.gType === 'generate_photo') {
+  else if (message.jsonData?.gType === 'generate_take_photo') {
     console.log(message.jsonData?.gType)
     const prompt = [
       {
@@ -915,6 +917,52 @@ const generate = (message: ChatMessage) => {
       })
     })
   }
+  else if (message.jsonData?.gType === 'generate_file') {
+    console.log(message.jsonData?.gType)
+    const prompt = [
+      {
+        role: 'user',
+        content: `这是用户输入的内容:“${message.aiContent}”,根据用户输入的内容,生成文件上传的json。输出一个json格式的回复,格式如下:{"answerQ":"问题","answer":"","fileList":[]}。`, // ,"imageList":[],"evaluationCriteria":"评价标准" 输出语言为${lang.lang === 'en' ? '英文' : lang.lang === 'hk' ? '繁体中文' : '简体中文'}
+      },
+    ]
+    chat_no_stream2(prompt, { type: 'json_object' }).then((res: any) => {
+      console.log('文件上传', JSON.parse(res))
+      gType.value = 'chat'
+      setPageId(84, res).then(res => {
+        const baseUrl = setUrl()
+        const url = `${baseUrl}/pbl-teacher-table/dist/workPage.html#/setWorkPage?id=${res}&type=${84}&userid=${props.userid || ''}`
+        createSlide()
+        createFrameElement(url, 84)
+        message.gLoading = false
+        message.jsonData.isGenerate = true
+      })
+    })
+  }
+  else if (message.jsonData?.gType === 'generate_image') {
+    console.log(message.jsonData?.gType)
+    const prompt = `${message.aiContent} 根据用户的内容,生成图片`
+    const result = chat_no_stream(prompt, agentidPhoto.value, props.userid || '', lang.lang)
+    console.log('图片', result)
+    const content = await result.promise
+    console.log('event.data', content)
+    // 从content中提取图片链接
+    const urlMatch = content.match(/\[.*?\]\((https?:\/\/.*?)\)/)
+    const imageUrl = urlMatch ? urlMatch[1] : ''
+
+    // 判断当前页面是否是工具页(含frame元素)
+    const isToolPage = (currentSlide.value?.elements || []).some((el: any) => el.type === 'frame')
+    // 如果当前页不是工具页则直接加图片,是工具页则新建页面再加图片
+    if (!isToolPage) {
+      createImageElement(imageUrl)
+    }
+    else {
+      createSlide()
+      createImageElement(imageUrl)
+    }
+
+    message.gLoading = false
+    message.jsonData.isGenerate = true
+  }
   else if (message.jsonData?.gType === 'trigger_batch_tool') {
     console.log(message.jsonData?.gType)
     const prompt = [
@@ -1009,6 +1057,10 @@ const createTool = async (array: any[], tool: any, index: number, slide: any) =>
     action = lang.ssAiChatQuickAction7
     type = 79
   }
+  else if (tool.tool_id === 'file') {
+    action = lang.ssAiChatQuickAction9
+    type = 84
+  }
   
   const textContents = slide?.elements
     .filter((element: any) => element.type === 'text' || (element.type === 'shape' && element.text && element.text.content))
@@ -1048,6 +1100,9 @@ const createTool = async (array: any[], tool: any, index: number, slide: any) =>
   else if (tool.tool_id === 'photo') {
     jsonFormat = `{"answerQ":"问题","answer":"","fileList":[]}`
   }
+  else if (tool.tool_id === 'file') {
+    jsonFormat = `{"answerQ":"问题","answer":"","fileList":[]}`
+  }
   
   const res = await chat_no_stream2([{
     role: 'user',
@@ -1127,6 +1182,7 @@ const agentid2 = ref('f86aa63c-b7b7-4d03-9b37-b59f116d36f3')// 生成内容
 const agentid3 = ref('caaa43ab-41a5-466a-94bc-74e0c9265068')// 互动工具推荐
 const agentid4 = ref('b41bc650-9861-468c-a624-b52269dfff22')// 批量生成工具
 const agentid5 = ref('939d28ef-3a1b-442b-871f-3894eb67ac9c')// 互动网页
+const agentidPhoto = ref('2adb7966-86a3-42b4-a9fb-7439635fb28b')// 互动图片
 
 const isQuickActions = ref<string[]>([])
 const toggleQuickActions = (section: string) => {
@@ -1241,6 +1297,7 @@ onMounted(() => {
   getAgentModel(agentid3.value)
   getAgentModel(agentid4.value)
   getAgentModel(agentid5.value)
+  getAgentModel(agentidPhoto.value)
 
   for (let i = 0; i < slidesStore.slides.length; i++) {
     const slide = slidesStore.slides[i]

+ 1 - 0
src/views/Student/index.vue

@@ -3179,6 +3179,7 @@ const setCan = (Array: any[]) => {
 }
 
 const forceLogout = () => {
+  // cleanupWebSocketConnection()
   sendMessage({ type: 'logout' })
 }
 

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

@@ -746,6 +746,8 @@
   "ssAiChatQuickAction2": "为当前页面内容生成1道问答题",
   "ssAiChatQuickAction6": "为当前页面生成投票",
   "ssAiChatQuickAction7": "为当前页面生成拍照题",
+  "ssAiChatQuickAction8": "当前页面生成配图",
+  "ssAiChatQuickAction9": "为当前页面内容生成文件上传",
   "ssAiChatParsing": "解析中...",
   "ssAiChatWaitUpload": "请等待文件上传完成后再发送消息",
   "ssAiChatFileSizeLimit": "文件大小不能超过10MB",

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

@@ -747,6 +747,8 @@
   "ssAiChatQuickAction2": "Generate 1 essay question for the current page content",
   "ssAiChatQuickAction6": "Generate a poll for the current page",
   "ssAiChatQuickAction7": "Generate a photo question for the current page",
+  "ssAiChatQuickAction8": "Generate a photo for the current page",
+  "ssAiChatQuickAction9": "Generate a file upload for the current page content",
   "ssAiChatParsing": "Parsing...",
   "ssAiChatWaitUpload": "Please wait for the file upload to complete before sending a message",
   "ssAiChatFileSizeLimit": "File size cannot exceed 10MB",

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

@@ -747,6 +747,8 @@
   "ssAiChatQuickAction2": "為當前頁面內容生成1道問答題",
   "ssAiChatQuickAction6": "為當前頁面生成投票",
   "ssAiChatQuickAction7": "為當前頁面生成拍照題",
+  "ssAiChatQuickAction8": "當前頁面生成配圖",
+  "ssAiChatQuickAction9": "為當前頁面內容生成文件上傳",
   "ssAiChatParsing": "解析中...",
   "ssAiChatWaitUpload": "請等待文件上傳完成後再發送消息",
   "ssAiChatFileSizeLimit": "文件大小不能超過10MB",