提交 71d717e6 authored 作者: coderBryanFu's avatar coderBryanFu

update

上级 35021936
...@@ -7,3 +7,12 @@ export function getChat(params) { ...@@ -7,3 +7,12 @@ export function getChat(params) {
data: params, data: params,
}) })
} }
// 清单问答
export function getChecklistChat(params) {
return request({
method: 'POST',
url: `/checklistChat/langgraph/checklist/chat-stream`,
data: params,
})
}
\ No newline at end of file
...@@ -85,9 +85,9 @@ ...@@ -85,9 +85,9 @@
<div class="text">{{ `正在思考中,请稍候` }}</div> <div class="text">{{ `正在思考中,请稍候` }}</div>
</div> </div>
<div class="loading-indicator"> <div class="loading-indicator">
<span class="dot"></span> <span v-show="loadingDotIndex < 3" class="dot"></span>
<span class="dot"></span> <span v-show="loadingDotIndex > 0" class="dot"></span>
<span class="dot"></span> <span v-show="loadingDotIndex === 2" class="dot"></span>
</div> </div>
</div> </div>
</div> </div>
...@@ -140,7 +140,7 @@ import { ref, onMounted, onUnmounted, nextTick } from "vue"; ...@@ -140,7 +140,7 @@ import { ref, onMounted, onUnmounted, nextTick } from "vue";
import { fetchEventSource } from "@microsoft/fetch-event-source"; import { fetchEventSource } from "@microsoft/fetch-event-source";
import MarkdownIt from "markdown-it"; import MarkdownIt from "markdown-it";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { getChat } from "@/api/chat"; import { getChat, getChecklistChat } from "@/api/chat";
import router from "@/router/index"; import router from "@/router/index";
import json5 from "json5"; import json5 from "json5";
...@@ -152,24 +152,8 @@ const areaList = ref([ ...@@ -152,24 +152,8 @@ const areaList = ref([
value: "法案" value: "法案"
}, },
{ {
label: "政令", label: "清单",
value: "政令" value: "清单"
},
{
label: "智库",
value: "智库"
},
{
label: "出口管制",
value: "出口管制"
},
{
label: "投融资限制",
value: "投融资限制"
},
{
label: "市场准入限制",
value: "市场准入限制"
} }
]); ]);
...@@ -186,6 +170,8 @@ const userInput = ref(""); ...@@ -186,6 +170,8 @@ const userInput = ref("");
const isLoading = ref(false); const isLoading = ref(false);
const abortController = ref(null); const abortController = ref(null);
const loadingDotIndex = ref(0);
// 消息数据 // 消息数据
const messages = ref([ const messages = ref([
// { // {
...@@ -369,6 +355,13 @@ const connectSSE = async question => { ...@@ -369,6 +355,13 @@ const connectSSE = async question => {
addMessage("ai", ""); addMessage("ai", "");
isLoading.value = true; isLoading.value = true;
const loadingInterval = setInterval(() => {
if (loadingDotIndex.value < 2) {
loadingDotIndex.value++;
} else {
loadingDotIndex.value = 0;
}
},500);
// 创建 AbortController 用于取消请求 // 创建 AbortController 用于取消请求
abortController.value = new AbortController(); abortController.value = new AbortController();
...@@ -394,6 +387,7 @@ const connectSSE = async question => { ...@@ -394,6 +387,7 @@ const connectSSE = async question => {
openWhenHidden: true, openWhenHidden: true,
async onopen(res) { async onopen(res) {
isLoading.value = false; isLoading.value = false;
clearInterval(loadingInterval);
console.log("流式回答开始", res); console.log("流式回答开始", res);
}, },
async onmessage(res) { async onmessage(res) {
...@@ -465,21 +459,138 @@ const connectSSE = async question => { ...@@ -465,21 +459,138 @@ const connectSSE = async question => {
}); });
}; };
const chat = async () => { function formatDateTime(isoString) {
const date = new Date(isoString);
// 获取各个时间部分
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始
const day = String(date.getDate()).padStart(2, "0");
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
const chat = async question => {
// 添加用户消息
addMessage("user", question);
const params = { const params = {
query: "如何检索?", model: "neko-checklist-agent",
knowledge_base_name: "kb_test251112", // messages: [
top_k: 6, // {
score_threshold: 0.5, // role: "user",
metadata: { year: 2024 } // content: "2024年12月5日当期实体清单的主要制裁对象、制裁原因是?"
// }
// ]
messages: messages.value.map(item => {
return {
role: item.type === "ai" ? "assistant" : "user",
content: item.content
};
})
}; };
try { // 添加空的 AI 消息用于流式更新
const res = await getChat(params); addMessage("ai", "");
console.log("chat", res);
} catch (error) { isLoading.value = true;
console.error(error);
const loadingInterval = setInterval(() => {
if (loadingDotIndex.value < 2) {
loadingDotIndex.value++;
} else {
loadingDotIndex.value = 0;
} }
},500);
// 创建 AbortController 用于取消请求
abortController.value = new AbortController();
fetchEventSource("/checklistChat/langgraph/checklist/chat-stream", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(params),
signal: abortController.value.signal,
openWhenHidden: true,
async onopen(res) {
isLoading.value = false;
clearInterval(loadingInterval);
console.log("流式回答开始", res);
},
async onmessage(res) {
console.log("res", res);
if (res.data === "[DONE]") {
ElMessage.success("生成完成!");
}
let msgData = JSON.parse(res.data);
if (msgData.logs) {
console.log("docs", msgData.logs);
const lastMessage = messages.value[messages.value.length - 1];
if (lastMessage && lastMessage.type === "ai") {
let newDocs = msgData.logs.map(item => {
return item.detail + " " + formatDateTime(item.ts);
});
lastMessage.source = newDocs;
scrollToBottom();
}
}
if (msgData.choices && msgData.choices[0].delta.content) {
isCurAnswerMessage.value = true;
let content = msgData.choices[0].delta.content;
if (content === "[DONE]") {
ElMessage.success("生成完成!");
} else {
aiMessage.value += content;
updateLastAIMessage(aiMessage.value);
}
}
// if (res.event === "end_of_workflow") {
// ElMessage.success("问答完成!");
// abortController.value.abort();
// abortController.value = new AbortController();
// return;
// }
// if (res.event === "start_of_agent" && msgData.agent_name === "answer") {
// isCurAnswerMessage.value = true;
// aiMessage.value = "";
// }
// if (res.event === "message") {
// let content = msgData.delta.content;
// console.log("msgData", msgData);
// console.log("content", content);
// if (content !== "[DONE]") {
// aiMessage.value += content;
// updateLastAIMessage(aiMessage.value);
// } else {
// aiMessage.value = "";
// abortController.value.abort();
// abortController.value = new AbortController();
// }
// }
},
onerror(error) {
ElMessage({
message: "问答报错!",
type: "warning"
});
abortController.value.abort();
abortController.value = new AbortController();
throw new Error(error);
}
}).catch(error => {
ElMessage({
message: "问答报错!",
type: "warning"
});
abortController.value.abort();
abortController.value = new AbortController();
throw new Error(error);
});
}; };
// 发送消息 // 发送消息
...@@ -496,8 +607,11 @@ const sendMessage = async () => { ...@@ -496,8 +607,11 @@ const sendMessage = async () => {
} }
userInput.value = ""; userInput.value = "";
if (curArea.value === "法案") {
await connectSSE(question); await connectSSE(question);
// chat(); } else {
chat(question);
}
}; };
const newChatTitle = ref(""); // 新对话 const newChatTitle = ref(""); // 新对话
......
...@@ -56,6 +56,11 @@ export default defineConfig({ ...@@ -56,6 +56,11 @@ export default defineConfig({
target: 'http://192.168.184.24:7861/', target: 'http://192.168.184.24:7861/',
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/aichat/, '') rewrite: (path) => path.replace(/^\/aichat/, '')
},
'/checklistChat': {
target: 'http://8.140.26.4:10021/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/checklistChat/, '')
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论