|
@@ -68,7 +68,7 @@ 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();
|
|
|
|
|
|
export default {
|
|
export default {
|
|
@@ -279,7 +279,6 @@ 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'
|
|
|
|
let message = this.userInput.trim();
|
|
let message = this.userInput.trim();
|
|
if (!message) return;
|
|
if (!message) return;
|
|
|
|
|
|
@@ -310,72 +309,36 @@ export default {
|
|
botMessage,
|
|
botMessage,
|
|
thinkingController.signal
|
|
thinkingController.signal
|
|
);
|
|
);
|
|
- // 通过 HTTP 发送消息
|
|
|
|
|
|
+
|
|
try {
|
|
try {
|
|
- ///send-message
|
|
|
|
- const response = await fetch(`${wsUrl}`, {
|
|
|
|
- method: "POST",
|
|
|
|
- headers: {
|
|
|
|
- "Content-Type": "application/json",
|
|
|
|
- },
|
|
|
|
- /* mode: 'no-cors', */
|
|
|
|
- /* credentials: "include", */
|
|
|
|
- body: JSON.stringify({
|
|
|
|
- /* chatId: chatId, */
|
|
|
|
- message: message,
|
|
|
|
- /* output_type: "chat",
|
|
|
|
- input_type: "chat", */
|
|
|
|
- chat_config_id: this.currentChat_id,
|
|
|
|
- user_id: this.$store.state.user.id,
|
|
|
|
- session_id: this.session_id || "",
|
|
|
|
- /* tweaks:this.tweaks {
|
|
|
|
- "ChatInput-U82Vu": {},
|
|
|
|
- "Prompt-b8Z1E": {},
|
|
|
|
- "OllamaModel-z9SVx": {},
|
|
|
|
- "Milvus-l0vvr": {},
|
|
|
|
- "OllamaEmbeddings-4Ml5q": {},
|
|
|
|
- "ParseData-LM8yW": {},
|
|
|
|
- "ParseData-jVoZg": {},
|
|
|
|
- "APIRequest-OnZHl": {},
|
|
|
|
- "ParseData-fH1vY": {},
|
|
|
|
- "ChatOutput-ybzb9": {}
|
|
|
|
- } */
|
|
|
|
- }),
|
|
|
|
|
|
+ // 直接使用 axios 而不是 this.$axios
|
|
|
|
+ const response = await axios.post(`${process.env.VUE_APP_BASE_AI_API}/chatbot/chat`, {
|
|
|
|
+ message: message,
|
|
|
|
+ chat_config_id: this.currentChat_id,
|
|
|
|
+ user_id: this.$store.state.user.id,
|
|
|
|
+ session_id: this.session_id || "",
|
|
|
|
+ source: "pc",
|
|
});
|
|
});
|
|
|
|
+
|
|
// 停止思考动画
|
|
// 停止思考动画
|
|
thinkingController.abort();
|
|
thinkingController.abort();
|
|
await thinkingPromise;
|
|
await thinkingPromise;
|
|
- const result = await response.json();
|
|
|
|
- this.session_id = result.data.session_id;
|
|
|
|
- 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; //outputs?.[0]?.outputs?.[0]?.results?.message?.data?.additional_input;
|
|
|
|
|
|
|
|
- // 处理字符串,提取 ID 值
|
|
|
|
- this.idArray = additionalInput; /* .split('\n') // 按换行符分割
|
|
|
|
- .map(line => line.trim()) // 去除每行首尾空白 */
|
|
|
|
- /* .filter(line => line.startsWith('ID:')) // 只保留以 'ID:' 开头的行
|
|
|
|
- .map(line => line.substring(3).trim()); // 提取 'ID:' 后面的内容并去除空白 */
|
|
|
|
-
|
|
|
|
- // 创建符合要求格式的对象
|
|
|
|
- const idObject = { ids: this.idArray };
|
|
|
|
-
|
|
|
|
- console.log("ID Object:", idObject);
|
|
|
|
|
|
+ if (response.status === 200) {
|
|
|
|
+ const result = response.data;
|
|
|
|
+ this.session_id = result.data.session_id;
|
|
|
|
+
|
|
|
|
+ if (this.$route.name !== "ai") {
|
|
|
|
+ const additionalInput = result.data.milvus_ids;
|
|
|
|
+ this.idArray = additionalInput;
|
|
|
|
+ const idObject = { ids: this.idArray };
|
|
|
|
+ await this.getMinioUrls(idObject);
|
|
|
|
+ }
|
|
|
|
|
|
- // 调用方法来获取 Minio URL,传递新的 idObject
|
|
|
|
- await this.getMinioUrls(idObject);
|
|
|
|
|
|
+ this.handleResponse(result, botMessage);
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
}
|
|
-
|
|
|
|
- this.handleResponse(result, botMessage);
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error("Error sending message:", error);
|
|
console.error("Error sending message:", error);
|
|
thinkingController.abort();
|
|
thinkingController.abort();
|
|
@@ -385,7 +348,7 @@ export default {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
async getMinioUrls(idObject) {
|
|
async getMinioUrls(idObject) {
|
|
- this.minioUrls = []; // 清空之前的 URL
|
|
|
|
|
|
+ this.minioUrls = []; // 清空���前的 URL
|
|
|
|
|
|
try {
|
|
try {
|
|
console.log("Sending to backend:", JSON.stringify(idObject));
|
|
console.log("Sending to backend:", JSON.stringify(idObject));
|
|
@@ -795,7 +758,7 @@ export default {
|
|
border-radius: 50%; /* 圆形头像 */
|
|
border-radius: 50%; /* 圆形头像 */
|
|
/*background-color: #e9e0e0; 暂时用灰色代替,你可以用图片替换 */
|
|
/*background-color: #e9e0e0; 暂时用灰色代替,你可以用图片替换 */
|
|
align-self: start; /* 这将覆盖 flex 容器的 align-items 并将头像对齐到顶部 */
|
|
align-self: start; /* 这将覆盖 flex 容器的 align-items 并将头像对齐到顶部 */
|
|
- margin-right: 10px; /* 按需调整以在头像和消息之间提供空间 */
|
|
|
|
|
|
+ margin-right: 10px; /* 按需调整以��头像和消息之间提供空间 */
|
|
}
|
|
}
|
|
|
|
|
|
.user-avatar {
|
|
.user-avatar {
|