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