|
|
|
|
@ -38,7 +38,7 @@
|
|
|
|
|
>
|
|
|
|
|
<div class="chat-info">
|
|
|
|
|
<div class="chat-title-row">
|
|
|
|
|
<span class="chat-title">{{ chat.messageTopic }}</span>
|
|
|
|
|
<span class="chat-title" :title="chat.messageTopic">{{ chat.messageTopic }}</span>
|
|
|
|
|
<!-- 加载动画 -->
|
|
|
|
|
<div v-if="loadingChatId === chat.sessionId" class="loading-indicator">
|
|
|
|
|
<el-icon class="is-loading">
|
|
|
|
|
@ -469,6 +469,8 @@ const platformIcon = ref('');//ai平台图标
|
|
|
|
|
const chatList = ref<ChatSession[]>([])
|
|
|
|
|
|
|
|
|
|
const selectedKnowledgeBaseId = ref()
|
|
|
|
|
const embeddingModelId = ref();
|
|
|
|
|
const retrieveLimit = ref();
|
|
|
|
|
const aiKnowledgeBaseList = ref<AiKnowledgeBaseVO[]>([])
|
|
|
|
|
|
|
|
|
|
// 可用模型
|
|
|
|
|
@ -488,9 +490,17 @@ const selectedModel = ref(0)
|
|
|
|
|
const getAiChatSessions = async () => {
|
|
|
|
|
sidebarLoading.value = true;
|
|
|
|
|
chatList.value = [];
|
|
|
|
|
const res = await getAiChatMessageList({knowledgeBaseId: selectedKnowledgeBaseId.value});
|
|
|
|
|
chatList.value = res.data;
|
|
|
|
|
console.log(res)
|
|
|
|
|
const res = await getAiChatMessageList({knowledgeBaseId: selectedKnowledgeBaseId.value ? selectedKnowledgeBaseId.value : -1 });
|
|
|
|
|
chatList.value = res.data.map(item => ({
|
|
|
|
|
...item,
|
|
|
|
|
messageTopic: typeof item.messageTopic === 'string'
|
|
|
|
|
? item.messageTopic.replace(/^["']|["']$/g, '')
|
|
|
|
|
: item.messageTopic
|
|
|
|
|
}));
|
|
|
|
|
// chatList.value.forEach(cl =>{
|
|
|
|
|
// cl.messageTopic = JSON.parse(cl.messageTopic)
|
|
|
|
|
// });
|
|
|
|
|
// console.log(res)
|
|
|
|
|
sidebarLoading.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -500,7 +510,7 @@ const getAiModelList = async () => {
|
|
|
|
|
const res = await getAiModelJoinList({modelTypeId: 1});
|
|
|
|
|
aiModelList.value = res.data;
|
|
|
|
|
await setDefaultAiModel();
|
|
|
|
|
console.log(res)
|
|
|
|
|
// console.log(res)
|
|
|
|
|
// platformList.value = res.data;
|
|
|
|
|
// loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
@ -511,7 +521,7 @@ const setDefaultAiModel = async () => {
|
|
|
|
|
// alert(JSON.stringify(item))
|
|
|
|
|
selectedModel.value = item.modelId;
|
|
|
|
|
provider.value = item.platformCode;
|
|
|
|
|
console.log(item.platformIcon)
|
|
|
|
|
// console.log(item.platformIcon)
|
|
|
|
|
platformIcon.value = item.platformIcon;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
@ -622,7 +632,7 @@ const selectChat = async (chatSessionId: string) => {
|
|
|
|
|
deletingChatId.value = null
|
|
|
|
|
|
|
|
|
|
activeChatSessionId.value = chatSessionId
|
|
|
|
|
console.log(activeChatSessionId.value)
|
|
|
|
|
// console.log(activeChatSessionId.value)
|
|
|
|
|
|
|
|
|
|
if (!currentChat.value.messages) {
|
|
|
|
|
// 设置加载状态
|
|
|
|
|
@ -636,12 +646,15 @@ const selectChat = async (chatSessionId: string) => {
|
|
|
|
|
|
|
|
|
|
// 验证当前会话ID是否还是用户选择的那个
|
|
|
|
|
if (activeChatSessionId.value === chatSessionId) {
|
|
|
|
|
console.log(res)
|
|
|
|
|
// console.log(res)
|
|
|
|
|
// res.data已经是对象数组
|
|
|
|
|
|
|
|
|
|
currentChat.value.messages = res.data.map(item => {
|
|
|
|
|
return {
|
|
|
|
|
role: item.role,
|
|
|
|
|
content: item.content,
|
|
|
|
|
content: typeof item.content === 'string'
|
|
|
|
|
? item.content.replace(/^["']|["']$/g, '')
|
|
|
|
|
: item.content,
|
|
|
|
|
timestamp: item.timestamp
|
|
|
|
|
// 可以根据需要转换字段
|
|
|
|
|
};
|
|
|
|
|
@ -865,7 +878,7 @@ const sendMessage = async () => {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(activeChatSessionId.value)
|
|
|
|
|
// console.log(activeChatSessionId.value)
|
|
|
|
|
// 如果没有当前对话,自动创建一个新的
|
|
|
|
|
if (!currentChat.value) {
|
|
|
|
|
newChatFirstMessage()
|
|
|
|
|
@ -904,14 +917,16 @@ const sendMessage = async () => {
|
|
|
|
|
sendMessages.push(userMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(sendMessages.map(m => ({role: m.role, content: m.content})));
|
|
|
|
|
// console.log(sendMessages.map(m => ({role: m.role, content: m.content})));
|
|
|
|
|
|
|
|
|
|
const response = await service.post('/ai/assistant/chatStream?provider=' + provider.value, {
|
|
|
|
|
messages: sendMessages.map(m => ({role: m.role, content: m.content})),
|
|
|
|
|
carryHistoryFlag: carryHistory.value ? "1" : "0",
|
|
|
|
|
modelId: selectedModel.value,
|
|
|
|
|
sessionId: activeChatSessionId.value,
|
|
|
|
|
knowledgeBaseId: selectedKnowledgeBaseId.value
|
|
|
|
|
knowledgeBaseId: selectedKnowledgeBaseId.value,
|
|
|
|
|
embeddingModelId: embeddingModelId.value,
|
|
|
|
|
retrieveLimit:retrieveLimit.value
|
|
|
|
|
}, {
|
|
|
|
|
responseType: 'text',
|
|
|
|
|
headers: {
|
|
|
|
|
@ -920,14 +935,12 @@ const sendMessage = async () => {
|
|
|
|
|
},
|
|
|
|
|
onDownloadProgress: progress => {
|
|
|
|
|
const raw = progress.event.target.responseText
|
|
|
|
|
console.log(1)
|
|
|
|
|
console.log(raw)
|
|
|
|
|
console.log(2)
|
|
|
|
|
// console.log(raw)
|
|
|
|
|
processStream(raw)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
console.log("----" + streamingContent.value);
|
|
|
|
|
// console.log("----" + streamingContent.value);
|
|
|
|
|
// 添加用户消息到messages数组
|
|
|
|
|
currentChat.value.messages.push({
|
|
|
|
|
role: 'assistant',
|
|
|
|
|
@ -953,7 +966,6 @@ const processStream = (raw) => {
|
|
|
|
|
let fullText = ''
|
|
|
|
|
|
|
|
|
|
chunks.forEach(chunk => {
|
|
|
|
|
// console.log(chunk)
|
|
|
|
|
const content = chunk.substring(5)
|
|
|
|
|
if (content && content !== '[DONE]') {
|
|
|
|
|
fullText += content
|
|
|
|
|
@ -1148,6 +1160,8 @@ const getKnowledgeBaseSelectList = async () => {
|
|
|
|
|
// 生命周期
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
let knowledgeBaseId = proxy.$route.params?.knowledgeBaseId
|
|
|
|
|
embeddingModelId.value = proxy.$route.params?.embeddingModelId
|
|
|
|
|
retrieveLimit.value = proxy.$route.params?.retrieveLimit
|
|
|
|
|
if (knowledgeBaseId && knowledgeBaseId !== '') {
|
|
|
|
|
selectedKnowledgeBaseId.value = parseInt(knowledgeBaseId);
|
|
|
|
|
chatTitle.value = 'AI知识库';
|
|
|
|
|
|