|
|
|
@ -6,24 +6,17 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
|
|
|
|
import { doAiChat,aiChatData} from "@/api/doc/space" |
|
|
|
import {ElText,ElInput, ButtonInstance} from "element-plus"; |
|
|
|
import { VueMarkdown } from '@crazydos/vue-markdown' |
|
|
|
import rehypeRaw from 'rehype-raw' |
|
|
|
import remarkGfm from 'remark-gfm' |
|
|
|
import { useUserStore } from "@/store/modules/user"; |
|
|
|
|
|
|
|
//选中的咨询模式 |
|
|
|
const checkedModel = ref([]) |
|
|
|
const userStore = useUserStore(); |
|
|
|
const userid="p0"+userStore.userInfoCont.userId; |
|
|
|
|
|
|
|
const baseURL=import.meta.env.VITE_APP_BASE_API |
|
|
|
const conversation=ref("") //当前会话的uuid |
|
|
|
const myquestion=ref('') |
|
|
|
const controller = ref<AbortController | null>(null) |
|
|
|
|
|
|
|
const interact_msg=ref<{ask:boolean,think:string,content:string}[]>([]) |
|
|
|
const props = withDefaults(defineProps<{ |
|
|
|
//closefunc:()=>void, |
|
|
|
//agent:{model:boolean,name:string,uuid:string[]} |
|
|
|
}>(),{}) |
|
|
|
|
|
|
|
|
|
|
|
//消息体 |
|
|
|
@ -40,22 +33,15 @@ interface chatRecord{ |
|
|
|
messages:message[] |
|
|
|
} |
|
|
|
|
|
|
|
/* 中断函数,供按钮调用 */ |
|
|
|
function abortFetch() { |
|
|
|
if (controller.value) { |
|
|
|
controller.value.abort() |
|
|
|
controller.value = null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
defineExpose({onSendParamToAI}) |
|
|
|
|
|
|
|
async function onSendParamToAI(user:string,arr:Array<{ uuids: string[]; params: { [key: string]: any } }>){ |
|
|
|
async function onSendParamToAI(arr:Array<{ uuids: string[]; params: { [key: string]: any } }>){ |
|
|
|
interact_msg.value=[] |
|
|
|
for (let ele of arr){ |
|
|
|
interact_msg.value.unshift({ask:true,think:"", content:"AI正在分析。。。"}) |
|
|
|
for (let uid of ele.uuids){ |
|
|
|
await doRequest(user,uid,ele.params) |
|
|
|
await doRequest(userid,uid,ele.params) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -63,21 +49,15 @@ async function onSendParamToAI(user:string,arr:Array<{ uuids: string[]; params: |
|
|
|
async function doRequest(_user:string,uuid:string,param:any){ |
|
|
|
let mRespMsg="" |
|
|
|
const params={ |
|
|
|
"onlineSearch":"否", |
|
|
|
"useDataset":"否" |
|
|
|
} |
|
|
|
for (let item of checkedModel.value){ |
|
|
|
if(item==="onlineSearch") params.onlineSearch="是" |
|
|
|
if(item==="useDataset") params.useDataset="是" |
|
|
|
"checkType":"travel", |
|
|
|
"checkInfo":JSON.stringify(param) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
controller.value = new AbortController(); |
|
|
|
try{ |
|
|
|
const res= await doAiChat(`${baseURL}/aibot/assisted/${uuid}/chat`,{ |
|
|
|
const res= await doAiChat(`${baseURL}/aibot/assisted/${uuid}/workflow`,{ |
|
|
|
inputs: params, |
|
|
|
query:JSON.stringify(param), |
|
|
|
response_mode:"streaming", |
|
|
|
conversation_id:"",//conversation.value, |
|
|
|
user:_user,//这里已经base64解析了 |
|
|
|
},controller.value.signal |
|
|
|
) |
|
|
|
@ -103,9 +83,9 @@ async function doRequest(_user:string,uuid:string,param:any){ |
|
|
|
if (line.startsWith('data: ')) { |
|
|
|
const data = line.slice(6); |
|
|
|
const json = JSON.parse(data); |
|
|
|
if(json.event==="message"){ |
|
|
|
if(json.event==="text_chunk"){ |
|
|
|
//conversation.value=json.conversation_id |
|
|
|
mRespMsg+=json.answer |
|
|
|
mRespMsg+=json.data.text |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -122,7 +102,13 @@ async function doRequest(_user:string,uuid:string,param:any){ |
|
|
|
interact_msg.value.unshift({ask:false,think:"",content:arr[0]}) |
|
|
|
}else{ |
|
|
|
//思考模式 |
|
|
|
interact_msg.value.unshift({ask:false,think:arr[0],content:arr[1]}) |
|
|
|
let st = arr[1].trim().match(/({.*})/s) |
|
|
|
if (st){ |
|
|
|
let res= JSON.parse(st[1]) |
|
|
|
interact_msg.value.unshift({ask:false,think:res.success,content:res.reason}) |
|
|
|
}else{ |
|
|
|
interact_msg.value.unshift({ask:false,think:arr[0],content:arr[1]}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -142,7 +128,7 @@ function resetContext(){ |
|
|
|
<div class="reply_area" > |
|
|
|
<template v-for="msg of interact_msg"> |
|
|
|
<div v-if="msg.ask" class="t_ask" >{{ msg.content }}</div> |
|
|
|
<div v-else class="t_resp"> |
|
|
|
<div v-else class="t_resp" :class="{merr:msg.think==false}"> |
|
|
|
{{ msg.content }} |
|
|
|
<!-- <VueMarkdown :markdown="msg.content"></VueMarkdown> --> |
|
|
|
</div> |
|
|
|
@ -170,8 +156,12 @@ function resetContext(){ |
|
|
|
} |
|
|
|
.t_resp{ |
|
|
|
margin: 5px; |
|
|
|
font-size:14px; |
|
|
|
align-self: start; |
|
|
|
color: black; |
|
|
|
background-color: rgb(222, 243, 222); |
|
|
|
} |
|
|
|
.merr{ |
|
|
|
background-color: rgb(253 176 211); |
|
|
|
} |
|
|
|
</style> |
|
|
|
|