知识库查询
This commit is contained in:
@@ -274,15 +274,10 @@ public class AiChatServiceImpl implements AiChatService {
|
||||
chatRequest.setConversationId(conversation.getDifyConversationId());
|
||||
}
|
||||
|
||||
// 设置知识库ID列表(从Redis获取)
|
||||
if (knowledgeIds != null && !knowledgeIds.isEmpty()) {
|
||||
chatRequest.setDatasetIds(knowledgeIds);
|
||||
log.info("使用知识库: {}", knowledgeIds);
|
||||
}
|
||||
|
||||
chatRequest.setResponseMode("streaming");
|
||||
Map<String, Object> inputs = new HashMap<>();
|
||||
inputs.put("connectInternet", agent.getConnectInternet());
|
||||
inputs.put("datasets", JSON.toJSONString(knowledgeIds));
|
||||
chatRequest.setInputs(inputs);
|
||||
chatRequest.setFiles(filesData);
|
||||
// 6. 调用Dify流式对话
|
||||
|
||||
@@ -225,7 +225,7 @@ export const chatApi = {
|
||||
* @returns Promise<ResultDomain<boolean>>
|
||||
*/
|
||||
async deleteConversation(conversationId: string): Promise<ResultDomain<boolean>> {
|
||||
const response = await api.delete<boolean>(`/ai/chat/conversation/${conversationId}`, {
|
||||
const response = await api.delete<boolean>(`/ai/chat/conversation/${conversationId}`,{}, {
|
||||
showLoading: false
|
||||
});
|
||||
return response.data;
|
||||
@@ -249,7 +249,7 @@ export const chatApi = {
|
||||
* @returns Promise<ResultDomain<AiMessage[]>>
|
||||
*/
|
||||
async listMessages(conversationId: string): Promise<ResultDomain<AiMessage>> {
|
||||
const response = await api.get<AiMessage>(`/ai/chat/conversation/${conversationId}/messages`, {
|
||||
const response = await api.get<AiMessage>(`/ai/chat/conversation/${conversationId}/messages`, {},{
|
||||
showLoading: false
|
||||
});
|
||||
return response.data;
|
||||
|
||||
@@ -136,7 +136,7 @@ export const fileUploadApi = {
|
||||
* @returns Promise<ResultDomain<AiUploadFile[]>>
|
||||
*/
|
||||
async listFilesByMessage(messageId: string): Promise<ResultDomain<AiUploadFile[]>> {
|
||||
const response = await api.get<AiUploadFile[]>(`/ai/file/message/${messageId}`, {
|
||||
const response = await api.get<AiUploadFile[]>(`/ai/file/message/${messageId}`, {},{
|
||||
showLoading: false
|
||||
});
|
||||
return response.data;
|
||||
|
||||
@@ -460,10 +460,11 @@ async function loadRecentConversations() {
|
||||
conversations.value = [];
|
||||
}
|
||||
|
||||
// 不自动选中对话,等待用户手动点击
|
||||
// 如果有对话,自动选中第一个
|
||||
if (conversations.value.length > 0 && !currentConversation.value) {
|
||||
await selectConversation(conversations.value[0]);
|
||||
}
|
||||
// if (conversations.value.length > 0 && !currentConversation.value) {
|
||||
// await selectConversation(conversations.value[0]);
|
||||
// }
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载对话历史失败:', error);
|
||||
@@ -608,12 +609,23 @@ async function loadMessages(conversationId: string) {
|
||||
const messageList = result.dataList || result.data || [];
|
||||
messages.value = Array.isArray(messageList) ? messageList : [];
|
||||
|
||||
// 加载每条用户消息的关联文件
|
||||
// 加载每条用户消息的关联文件(只有当fileIDs不为空时)
|
||||
for (const message of messages.value) {
|
||||
if (message.role === 'user' && message.id) {
|
||||
if (message.role === 'user' && message.id && message.fileIDs) {
|
||||
// 检查fileIDs是否不为空(可能是JSON字符串或数组)
|
||||
let hasFiles = false;
|
||||
const fileIDs = message.fileIDs;
|
||||
if (typeof fileIDs === 'string') {
|
||||
hasFiles = fileIDs.trim() !== '' && fileIDs !== '[]';
|
||||
} else if (Array.isArray(fileIDs)) {
|
||||
hasFiles = (fileIDs as any[]).length > 0;
|
||||
}
|
||||
|
||||
if (hasFiles) {
|
||||
await loadMessageFiles(message.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await nextTick();
|
||||
scrollToBottom();
|
||||
@@ -1691,31 +1703,41 @@ onUnmounted(() => {
|
||||
}
|
||||
|
||||
.message-files {
|
||||
margin-top: 8px;
|
||||
margin-top: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
gap: 8px;
|
||||
|
||||
.message-file-item {
|
||||
.file-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 8px 12px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 6px;
|
||||
gap: 10px;
|
||||
padding: 10px 14px;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border: 1px solid rgba(255, 255, 255, 0.25);
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: all 0.2s;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
font-size: 13px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
border-color: rgba(255, 255, 255, 0.4);
|
||||
transform: translateX(3px);
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateX(2px);
|
||||
}
|
||||
|
||||
.file-icon {
|
||||
font-size: 16px;
|
||||
font-size: 18px;
|
||||
flex-shrink: 0;
|
||||
filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
|
||||
}
|
||||
|
||||
.file-name {
|
||||
@@ -1723,11 +1745,17 @@ onUnmounted(() => {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.file-size {
|
||||
opacity: 0.7;
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
font-size: 11px;
|
||||
font-weight: 400;
|
||||
flex-shrink: 0;
|
||||
padding-left: 8px;
|
||||
border-left: 1px solid rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user