mirror of
https://github.com/open-webui/open-webui
synced 2025-05-20 13:15:13 +00:00
feat: knowledge integration
This commit is contained in:
parent
78272aed8d
commit
b565301a47
@ -575,8 +575,6 @@
|
|||||||
const sendPromptOllama = async (model, userPrompt, responseMessageId, _chatId) => {
|
const sendPromptOllama = async (model, userPrompt, responseMessageId, _chatId) => {
|
||||||
let _response = null;
|
let _response = null;
|
||||||
|
|
||||||
model = model.id;
|
|
||||||
|
|
||||||
const responseMessage = history.messages[responseMessageId];
|
const responseMessage = history.messages[responseMessageId];
|
||||||
|
|
||||||
// Wait until history/message have been updated
|
// Wait until history/message have been updated
|
||||||
@ -634,17 +632,29 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const docs = messages
|
let docs = [];
|
||||||
|
|
||||||
|
if (model.info.meta.knowledge) {
|
||||||
|
docs = model.info.meta.knowledge;
|
||||||
|
}
|
||||||
|
|
||||||
|
docs = [
|
||||||
|
...docs,
|
||||||
|
...messages
|
||||||
.filter((message) => message?.files ?? null)
|
.filter((message) => message?.files ?? null)
|
||||||
.map((message) =>
|
.map((message) =>
|
||||||
message.files.filter((item) =>
|
message.files.filter((item) =>
|
||||||
['doc', 'collection', 'web_search_results'].includes(item.type)
|
['doc', 'collection', 'web_search_results'].includes(item.type)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.flat(1);
|
.flat(1)
|
||||||
|
].filter(
|
||||||
|
(item, index, array) =>
|
||||||
|
array.findIndex((i) => JSON.stringify(i) === JSON.stringify(item)) === index
|
||||||
|
);
|
||||||
|
|
||||||
const [res, controller] = await generateChatCompletion(localStorage.token, {
|
const [res, controller] = await generateChatCompletion(localStorage.token, {
|
||||||
model: model,
|
model: model.id,
|
||||||
messages: messagesBody,
|
messages: messagesBody,
|
||||||
options: {
|
options: {
|
||||||
...($settings.params ?? {}),
|
...($settings.params ?? {}),
|
||||||
@ -682,7 +692,7 @@
|
|||||||
controller.abort('User: Stop Response');
|
controller.abort('User: Stop Response');
|
||||||
} else {
|
} else {
|
||||||
const messages = createMessagesList(responseMessageId);
|
const messages = createMessagesList(responseMessageId);
|
||||||
await chatCompletedHandler(model, messages);
|
await chatCompletedHandler(model.id, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
_response = responseMessage.content;
|
_response = responseMessage.content;
|
||||||
@ -743,7 +753,7 @@
|
|||||||
selectedModelfile.title.charAt(0).toUpperCase() +
|
selectedModelfile.title.charAt(0).toUpperCase() +
|
||||||
selectedModelfile.title.slice(1)
|
selectedModelfile.title.slice(1)
|
||||||
}`
|
}`
|
||||||
: `${model}`,
|
: `${model.id}`,
|
||||||
{
|
{
|
||||||
body: responseMessage.content,
|
body: responseMessage.content,
|
||||||
icon: selectedModelfile?.imageUrl ?? `${WEBUI_BASE_URL}/static/favicon.png`
|
icon: selectedModelfile?.imageUrl ?? `${WEBUI_BASE_URL}/static/favicon.png`
|
||||||
@ -830,16 +840,26 @@
|
|||||||
let _response = null;
|
let _response = null;
|
||||||
const responseMessage = history.messages[responseMessageId];
|
const responseMessage = history.messages[responseMessageId];
|
||||||
|
|
||||||
const docs = messages
|
let docs = [];
|
||||||
|
|
||||||
|
if (model.info.meta.knowledge) {
|
||||||
|
docs = model.info.meta.knowledge;
|
||||||
|
}
|
||||||
|
|
||||||
|
docs = [
|
||||||
|
...docs,
|
||||||
|
...messages
|
||||||
.filter((message) => message?.files ?? null)
|
.filter((message) => message?.files ?? null)
|
||||||
.map((message) =>
|
.map((message) =>
|
||||||
message.files.filter((item) =>
|
message.files.filter((item) =>
|
||||||
['doc', 'collection', 'web_search_results'].includes(item.type)
|
['doc', 'collection', 'web_search_results'].includes(item.type)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.flat(1);
|
.flat(1)
|
||||||
|
].filter(
|
||||||
console.log(docs);
|
(item, index, array) =>
|
||||||
|
array.findIndex((i) => JSON.stringify(i) === JSON.stringify(item)) === index
|
||||||
|
);
|
||||||
|
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
|
|
||||||
@ -971,7 +991,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($settings.notificationEnabled && !document.hasFocus()) {
|
if ($settings.notificationEnabled && !document.hasFocus()) {
|
||||||
const notification = new Notification(`OpenAI ${model}`, {
|
const notification = new Notification(`${model.id}`, {
|
||||||
body: responseMessage.content,
|
body: responseMessage.content,
|
||||||
icon: `${WEBUI_BASE_URL}/static/favicon.png`
|
icon: `${WEBUI_BASE_URL}/static/favicon.png`
|
||||||
});
|
});
|
||||||
|
@ -67,7 +67,13 @@
|
|||||||
class="flex gap-2.5 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
class="flex gap-2.5 items-center px-3 py-2 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (!knowledge.find((k) => k.name === item.name)) {
|
if (!knowledge.find((k) => k.name === item.name)) {
|
||||||
knowledge = [...knowledge, item];
|
knowledge = [
|
||||||
|
...knowledge,
|
||||||
|
{
|
||||||
|
...item,
|
||||||
|
type: item?.type ?? 'doc'
|
||||||
|
}
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user