|
@@ -643,8 +643,10 @@ import { CirclePlus, CircleClose, MagicStick, Download } from "@element-plus/ico
|
|
|
import { recorderInfoType, ChangeReasonType } from "./formData.ts";
|
|
import { recorderInfoType, ChangeReasonType } from "./formData.ts";
|
|
|
import { confirm } from "@/helper/message";
|
|
import { confirm } from "@/helper/message";
|
|
|
import { chat, abort, listModels } from "@/util/ollama";
|
|
import { chat, abort, listModels } from "@/util/ollama";
|
|
|
|
|
+import { createSSEPostClient } from "@/util/ssePost";
|
|
|
import { copyTextToClipboard } from "@/util/index";
|
|
import { copyTextToClipboard } from "@/util/index";
|
|
|
const props = defineProps({ caseId: Number, title: String });
|
|
const props = defineProps({ caseId: Number, title: String });
|
|
|
|
|
+let sseClient = null;
|
|
|
console.log("router.currentRoute", router.currentRoute.value?.params);
|
|
console.log("router.currentRoute", router.currentRoute.value?.params);
|
|
|
const fileId = computed(() => router.currentRoute.value?.params?.fileId);
|
|
const fileId = computed(() => router.currentRoute.value?.params?.fileId);
|
|
|
const caseId = computed(() => router.currentRoute.value?.params?.caseId);
|
|
const caseId = computed(() => router.currentRoute.value?.params?.caseId);
|
|
@@ -658,7 +660,8 @@ const aiImgData = ref({
|
|
|
list: [],
|
|
list: [],
|
|
|
});
|
|
});
|
|
|
const caseInfo = computed(() => getCaseInfoData());
|
|
const caseInfo = computed(() => getCaseInfoData());
|
|
|
-
|
|
|
|
|
|
|
+const messages = ref([])
|
|
|
|
|
+const isConnected = ref();
|
|
|
const data = reactive({
|
|
const data = reactive({
|
|
|
title: "",
|
|
title: "",
|
|
|
inquestNum: "", //现场勘验号
|
|
inquestNum: "", //现场勘验号
|
|
@@ -757,59 +760,121 @@ const handleAI = async () => {
|
|
|
aiImgData.value.loading = true;
|
|
aiImgData.value.loading = true;
|
|
|
aiImgData.value.result = "";
|
|
aiImgData.value.result = "";
|
|
|
isOption.value = true;
|
|
isOption.value = true;
|
|
|
- const item = aiImgData.value.list.find((i) => i.url == aiImgData.value.src);
|
|
|
|
|
- try {
|
|
|
|
|
- // const res = await getAiByImage({imageUrl: imageUrl})
|
|
|
|
|
- chat("", item.params + item.paramContent).then(async (stream) => {
|
|
|
|
|
- if (!aiImgShow.value) {
|
|
|
|
|
- abort();
|
|
|
|
|
- }
|
|
|
|
|
- for await (const part of stream) {
|
|
|
|
|
- // chatHistory.value.at(idx).text += part.message.content;
|
|
|
|
|
- let tep_mesg = part.message.content;
|
|
|
|
|
- console.log("isThinktep", tep_mesg);
|
|
|
|
|
- //判断是否是deepseek模型
|
|
|
|
|
- // if (testRegex.test(agentInfo.value.model)) {
|
|
|
|
|
- if (tep_mesg == "\u003c/think\u003e") {
|
|
|
|
|
- // isThink.value = true;
|
|
|
|
|
- aiImgData.value.loading = false;
|
|
|
|
|
- }
|
|
|
|
|
- if (!aiImgData.value.loading) {
|
|
|
|
|
- //清除think
|
|
|
|
|
- if (
|
|
|
|
|
- tep_mesg == "\u003cthink\u003e" ||
|
|
|
|
|
- tep_mesg == "\u003c/think\u003e"
|
|
|
|
|
- ) {
|
|
|
|
|
- // chatHistory.value.at(idx).think += "";
|
|
|
|
|
- } else {
|
|
|
|
|
- console.log("isThinktep_mesg", tep_mesg);
|
|
|
|
|
- aiImgData.value.result += tep_mesg;
|
|
|
|
|
- // chatHistory.value.at(idx).think += tep_mesg;
|
|
|
|
|
- }
|
|
|
|
|
- //如果结尾标签则停止拼接
|
|
|
|
|
- if (tep_mesg == "\u003c/think\u003e") {
|
|
|
|
|
- // isThink.value = false;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- // aiImgData.value.result += tep_mesg;
|
|
|
|
|
- // chatHistory.value.at(idx).text += tep_mesg;
|
|
|
|
|
- }
|
|
|
|
|
- // } else {
|
|
|
|
|
- // // chatHistory.value.at(idx).text += tep_mesg;
|
|
|
|
|
- // aiImgData.value.result += tep_mesg;
|
|
|
|
|
- // }
|
|
|
|
|
- // autoScrollSwitch.value && scrollToBottom(true);
|
|
|
|
|
- }
|
|
|
|
|
- isOption.value = false;
|
|
|
|
|
- console.log("handleAI完成", aiImgData.value.result);
|
|
|
|
|
- });
|
|
|
|
|
- // console.log("handleAI", res)
|
|
|
|
|
- // aiImgData.value.result = res
|
|
|
|
|
- // aiImgData.value.loading = false
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.log("handleAI", error);
|
|
|
|
|
- aiImgData.value.loading = false;
|
|
|
|
|
|
|
+ // const item = aiImgData.value.list.find((i) => i.url == aiImgData.value.src);
|
|
|
|
|
+ initSSE(aiImgData.value.src)
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // const res = await getAiByImage({imageUrl: imageUrl})
|
|
|
|
|
+ // chat("", item.params + item.paramContent).then(async (stream) => {
|
|
|
|
|
+ // if (!aiImgShow.value) {
|
|
|
|
|
+ // abort();
|
|
|
|
|
+ // }
|
|
|
|
|
+ // for await (const part of stream) {
|
|
|
|
|
+ // // chatHistory.value.at(idx).text += part.message.content;
|
|
|
|
|
+ // let tep_mesg = part.message.content;
|
|
|
|
|
+ // console.log("isThinktep", tep_mesg);
|
|
|
|
|
+ // //判断是否是deepseek模型
|
|
|
|
|
+ // // if (testRegex.test(agentInfo.value.model)) {
|
|
|
|
|
+ // if (tep_mesg == "\u003c/think\u003e") {
|
|
|
|
|
+ // // isThink.value = true;
|
|
|
|
|
+ // aiImgData.value.loading = false;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // if (!aiImgData.value.loading) {
|
|
|
|
|
+ // //清除think
|
|
|
|
|
+ // if (
|
|
|
|
|
+ // tep_mesg == "\u003cthink\u003e" ||
|
|
|
|
|
+ // tep_mesg == "\u003c/think\u003e"
|
|
|
|
|
+ // ) {
|
|
|
|
|
+ // // chatHistory.value.at(idx).think += "";
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // console.log("isThinktep_mesg", tep_mesg);
|
|
|
|
|
+ // aiImgData.value.result += tep_mesg;
|
|
|
|
|
+ // // chatHistory.value.at(idx).think += tep_mesg;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // //如果结尾标签则停止拼接
|
|
|
|
|
+ // if (tep_mesg == "\u003c/think\u003e") {
|
|
|
|
|
+ // // isThink.value = false;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // // aiImgData.value.result += tep_mesg;
|
|
|
|
|
+ // // chatHistory.value.at(idx).text += tep_mesg;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // // } else {
|
|
|
|
|
+ // // // chatHistory.value.at(idx).text += tep_mesg;
|
|
|
|
|
+ // // aiImgData.value.result += tep_mesg;
|
|
|
|
|
+ // // }
|
|
|
|
|
+ // // autoScrollSwitch.value && scrollToBottom(true);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // isOption.value = false;
|
|
|
|
|
+ // console.log("handleAI完成", aiImgData.value.result);
|
|
|
|
|
+ // });
|
|
|
|
|
+ // // console.log("handleAI", res)
|
|
|
|
|
+ // // aiImgData.value.result = res
|
|
|
|
|
+ // // aiImgData.value.loading = false
|
|
|
|
|
+ // } catch (error) {
|
|
|
|
|
+ // console.log("handleAI", error);
|
|
|
|
|
+ // aiImgData.value.loading = false;
|
|
|
|
|
+ // }
|
|
|
|
|
+};
|
|
|
|
|
+const initSSE = (url) => {
|
|
|
|
|
+ // 销毁旧连接(避免重复连接)
|
|
|
|
|
+ if (sseClient) {
|
|
|
|
|
+ sseClient.close();
|
|
|
}
|
|
}
|
|
|
|
|
+ sseClient = createSSEPostClient({
|
|
|
|
|
+ // headers: {
|
|
|
|
|
+ // Authorization: `Bearer ${localStorage.getItem('token')}`, // 认证 Token
|
|
|
|
|
+ // },
|
|
|
|
|
+ body: {
|
|
|
|
|
+ "inputs": {
|
|
|
|
|
+ "img": {
|
|
|
|
|
+ "type": "image",
|
|
|
|
|
+ "transfer_method": "remote_url",
|
|
|
|
|
+ "url": 'http://192.168.0.125:1804' + url
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ "response_mode": "streaming",
|
|
|
|
|
+ "user": "web-4dage"
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 监听连接成功
|
|
|
|
|
+ sseClient.on('open', () => {
|
|
|
|
|
+ isConnected.value = true;
|
|
|
|
|
+ console.log('POST SSE 连接成功');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 监听默认消息事件(服务器未指定 event 时)
|
|
|
|
|
+ sseClient.on('message', ({data, outputs}) => {
|
|
|
|
|
+ console.log('message连接成功', data);
|
|
|
|
|
+ if(data && data.text){
|
|
|
|
|
+ aiImgData.value.result += data.text
|
|
|
|
|
+ }
|
|
|
|
|
+ if(outputs && outputs.text){
|
|
|
|
|
+ aiImgData.value.result = outputs.text
|
|
|
|
|
+ }
|
|
|
|
|
+ aiImgData.value.loading = false
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // // 监听自定义事件(服务器指定 event: customEvent)
|
|
|
|
|
+ // sseClient.on('customEvent', (data) => {
|
|
|
|
|
+ // messages.value.push({ type: '自定义事件', data });
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ // 监听错误
|
|
|
|
|
+ sseClient.on('error', (err) => {
|
|
|
|
|
+ isOption.value = false;
|
|
|
|
|
+ messages.value.push({ type: '错误', data: err.message });
|
|
|
|
|
+ console.error('POST SSE 错误:', err);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 监听连接关闭
|
|
|
|
|
+ sseClient.on('close', () => {
|
|
|
|
|
+ isOption.value = false;
|
|
|
|
|
+ console.log('POST SSE 连接关闭');
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 建立连接
|
|
|
|
|
+ sseClient.connect();
|
|
|
};
|
|
};
|
|
|
const initSignatureAndWitInfo = () => {
|
|
const initSignatureAndWitInfo = () => {
|
|
|
(data.recorderInfo.length === 0 || !data.recorderInfo) &&
|
|
(data.recorderInfo.length === 0 || !data.recorderInfo) &&
|