|
@@ -6,8 +6,7 @@ import moment from 'moment'
|
|
|
import { cloneDeep } from 'lodash'
|
|
|
import {
|
|
|
getFormKey,
|
|
|
- buildObjPrompt,
|
|
|
- getFileSummaryPrompt,
|
|
|
+ hepl,
|
|
|
formatMessage,
|
|
|
sendMessage
|
|
|
} from '../utils/ai-service.js'
|
|
@@ -28,30 +27,6 @@ export function useMsg(scrollbar?: any) {
|
|
|
// 获取父组件提供的 Hook 实例
|
|
|
const { useStore } = inject('indexedDBHook') as any
|
|
|
|
|
|
- const getFileSummary = async (file: any) => {
|
|
|
- const obj = reactive({
|
|
|
- id: moment(),
|
|
|
- username: '用户1',
|
|
|
- rawContent: '',
|
|
|
- content: '解析文件中',
|
|
|
- timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- isSelf: false,
|
|
|
- avatar: avator,
|
|
|
- addToHistory: !taklToHtml.value
|
|
|
- })
|
|
|
- try {
|
|
|
- sendLoading.value = true
|
|
|
- messages.value.push(obj)
|
|
|
- nextTick(() => scrollbar.value?.setScrollTop(99999))
|
|
|
- const res = await getFileValue(file)
|
|
|
- console.log(res.data, file)
|
|
|
- await streamRes()
|
|
|
- } catch (error) {
|
|
|
- obj.content = '解析出错'
|
|
|
- } finally {
|
|
|
- sendLoading.value = false
|
|
|
- }
|
|
|
- }
|
|
|
const getFormKeyAndValue = async (file: any, form?: any) => {
|
|
|
// const obj = reactive({
|
|
|
// id: moment(),
|
|
@@ -113,7 +88,6 @@ export function useMsg(scrollbar?: any) {
|
|
|
}
|
|
|
if (status === 'select') {
|
|
|
obj.content = '检测到左侧页面中有多个表单,请选择要填写的表单。'
|
|
|
-
|
|
|
function handle(message, sender, sendResponse) {
|
|
|
if (message.type === 'TO_SIDE_PANEL_FORM_INFO') {
|
|
|
console.log('收到一次性消息:', message.data)
|
|
@@ -152,20 +126,28 @@ export function useMsg(scrollbar?: any) {
|
|
|
const res = await awaitFindForm(obj)
|
|
|
return res
|
|
|
}
|
|
|
- const res = await fetchDataAndProcess(msg, obj)
|
|
|
- sendLoading.value = false
|
|
|
- if (res.status === 'ok') {
|
|
|
- await new Promise((res: any) =>
|
|
|
- setTimeout(() => {
|
|
|
- res()
|
|
|
- }, 2000)
|
|
|
- )
|
|
|
- const res = await awaitFindForm(obj)
|
|
|
- return res
|
|
|
- }
|
|
|
+ try {
|
|
|
+ const res = await fetchDataAndProcess(msg, obj)
|
|
|
+ sendLoading.value = false
|
|
|
+ if (res.status === 'ok') {
|
|
|
+ await new Promise((res: any) =>
|
|
|
+ setTimeout(() => {
|
|
|
+ res()
|
|
|
+ }, 2000)
|
|
|
+ )
|
|
|
+ const res = await awaitFindForm(obj)
|
|
|
+ console.log(res,34444);
|
|
|
+
|
|
|
+ return res
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ obj.content = '流程链执行出错'
|
|
|
+ return {status: 'error'}
|
|
|
+ } finally {
|
|
|
+ sendLoading.value = false
|
|
|
+ }
|
|
|
}
|
|
|
let str = ''
|
|
|
-
|
|
|
async function fetchDataAndProcess(input: any, obj: any) {
|
|
|
str = input
|
|
|
console.log(str)
|
|
@@ -214,6 +196,8 @@ export function useMsg(scrollbar?: any) {
|
|
|
if (status === 'error') {
|
|
|
obj.content = data
|
|
|
resolve({ data, status })
|
|
|
+ console.log(222);
|
|
|
+
|
|
|
}
|
|
|
if (res.data.next === '是') {
|
|
|
const arr = str.split(',')
|
|
@@ -223,23 +207,6 @@ export function useMsg(scrollbar?: any) {
|
|
|
const res = await fetchDataAndProcess(str, obj)
|
|
|
resolve(res)
|
|
|
} else resolve({ status: 'ok' })
|
|
|
- // else {
|
|
|
- // await new Promise((resolve, reject) => {
|
|
|
- // setTimeout(() => {
|
|
|
- // resolve(1)
|
|
|
- // }, 2000)
|
|
|
- // })
|
|
|
- // obj.content = `请选择表单`
|
|
|
- // ElMessage({
|
|
|
- // message: '请选择表单',
|
|
|
- // type: 'success',
|
|
|
- // duration: 4 * 1000,
|
|
|
- // grouping: true
|
|
|
- // })
|
|
|
- // chrome.runtime.sendMessage({
|
|
|
- // type: 'FROM_SIDE_PANEL_TO_GET_PAGE_FORM'
|
|
|
- // })
|
|
|
- // }
|
|
|
}
|
|
|
}
|
|
|
)
|
|
@@ -258,6 +225,7 @@ export function useMsg(scrollbar?: any) {
|
|
|
id: messages.value.length + 1,
|
|
|
username: '用户1',
|
|
|
content: '',
|
|
|
+ type: '', // form 用于展示抽取的内容
|
|
|
rawContent: '', // 存储原始内容
|
|
|
timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
isSelf: false,
|
|
@@ -290,45 +258,36 @@ export function useMsg(scrollbar?: any) {
|
|
|
nextTick(() => {
|
|
|
scrollbar.value?.setScrollTop(99999)
|
|
|
})
|
|
|
- const iterator = await sendMessage(history)
|
|
|
- for await (const chunk of iterator) {
|
|
|
- if (chunk) {
|
|
|
- const decodedChunk = chunk.choices[0].delta.content
|
|
|
- if (decodedChunk) {
|
|
|
- // 保存原始内容
|
|
|
- obj.rawContent += decodedChunk
|
|
|
- // 实时格式化显示内容
|
|
|
- obj.content = formatMessage(obj.rawContent)
|
|
|
- // if (type.value === '2') obj.content = obj.content.replace(/item/g, '表单项').replace(/excelColumn/g, '对应数据源')
|
|
|
- }
|
|
|
- }
|
|
|
- scrollbar.value?.setScrollTop(99999)
|
|
|
- }
|
|
|
- console.log(obj.rawContent)
|
|
|
-
|
|
|
- //添加到存储历史
|
|
|
+ try {
|
|
|
+ const iterator = await sendMessage(history)
|
|
|
+ for await (const chunk of iterator) {
|
|
|
+ if (chunk) {
|
|
|
+ const decodedChunk = chunk.choices[0].delta.content
|
|
|
+ if (decodedChunk) {
|
|
|
+ // 保存原始内容
|
|
|
+ obj.rawContent += decodedChunk
|
|
|
+ // 实时格式化显示内容
|
|
|
+ obj.content = formatMessage(obj.rawContent)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ scrollbar.value?.setScrollTop(99999)
|
|
|
+ }
|
|
|
+ if (type.value === FunctionList.Intelligent_Form_filling) {
|
|
|
+ obj.type = 'form' //
|
|
|
+ }
|
|
|
+ return {rawContent:obj.rawContent,status:'ok'}
|
|
|
+ } catch (error) {
|
|
|
+ obj.content = '网络出错'
|
|
|
+ return { rawContent: obj.rawContent, status: 'error' }
|
|
|
+ } finally {
|
|
|
+ //添加到存储历史
|
|
|
useStore(msgUuid.value).add(cloneDeep(obj))
|
|
|
- // 处理最终内容
|
|
|
- sendLoading.value = false
|
|
|
- nextTick(() => {
|
|
|
- scrollbar.value?.setScrollTop(99999)
|
|
|
- })
|
|
|
- if (type.value === '2') {
|
|
|
- const arr = JSON.parse(obj.rawContent.split('json')[1].split('```')[0])
|
|
|
- const newArr = arr
|
|
|
- .map((obj) => {
|
|
|
- return `| ${[
|
|
|
- `“findBy”: \` "label",`,
|
|
|
- `"findByValue" \` “${obj.findByValue}”,`,
|
|
|
- `"数据来源字段" \` “${obj.excelColumn}”,`,
|
|
|
- `"表单项" \` “${obj.item}"`
|
|
|
- ].join(' ')} |`
|
|
|
- })
|
|
|
- .join('\n')
|
|
|
- obj.content = formatMessage('```json' + JSON.stringify(newArr) + '```')
|
|
|
- console.log(formatMessage('```json' + JSON.stringify(newArr) + '```'))
|
|
|
- }
|
|
|
- return obj.rawContent
|
|
|
+ // 处理最终内容
|
|
|
+ sendLoading.value = false
|
|
|
+ nextTick(() => {
|
|
|
+ scrollbar.value?.setScrollTop(99999)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -352,7 +311,6 @@ export function useMsg(scrollbar?: any) {
|
|
|
messages.value.push(obj)
|
|
|
scrollbar.value?.setScrollTop(99999)
|
|
|
const iterator = await sendMessage(data)
|
|
|
- console.log(iterator)
|
|
|
if (iterator.error) {
|
|
|
// 实时格式化显示内容
|
|
|
obj.content = iterator.error
|
|
@@ -386,12 +344,10 @@ export function useMsg(scrollbar?: any) {
|
|
|
indexTemp,
|
|
|
taklToHtml,
|
|
|
sendLoading,
|
|
|
- formMap,
|
|
|
type,
|
|
|
fetchRes,
|
|
|
streamRes,
|
|
|
getFormKeyAndValue,
|
|
|
- getFileSummary,
|
|
|
requestFlowFn
|
|
|
}
|
|
|
}
|