-
+
+
-
- {title != '' ? title : 'Ollama Web UI'}
+
+
+ {title != '' ? title : 'Ollama Web UI'}
+
- {#if shareEnabled}
-
-
diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte
index 927d87d6f..afd4b0e52 100644
--- a/src/lib/components/layout/Sidebar.svelte
+++ b/src/lib/components/layout/Sidebar.svelte
@@ -6,9 +6,14 @@
import { goto, invalidateAll } from '$app/navigation';
import { page } from '$app/stores';
- import { user, chats, settings, showSettings, chatId } from '$lib/stores';
+ import { user, chats, settings, showSettings, chatId, tags } from '$lib/stores';
import { onMount } from 'svelte';
- import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats';
+ import {
+ deleteChatById,
+ getChatList,
+ getChatListByTagName,
+ updateChatById
+ } from '$lib/apis/chats';
let show = false;
let navElement;
@@ -28,6 +33,12 @@
}
await chats.set(await getChatList(localStorage.token));
+
+ tags.subscribe(async (value) => {
+ if (value.length === 0) {
+ await chats.set(await getChatList(localStorage.token));
+ }
+ });
});
const loadChat = async (id) => {
@@ -281,6 +292,29 @@
{#each $chats.filter((chat) => {
if (search === '') {
diff --git a/src/lib/stores/index.ts b/src/lib/stores/index.ts
index c7d8f5e62..7880235cf 100644
--- a/src/lib/stores/index.ts
+++ b/src/lib/stores/index.ts
@@ -10,6 +10,7 @@ export const theme = writable('dark');
export const chatId = writable('');
export const chats = writable([]);
+export const tags = writable([]);
export const models = writable([]);
export const modelfiles = writable([]);
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte
index 39ae0eeac..c7839d93f 100644
--- a/src/routes/(app)/+layout.svelte
+++ b/src/routes/(app)/+layout.svelte
@@ -20,7 +20,8 @@
models,
modelfiles,
prompts,
- documents
+ documents,
+ tags
} from '$lib/stores';
import { REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
@@ -29,6 +30,7 @@
import { checkVersion } from '$lib/utils';
import ShortcutsModal from '$lib/components/chat/ShortcutsModal.svelte';
import { getDocs } from '$lib/apis/documents';
+ import { getAllChatTags } from '$lib/apis/chats';
let ollamaVersion = '';
let loaded = false;
@@ -106,6 +108,7 @@
await modelfiles.set(await getModelfiles(localStorage.token));
await prompts.set(await getPrompts(localStorage.token));
await documents.set(await getDocs(localStorage.token));
+ await tags.set(await getAllChatTags(localStorage.token));
modelfiles.subscribe(async () => {
// should fetch models
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte
index 93b50a32d..9507579c6 100644
--- a/src/routes/(app)/+page.svelte
+++ b/src/routes/(app)/+page.svelte
@@ -6,11 +6,28 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
- import { models, modelfiles, user, settings, chats, chatId, config } from '$lib/stores';
+ import {
+ models,
+ modelfiles,
+ user,
+ settings,
+ chats,
+ chatId,
+ config,
+ tags as _tags
+ } from '$lib/stores';
import { copyToClipboard, splitStream } from '$lib/utils';
import { generateChatCompletion, cancelChatCompletion, generateTitle } from '$lib/apis/ollama';
- import { createNewChat, getChatList, updateChatById } from '$lib/apis/chats';
+ import {
+ addTagById,
+ createNewChat,
+ deleteTagById,
+ getAllChatTags,
+ getChatList,
+ getTagsById,
+ updateChatById
+ } from '$lib/apis/chats';
import { queryVectorDB } from '$lib/apis/rag';
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
@@ -47,6 +64,7 @@
}, {});
let chat = null;
+ let tags = [];
let title = '';
let prompt = '';
@@ -181,6 +199,7 @@
},
messages: messages,
history: history,
+ tags: [],
timestamp: Date.now()
});
await chats.set(await getChatList(localStorage.token));
@@ -673,6 +692,34 @@
}
};
+ const getTags = async () => {
+ return await getTagsById(localStorage.token, $chatId).catch(async (error) => {
+ return [];
+ });
+ };
+
+ const addTag = async (tagName) => {
+ const res = await addTagById(localStorage.token, $chatId, tagName);
+ tags = await getTags();
+
+ chat = await updateChatById(localStorage.token, $chatId, {
+ tags: tags
+ });
+
+ _tags.set(await getAllChatTags(localStorage.token));
+ };
+
+ const deleteTag = async (tagName) => {
+ const res = await deleteTagById(localStorage.token, $chatId, tagName);
+ tags = await getTags();
+
+ chat = await updateChatById(localStorage.token, $chatId, {
+ tags: tags
+ });
+
+ _tags.set(await getAllChatTags(localStorage.token));
+ };
+
const setChatTitle = async (_chatId, _title) => {
if (_chatId === $chatId) {
title = _title;
@@ -691,7 +738,7 @@
}}
/>
-
0} {initNewChat} />
+ 0} {initNewChat} {tags} {addTag} {deleteTag} />
diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte
index 412c332ef..206b73989 100644
--- a/src/routes/(app)/c/[id]/+page.svelte
+++ b/src/routes/(app)/c/[id]/+page.svelte
@@ -6,11 +6,29 @@
import { goto } from '$app/navigation';
import { page } from '$app/stores';
- import { models, modelfiles, user, settings, chats, chatId, config } from '$lib/stores';
+ import {
+ models,
+ modelfiles,
+ user,
+ settings,
+ chats,
+ chatId,
+ config,
+ tags as _tags
+ } from '$lib/stores';
import { copyToClipboard, splitStream, convertMessagesToHistory } from '$lib/utils';
import { generateChatCompletion, generateTitle } from '$lib/apis/ollama';
- import { createNewChat, getChatById, getChatList, updateChatById } from '$lib/apis/chats';
+ import {
+ addTagById,
+ createNewChat,
+ deleteTagById,
+ getAllChatTags,
+ getChatById,
+ getChatList,
+ getTagsById,
+ updateChatById
+ } from '$lib/apis/chats';
import { queryVectorDB } from '$lib/apis/rag';
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
@@ -49,6 +67,7 @@
}, {});
let chat = null;
+ let tags = [];
let title = '';
let prompt = '';
@@ -97,6 +116,7 @@
});
if (chat) {
+ tags = await getTags();
const chatContent = chat.chat;
if (chatContent) {
@@ -688,6 +708,34 @@
await chats.set(await getChatList(localStorage.token));
};
+ const getTags = async () => {
+ return await getTagsById(localStorage.token, $chatId).catch(async (error) => {
+ return [];
+ });
+ };
+
+ const addTag = async (tagName) => {
+ const res = await addTagById(localStorage.token, $chatId, tagName);
+ tags = await getTags();
+
+ chat = await updateChatById(localStorage.token, $chatId, {
+ tags: tags
+ });
+
+ _tags.set(await getAllChatTags(localStorage.token));
+ };
+
+ const deleteTag = async (tagName) => {
+ const res = await deleteTagById(localStorage.token, $chatId, tagName);
+ tags = await getTags();
+
+ chat = await updateChatById(localStorage.token, $chatId, {
+ tags: tags
+ });
+
+ _tags.set(await getAllChatTags(localStorage.token));
+ };
+
onMount(async () => {
if (!($settings.saveChatHistory ?? true)) {
await goto('/');
@@ -713,6 +761,9 @@
goto('/');
}}
+ {tags}
+ {addTag}
+ {deleteTag}
/>