|
@@ -67,7 +67,7 @@ import ChatBox from "@/components/webAi/index.vue";
|
|
import LoginModal from "@/components/LoginModal";
|
|
import LoginModal from "@/components/LoginModal";
|
|
import MarkdownIt from "markdown-it";
|
|
import MarkdownIt from "markdown-it";
|
|
import { pcInnerAi, getMinioURl } from "@/api/api";
|
|
import { pcInnerAi, getMinioURl } from "@/api/api";
|
|
-import { modelList,get_default } from "@/api/knowledge";
|
|
|
|
|
|
+import { modelList, get_default } from "@/api/knowledge";
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
const md = new MarkdownIt();
|
|
const md = new MarkdownIt();
|
|
|
|
|
|
@@ -111,8 +111,8 @@ export default {
|
|
documentDirectory: "",
|
|
documentDirectory: "",
|
|
document: "",
|
|
document: "",
|
|
},
|
|
},
|
|
- currentChat_id:'',
|
|
|
|
- phone:''
|
|
|
|
|
|
+ currentChat_id: "",
|
|
|
|
+ phone: "",
|
|
};
|
|
};
|
|
},
|
|
},
|
|
mounted() {
|
|
mounted() {
|
|
@@ -130,7 +130,7 @@ export default {
|
|
if (AIData && AIData.data) {
|
|
if (AIData && AIData.data) {
|
|
console.log(AIData);
|
|
console.log(AIData);
|
|
this.wsUrl = AIData.data.url || "";
|
|
this.wsUrl = AIData.data.url || "";
|
|
- this.phone=AIData.data.phone || ""
|
|
|
|
|
|
+ this.phone = AIData.data.phone || "";
|
|
this.tweaks = AIData.data.tweaks || {};
|
|
this.tweaks = AIData.data.tweaks || {};
|
|
} else {
|
|
} else {
|
|
console.error("Invalid AIData structure");
|
|
console.error("Invalid AIData structure");
|
|
@@ -148,7 +148,7 @@ export default {
|
|
this.tweaks = res.data.tweaks;
|
|
this.tweaks = res.data.tweaks;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- this.init()
|
|
|
|
|
|
+ this.init();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
checkAIData() {
|
|
checkAIData() {
|
|
@@ -283,49 +283,53 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const chatId = this.getUuid();
|
|
const chatId = this.getUuid();
|
|
- const wsUrl = `${process.env.VUE_APP_BASE_API}/chatbot/chat` //this.wsUrl;'http://58.246.234.210:7860/api/v1/run/3ef7369e-b617-40d2-9e2e-54f3ee76ed2e?stream=false'
|
|
|
|
|
|
+ const wsUrl = `${process.env.VUE_APP_BASE_API}/chatbot/chat`; //this.wsUrl;'http://58.246.234.210:7860/api/v1/run/3ef7369e-b617-40d2-9e2e-54f3ee76ed2e?stream=false'
|
|
let message = this.userInput.trim();
|
|
let message = this.userInput.trim();
|
|
- if (message) {
|
|
|
|
- // Markdown换行:在每个换行符之前添加两个空格
|
|
|
|
- message = message.replace(/(\r\n|\r|\n)/g, " \n");
|
|
|
|
-
|
|
|
|
- this.messages.push({
|
|
|
|
- time: Date.now(),
|
|
|
|
- message: message,
|
|
|
|
- messageType: "TEXT",
|
|
|
|
- user: "user",
|
|
|
|
- done: true,
|
|
|
|
- });
|
|
|
|
- this.userInput = "";
|
|
|
|
- // 添加机器人的响应消息(初始为空)
|
|
|
|
- const botMessage = {
|
|
|
|
- user: "bot",
|
|
|
|
- messageType: "TEXT",
|
|
|
|
- message: "",
|
|
|
|
- html: "",
|
|
|
|
- time: Date.now(),
|
|
|
|
- done: false,
|
|
|
|
- };
|
|
|
|
- this.messages.push(botMessage);
|
|
|
|
|
|
+ if (!message) return;
|
|
|
|
+
|
|
|
|
+ // 添加用户消息
|
|
|
|
+ this.messages.push({
|
|
|
|
+ time: Date.now(),
|
|
|
|
+ message: message.replace(/(\r\n|\r|\n)/g, " \n"),
|
|
|
|
+ messageType: "TEXT",
|
|
|
|
+ user: "user",
|
|
|
|
+ done: true,
|
|
|
|
+ });
|
|
|
|
+ this.userInput = "";
|
|
|
|
+
|
|
|
|
+ // 添加机器人的响应消息
|
|
|
|
+ const botMessage = {
|
|
|
|
+ user: "bot",
|
|
|
|
+ messageType: "TEXT",
|
|
|
|
+ message: "",
|
|
|
|
+ html: "",
|
|
|
|
+ time: Date.now(),
|
|
|
|
+ done: false,
|
|
|
|
+ };
|
|
|
|
+ this.messages.push(botMessage);
|
|
|
|
|
|
- // 开始模拟思考
|
|
|
|
- const thinkingPromise = this.simulateThinking(botMessage);
|
|
|
|
- // 通过 HTTP 发送消息
|
|
|
|
- try {
|
|
|
|
- ///send-message
|
|
|
|
- const response = await fetch(`${wsUrl}`, {
|
|
|
|
- method: "POST",
|
|
|
|
- headers: {
|
|
|
|
- "Content-Type": "application/json",
|
|
|
|
- },
|
|
|
|
- body: JSON.stringify({
|
|
|
|
- /* chatId: chatId, */
|
|
|
|
- message: message,
|
|
|
|
- /* output_type: "chat",
|
|
|
|
|
|
+ // 开始思考动画
|
|
|
|
+ const thinkingController = new AbortController();
|
|
|
|
+ const thinkingPromise = this.simulateThinking(
|
|
|
|
+ botMessage,
|
|
|
|
+ thinkingController.signal
|
|
|
|
+ );
|
|
|
|
+ // 通过 HTTP 发送消息
|
|
|
|
+ try {
|
|
|
|
+ ///send-message
|
|
|
|
+ const response = await fetch(`${wsUrl}`, {
|
|
|
|
+ method: "POST",
|
|
|
|
+ headers: {
|
|
|
|
+ "Content-Type": "application/json",
|
|
|
|
+ },
|
|
|
|
+ body: JSON.stringify({
|
|
|
|
+ /* chatId: chatId, */
|
|
|
|
+ message: message,
|
|
|
|
+ /* output_type: "chat",
|
|
input_type: "chat", */
|
|
input_type: "chat", */
|
|
- chat_config_id:'3',//this.currentChat_id,
|
|
|
|
- user_id: this.phone,//this.tweaks.Memory-KtRT7.session_id,
|
|
|
|
- session_id: this.session_id || ""/* {
|
|
|
|
|
|
+ chat_config_id: "3", //this.currentChat_id,
|
|
|
|
+ user_id: this.phone, //this.tweaks.Memory-KtRT7.session_id,
|
|
|
|
+ session_id: this.session_id || "" /* {
|
|
"ChatInput-U82Vu": {},
|
|
"ChatInput-U82Vu": {},
|
|
"Prompt-b8Z1E": {},
|
|
"Prompt-b8Z1E": {},
|
|
"OllamaModel-z9SVx": {},
|
|
"OllamaModel-z9SVx": {},
|
|
@@ -337,47 +341,49 @@ export default {
|
|
"ParseData-fH1vY": {},
|
|
"ParseData-fH1vY": {},
|
|
"ChatOutput-ybzb9": {}
|
|
"ChatOutput-ybzb9": {}
|
|
} */,
|
|
} */,
|
|
- }),
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- const result = await response.json();
|
|
|
|
- this.session_id = result.data.session_id;
|
|
|
|
- console.log(result);
|
|
|
|
- if (result.code !== 200) {
|
|
|
|
- const errorText = await response.text(); // 获取错误文本
|
|
|
|
- throw new Error(
|
|
|
|
- `HTTP error! status: ${response.status}, message: ${errorText}`
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- // 等待思考动画完成
|
|
|
|
- await thinkingPromise;
|
|
|
|
- if (this.$route.name !== "ai") {
|
|
|
|
- // 提取 additional_input 数据
|
|
|
|
- const additionalInput = result.data.milvus_ids;
|
|
|
|
-
|
|
|
|
- // 处理字符串,提取 ID 值
|
|
|
|
- this.idArray = additionalInput
|
|
|
|
- /* .split("\n") // 按换行符分割
|
|
|
|
|
|
+ }),
|
|
|
|
+ });
|
|
|
|
+ // 停止思考动画
|
|
|
|
+ thinkingController.abort();
|
|
|
|
+ await thinkingPromise;
|
|
|
|
+ const result = await response.json();
|
|
|
|
+ this.session_id = result.data.session_id;
|
|
|
|
+ console.log(result);
|
|
|
|
+ if (result.code !== 200) {
|
|
|
|
+ const errorText = await response.text(); // 获取错误文本
|
|
|
|
+ throw new Error(
|
|
|
|
+ `HTTP error! status: ${response.status}, message: ${errorText}`
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ // 等待思考动画完成
|
|
|
|
+ await thinkingPromise;
|
|
|
|
+ if (this.$route.name !== "ai") {
|
|
|
|
+ // 提取 additional_input 数据
|
|
|
|
+ const additionalInput = result.data.milvus_ids;
|
|
|
|
+
|
|
|
|
+ // 处理字符串,提取 ID 值
|
|
|
|
+ this.idArray = additionalInput;
|
|
|
|
+ /* .split("\n") // 按换行符分割
|
|
.map((line) => line.trim()) // 去除每行首尾空白
|
|
.map((line) => line.trim()) // 去除每行首尾空白
|
|
.filter((line) => line.startsWith("ID:")) // 只保留以 'ID:' 开头的行
|
|
.filter((line) => line.startsWith("ID:")) // 只保留以 'ID:' 开头的行
|
|
.map((line) => line.substring(3).trim()); // 提取 'ID:' 后面的内容并去除空白 */
|
|
.map((line) => line.substring(3).trim()); // 提取 'ID:' 后面的内容并去除空白 */
|
|
|
|
|
|
- // 创建符合要求格式的对象
|
|
|
|
- const idObject = { ids: this.idArray };
|
|
|
|
|
|
+ // 创建符合要求格式的对象
|
|
|
|
+ const idObject = { ids: this.idArray };
|
|
|
|
|
|
- console.log("ID Object:", idObject);
|
|
|
|
|
|
+ console.log("ID Object:", idObject);
|
|
|
|
|
|
- // 调用方法来获取 Minio URL,传递新的 idObject
|
|
|
|
- await this.getMinioUrls(idObject);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.handleResponse(result, botMessage);
|
|
|
|
- } catch (error) {
|
|
|
|
- console.error("Error sending message:", error);
|
|
|
|
- // 如果发生错误,停止思考动画
|
|
|
|
- botMessage.done = true;
|
|
|
|
- botMessage.message = "抱歉,发生了错误,请稍后再试。";
|
|
|
|
|
|
+ // 调用方法来获取 Minio URL,传递新的 idObject
|
|
|
|
+ await this.getMinioUrls(idObject);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ this.handleResponse(result, botMessage);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("Error sending message:", error);
|
|
|
|
+ thinkingController.abort();
|
|
|
|
+ await thinkingPromise;
|
|
|
|
+ botMessage.done = true;
|
|
|
|
+ botMessage.message = "抱歉,发生了错误,请稍后再试。";
|
|
}
|
|
}
|
|
},
|
|
},
|
|
async getMinioUrls(idObject) {
|
|
async getMinioUrls(idObject) {
|
|
@@ -415,36 +421,46 @@ export default {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- async simulateThinking(message) {
|
|
|
|
|
|
+ async simulateThinking(message, signal) {
|
|
this.isThinking = true;
|
|
this.isThinking = true;
|
|
- const thinkingTime = Math.random() * 1000 + 500; // 思考时间为 0.5-1.5 秒
|
|
|
|
const dotInterval = 200; // 每 200ms 更新一次点
|
|
const dotInterval = 200; // 每 200ms 更新一次点
|
|
|
|
|
|
- const updateDots = () => {
|
|
|
|
- this.thinkingDots += ".";
|
|
|
|
- if (this.thinkingDots.length > 3) {
|
|
|
|
- this.thinkingDots = "";
|
|
|
|
- }
|
|
|
|
- message.message = this.thinkingDots;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- const intervalId = setInterval(updateDots, dotInterval);
|
|
|
|
|
|
+ return new Promise((resolve) => {
|
|
|
|
+ const updateDots = () => {
|
|
|
|
+ if (signal.aborted) {
|
|
|
|
+ clearInterval(intervalId);
|
|
|
|
+ this.isThinking = false;
|
|
|
|
+ this.thinkingDots = "";
|
|
|
|
+ message.message = "";
|
|
|
|
+ resolve();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- await new Promise((resolve) => setTimeout(resolve, thinkingTime));
|
|
|
|
|
|
+ this.thinkingDots += ".";
|
|
|
|
+ if (this.thinkingDots.length > 3) {
|
|
|
|
+ this.thinkingDots = "";
|
|
|
|
+ }
|
|
|
|
+ message.message = "思考中" + this.thinkingDots;
|
|
|
|
+ };
|
|
|
|
|
|
- clearInterval(intervalId);
|
|
|
|
- this.isThinking = false;
|
|
|
|
- this.thinkingDots = "";
|
|
|
|
- message.message = "";
|
|
|
|
|
|
+ const intervalId = setInterval(updateDots, dotInterval);
|
|
|
|
+ signal.addEventListener("abort", () => {
|
|
|
|
+ clearInterval(intervalId);
|
|
|
|
+ this.isThinking = false;
|
|
|
|
+ this.thinkingDots = "";
|
|
|
|
+ message.message = "";
|
|
|
|
+ resolve();
|
|
|
|
+ });
|
|
|
|
+ });
|
|
},
|
|
},
|
|
|
|
|
|
async handleResponse(value, existingMessage) {
|
|
async handleResponse(value, existingMessage) {
|
|
- const data = value.data.answer
|
|
|
|
|
|
+ const data = value.data.answer;
|
|
|
|
|
|
existingMessage.messageType = data;
|
|
existingMessage.messageType = data;
|
|
/* existingMessage.time = data.timestamp; */
|
|
/* existingMessage.time = data.timestamp; */
|
|
- existingMessage.message = '';
|
|
|
|
-
|
|
|
|
|
|
+ existingMessage.message = "";
|
|
|
|
+
|
|
let mainText = data;
|
|
let mainText = data;
|
|
let sourceText = "";
|
|
let sourceText = "";
|
|
|
|
|
|
@@ -737,7 +753,7 @@ export default {
|
|
overflow-y: auto; /* 如果消息太多,允许滚动 */
|
|
overflow-y: auto; /* 如果消息太多,允许滚动 */
|
|
height: calc(100vh - 130px); /* 高度需要根据输入框和其他元素的高度调整 */
|
|
height: calc(100vh - 130px); /* 高度需要根据输入框和其他元素的高度调整 */
|
|
padding: 10px; /* 或你希望的内边距大小 */
|
|
padding: 10px; /* 或你希望的内边距大小 */
|
|
- /* margin-bottom: 120px; */
|
|
|
|
|
|
+ /* margin-bottom: 120px; */
|
|
}
|
|
}
|
|
/* 针对手机端的媒体查询 */
|
|
/* 针对手机端的媒体查询 */
|
|
@media screen and (max-width: 768px) {
|
|
@media screen and (max-width: 768px) {
|