feat: show rag status when using models with knowledge collections

This commit is contained in:
Jannik Streidl 2024-08-22 14:12:18 +02:00
parent 14f0e6a2ba
commit abe17ab4b5
3 changed files with 70 additions and 19 deletions

View File

@ -601,8 +601,8 @@
let selectedModelIds = modelId let selectedModelIds = modelId
? [modelId] ? [modelId]
: atSelectedModel !== undefined : atSelectedModel !== undefined
? [atSelectedModel.id] ? [atSelectedModel.id]
: selectedModels; : selectedModels;
// Create response messages for each selected model // Create response messages for each selected model
const responseMessageIds = {}; const responseMessageIds = {};
@ -763,11 +763,11 @@
? await getAndUpdateUserLocation(localStorage.token) ? await getAndUpdateUserLocation(localStorage.token)
: undefined : undefined
)}${ )}${
(responseMessage?.userContext ?? null) responseMessage?.userContext ?? null
? `\n\nUser Context:\n${responseMessage?.userContext ?? ''}` ? `\n\nUser Context:\n${responseMessage?.userContext ?? ''}`
: '' : ''
}` }`
} }
: undefined, : undefined,
...messages ...messages
] ]
@ -809,7 +809,18 @@
let files = JSON.parse(JSON.stringify(chatFiles)); let files = JSON.parse(JSON.stringify(chatFiles));
if (model?.info?.meta?.knowledge ?? false) { if (model?.info?.meta?.knowledge ?? false) {
// Only initialize and add status if knowledge exists
responseMessage.statusHistory = [
{
done: false,
action: 'rag_search',
description: $i18n.t(`Searching in Knowledge for "{{searchQuery}}"`, {
searchQuery: userMessage.content
})
}
];
files.push(...model.info.meta.knowledge); files.push(...model.info.meta.knowledge);
messages = messages; // Trigger Svelte update
} }
files.push( files.push(
...(userMessage?.files ?? []).filter((item) => ...(userMessage?.files ?? []).filter((item) =>
@ -818,6 +829,8 @@
...(responseMessage?.files ?? []).filter((item) => ['web_search_results'].includes(item.type)) ...(responseMessage?.files ?? []).filter((item) => ['web_search_results'].includes(item.type))
); );
scrollToBottom();
eventTarget.dispatchEvent( eventTarget.dispatchEvent(
new CustomEvent('chat:start', { new CustomEvent('chat:start', {
detail: { detail: {
@ -835,10 +848,10 @@
options: { options: {
...(params ?? $settings.params ?? {}), ...(params ?? $settings.params ?? {}),
stop: stop:
(params?.stop ?? $settings?.params?.stop ?? undefined) params?.stop ?? $settings?.params?.stop ?? undefined
? (params?.stop.split(',').map((token) => token.trim()) ?? $settings.params.stop).map( ? (params?.stop.split(',').map((token) => token.trim()) ?? $settings.params.stop).map(
(str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"')) (str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
) )
: undefined, : undefined,
num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined, num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined,
repeat_penalty: repeat_penalty:
@ -888,6 +901,12 @@
if ('citations' in data) { if ('citations' in data) {
responseMessage.citations = data.citations; responseMessage.citations = data.citations;
// Only remove status if it was initially set
if (responseMessage.statusHistory) {
responseMessage.statusHistory = responseMessage.statusHistory.filter(
(status) => status.action !== 'rag_search'
);
}
continue; continue;
} }
@ -977,7 +996,20 @@
} }
} }
await saveChatHandler(_chatId); if ($chatId == _chatId) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, {
messages: messages,
history: history,
models: selectedModels,
params: params,
files: chatFiles
});
currentChatPage.set(1);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
}
}
} else { } else {
if (res !== null) { if (res !== null) {
const error = await res.json(); const error = await res.json();
@ -1044,7 +1076,18 @@
let files = JSON.parse(JSON.stringify(chatFiles)); let files = JSON.parse(JSON.stringify(chatFiles));
if (model?.info?.meta?.knowledge ?? false) { if (model?.info?.meta?.knowledge ?? false) {
// Only initialize and add status if knowledge exists
responseMessage.statusHistory = [
{
done: false,
action: 'rag_search',
description: $i18n.t(`Searching in Knowledge for "{{searchQuery}}"`, {
searchQuery: userMessage.content
})
}
];
files.push(...model.info.meta.knowledge); files.push(...model.info.meta.knowledge);
messages = messages; // Trigger Svelte update
} }
files.push( files.push(
...(userMessage?.files ?? []).filter((item) => ...(userMessage?.files ?? []).filter((item) =>
@ -1071,10 +1114,10 @@
stream: true, stream: true,
model: model.id, model: model.id,
stream_options: stream_options:
(model.info?.meta?.capabilities?.usage ?? false) model.info?.meta?.capabilities?.usage ?? false
? { ? {
include_usage: true include_usage: true
} }
: undefined, : undefined,
messages: [ messages: [
params?.system || $settings.system || (responseMessage?.userContext ?? null) params?.system || $settings.system || (responseMessage?.userContext ?? null)
@ -1087,11 +1130,11 @@
? await getAndUpdateUserLocation(localStorage.token) ? await getAndUpdateUserLocation(localStorage.token)
: undefined : undefined
)}${ )}${
(responseMessage?.userContext ?? null) responseMessage?.userContext ?? null
? `\n\nUser Context:\n${responseMessage?.userContext ?? ''}` ? `\n\nUser Context:\n${responseMessage?.userContext ?? ''}`
: '' : ''
}` }`
} }
: undefined, : undefined,
...messages ...messages
] ]
@ -1107,7 +1150,7 @@
text: text:
arr.length - 1 !== idx arr.length - 1 !== idx
? message.content ? message.content
: (message?.raContent ?? message.content) : message?.raContent ?? message.content
}, },
...message.files ...message.files
.filter((file) => file.type === 'image') .filter((file) => file.type === 'image')
@ -1118,20 +1161,20 @@
} }
})) }))
] ]
} }
: { : {
content: content:
arr.length - 1 !== idx arr.length - 1 !== idx
? message.content ? message.content
: (message?.raContent ?? message.content) : message?.raContent ?? message.content
}) })
})), })),
seed: params?.seed ?? $settings?.params?.seed ?? undefined, seed: params?.seed ?? $settings?.params?.seed ?? undefined,
stop: stop:
(params?.stop ?? $settings?.params?.stop ?? undefined) params?.stop ?? $settings?.params?.stop ?? undefined
? (params?.stop.split(',').map((token) => token.trim()) ?? $settings.params.stop).map( ? (params?.stop.split(',').map((token) => token.trim()) ?? $settings.params.stop).map(
(str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"')) (str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"'))
) )
: undefined, : undefined,
temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined, temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined,
top_p: params?.top_p ?? $settings?.params?.top_p ?? undefined, top_p: params?.top_p ?? $settings?.params?.top_p ?? undefined,
@ -1184,6 +1227,12 @@
if (citations) { if (citations) {
responseMessage.citations = citations; responseMessage.citations = citations;
// Only remove status if it was initially set
if (responseMessage.statusHistory) {
responseMessage.statusHistory = responseMessage.statusHistory.filter(
(status) => status.action !== 'rag_search'
);
}
continue; continue;
} }
@ -1238,7 +1287,7 @@
} }
if ($chatId == _chatId) { if ($chatId == _chatId) {
if (!$temporaryChatEnabled) { if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, { chat = await updateChatById(localStorage.token, _chatId, {
models: selectedModels, models: selectedModels,
messages: messages, messages: messages,

View File

@ -473,8 +473,8 @@
"Playground": "Testumgebung", "Playground": "Testumgebung",
"Please carefully review the following warnings:": "", "Please carefully review the following warnings:": "",
"Positive attitude": "Positive Einstellung", "Positive attitude": "Positive Einstellung",
"Previous 30 days": "Vorherige 30 Tage",
"Previous 7 days": "Vorherige 7 Tage", "Previous 7 days": "Vorherige 7 Tage",
"Previous 30 days": "Vorherige 30 Tage",
"Profile Image": "Profilbild", "Profile Image": "Profilbild",
"Prompt": "Prompt", "Prompt": "Prompt",
"Prompt (e.g. Tell me a fun fact about the Roman Empire)": "Prompt (z. B. \"Erzähle mir eine interessante Tatsache über das Römische Reich\")", "Prompt (e.g. Tell me a fun fact about the Roman Empire)": "Prompt (z. B. \"Erzähle mir eine interessante Tatsache über das Römische Reich\")",
@ -535,6 +535,7 @@
"Searched {{count}} sites_one": "{{count}} Seite durchsucht", "Searched {{count}} sites_one": "{{count}} Seite durchsucht",
"Searched {{count}} sites_other": "{{count}} Seiten durchsucht", "Searched {{count}} sites_other": "{{count}} Seiten durchsucht",
"Searching \"{{searchQuery}}\"": "Suche nach \"{{searchQuery}}\"", "Searching \"{{searchQuery}}\"": "Suche nach \"{{searchQuery}}\"",
"Searching in Knowledge for \"{{searchQuery}}\"": "Suche in Wissen nach \"{{searchQuery}}\"",
"Searxng Query URL": "Searxng-Abfrage-URL", "Searxng Query URL": "Searxng-Abfrage-URL",
"See readme.md for instructions": "Anleitung in readme.md anzeigen", "See readme.md for instructions": "Anleitung in readme.md anzeigen",
"See what's new": "Entdecken Sie die Neuigkeiten", "See what's new": "Entdecken Sie die Neuigkeiten",

View File

@ -543,6 +543,7 @@
"Select a engine": "", "Select a engine": "",
"Select a function": "", "Select a function": "",
"Select a model": "", "Select a model": "",
"Searching in Knowledge for \"{{searchQuery}}\"": "",
"Select a pipeline": "", "Select a pipeline": "",
"Select a pipeline url": "", "Select a pipeline url": "",
"Select a tool": "", "Select a tool": "",