Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
7071716f
Unverified
Commit
7071716f
authored
Jan 06, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Jan 06, 2024
Browse files
Merge pull request #408 from ollama-webui/main
rag
parents
b050013c
c55c8728
Changes
56
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
1180 additions
and
988 deletions
+1180
-988
src/lib/components/admin/EditUserModal.svelte
src/lib/components/admin/EditUserModal.svelte
+172
-0
src/lib/components/chat/MessageInput/Suggestions.svelte
src/lib/components/chat/MessageInput/Suggestions.svelte
+4
-2
src/lib/components/chat/Messages/Placeholder.svelte
src/lib/components/chat/Messages/Placeholder.svelte
+1
-1
src/lib/components/chat/SettingsModal.svelte
src/lib/components/chat/SettingsModal.svelte
+243
-270
src/lib/components/common/Modal.svelte
src/lib/components/common/Modal.svelte
+13
-1
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+280
-231
src/lib/constants.ts
src/lib/constants.ts
+4
-10
src/lib/utils/index.ts
src/lib/utils/index.ts
+2
-2
src/routes/(app)/+layout.svelte
src/routes/(app)/+layout.svelte
+13
-21
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+202
-214
src/routes/(app)/admin/+page.svelte
src/routes/(app)/admin/+page.svelte
+48
-1
src/routes/(app)/c/[id]/+page.svelte
src/routes/(app)/c/[id]/+page.svelte
+179
-198
src/routes/(app)/modelfiles/+page.svelte
src/routes/(app)/modelfiles/+page.svelte
+1
-6
src/routes/(app)/modelfiles/create/+page.svelte
src/routes/(app)/modelfiles/create/+page.svelte
+2
-8
src/routes/(app)/modelfiles/edit/+page.svelte
src/routes/(app)/modelfiles/edit/+page.svelte
+1
-8
static/manifest.json
static/manifest.json
+15
-15
No files found.
src/lib/components/admin/EditUserModal.svelte
0 → 100644
View file @
7071716f
<script lang="ts">
import toast from 'svelte-french-toast';
import dayjs from 'dayjs';
import { createEventDispatcher } from 'svelte';
import { onMount } from 'svelte';
import { updateUserById } from '$lib/apis/users';
import Modal from '../common/Modal.svelte';
const dispatch = createEventDispatcher();
export let show = false;
export let selectedUser;
export let sessionUser;
let _user = {
profile_image_url: '',
name: '',
email: '',
password: ''
};
const submitHandler = async () => {
const res = await updateUserById(localStorage.token, selectedUser.id, _user).catch((error) => {
toast.error(error);
});
if (res) {
dispatch('save');
show = false;
}
};
onMount(() => {
if (selectedUser) {
_user = selectedUser;
_user.password = '';
}
});
</script>
<Modal size="sm" bind:show>
<div>
<div class=" flex justify-between dark:text-gray-300 px-5 py-4">
<div class=" text-lg font-medium self-center">Edit User</div>
<button
class="self-center"
on:click={() => {
show = false;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-5 h-5"
>
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
/>
</svg>
</button>
</div>
<hr class=" dark:border-gray-800" />
<div class="flex flex-col md:flex-row w-full p-5 md:space-x-4 dark:text-gray-200">
<div class=" flex flex-col w-full sm:flex-row sm:justify-center sm:space-x-6">
<form
class="flex flex-col w-full"
on:submit|preventDefault={() => {
submitHandler();
}}
>
<div class=" flex items-center rounded-md py-2 px-4 w-full">
<div class=" self-center mr-5">
<img
src={selectedUser.profile_image_url}
class=" max-w-[55px] object-cover rounded-full"
alt="User profile"
/>
</div>
<div>
<div class=" self-center capitalize font-semibold">{selectedUser.name}</div>
<div class="text-xs text-gray-500">
Created at {dayjs(selectedUser.timestamp * 1000).format('MMMM DD, YYYY')}
</div>
</div>
</div>
<hr class=" dark:border-gray-800 my-3 w-full" />
<div class=" flex flex-col space-y-1.5">
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">Email</div>
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 disabled:text-gray-500 dark:disabled:text-gray-500 outline-none"
type="email"
bind:value={_user.email}
autocomplete="off"
required
disabled={_user.id == sessionUser.id}
/>
</div>
</div>
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">Name</div>
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
type="text"
bind:value={_user.name}
autocomplete="off"
required
/>
</div>
</div>
<div class="flex flex-col w-full">
<div class=" mb-1 text-xs text-gray-500">New Password</div>
<div class="flex-1">
<input
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
type="password"
bind:value={_user.password}
autocomplete="new-password"
/>
</div>
</div>
</div>
<div class="flex justify-end pt-3 text-sm font-medium">
<button
class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
type="submit"
>
Save
</button>
</div>
</form>
</div>
</div>
</div>
</Modal>
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}
.tabs::-webkit-scrollbar {
display: none; /* for Chrome, Safari and Opera */
}
.tabs {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
input[type='number'] {
-moz-appearance: textfield; /* Firefox */
}
</style>
src/lib/components/chat/MessageInput/Suggestions.svelte
View file @
7071716f
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
{#each suggestionPrompts as prompt, promptIdx}
{#each suggestionPrompts as prompt, promptIdx}
<div class="{promptIdx > 1 ? 'hidden sm:inline-flex' : ''} basis-full sm:basis-1/2 p-[5px]">
<div class="{promptIdx > 1 ? 'hidden sm:inline-flex' : ''} basis-full sm:basis-1/2 p-[5px]">
<button
<button
class=" flex-1 flex justify-between w-full px-4 py-2.5 bg-white hover:bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-700 outline outline-1 outline-gray-200 dark:outline-gray-600 rounded-lg transition group"
class=" flex-1 flex justify-between w-full
h-full
px-4 py-2.5 bg-white hover:bg-gray-50 dark:bg-gray-800 dark:hover:bg-gray-700 outline outline-1 outline-gray-200 dark:outline-gray-600 rounded-lg transition group"
on:click={() => {
on:click={() => {
submitPrompt(prompt.content);
submitPrompt(prompt.content);
}}
}}
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
<div class="text-sm font-medium dark:text-gray-300">{prompt.title[0]}</div>
<div class="text-sm font-medium dark:text-gray-300">{prompt.title[0]}</div>
<div class="text-sm text-gray-500">{prompt.title[1]}</div>
<div class="text-sm text-gray-500">{prompt.title[1]}</div>
{:else}
{:else}
<div class=" self-center text-sm font-medium dark:text-gray-300">{prompt.content}</div>
<div class=" self-center text-sm font-medium dark:text-gray-300 line-clamp-2">
{prompt.content}
</div>
{/if}
{/if}
</div>
</div>
...
...
src/lib/components/chat/Messages/Placeholder.svelte
View file @
7071716f
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
>
>
{#if model in modelfiles}
{#if model in modelfiles}
<img
<img
src={modelfiles[model]?.imageUrl}
src={modelfiles[model]?.imageUrl
?? '/ollama-dark.png'
}
alt="modelfile"
alt="modelfile"
class=" w-20 mb-2 rounded-full {models.length > 1
class=" w-20 mb-2 rounded-full {models.length > 1
? ' border-[5px] border-white dark:border-gray-800'
? ' border-[5px] border-white dark:border-gray-800'
...
...
src/lib/components/chat/SettingsModal.svelte
View file @
7071716f
This diff is collapsed.
Click to expand it.
src/lib/components/common/Modal.svelte
View file @
7071716f
...
@@ -3,8 +3,18 @@
...
@@ -3,8 +3,18 @@
import { fade, blur } from 'svelte/transition';
import { fade, blur } from 'svelte/transition';
export let show = true;
export let show = true;
export let size = 'md';
let mounted = false;
let mounted = false;
const sizeToWidth = (size) => {
if (size === 'sm') {
return 'w-[30rem]';
} else {
return 'w-[40rem]';
}
};
onMount(() => {
onMount(() => {
mounted = true;
mounted = true;
});
});
...
@@ -28,7 +38,9 @@
...
@@ -28,7 +38,9 @@
}}
}}
>
>
<div
<div
class="m-auto rounded-xl max-w-full w-[40rem] mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl"
class="m-auto rounded-xl max-w-full {sizeToWidth(
size
)} mx-2 bg-gray-50 dark:bg-gray-900 shadow-3xl"
transition:fade={{ delay: 100, duration: 200 }}
transition:fade={{ delay: 100, duration: 200 }}
on:click={(e) => {
on:click={(e) => {
e.stopPropagation();
e.stopPropagation();
...
...
src/lib/components/layout/Sidebar.svelte
View file @
7071716f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
import { goto, invalidateAll } from '$app/navigation';
import { goto, invalidateAll } from '$app/navigation';
import { page } from '$app/stores';
import { page } from '$app/stores';
import { user, chats, showSettings, chatId } from '$lib/stores';
import { user, chats,
settings,
showSettings, chatId } from '$lib/stores';
import { onMount } from 'svelte';
import { onMount } from 'svelte';
import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats';
import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats';
...
@@ -49,6 +49,12 @@
...
@@ -49,6 +49,12 @@
await deleteChatById(localStorage.token, id);
await deleteChatById(localStorage.token, id);
await chats.set(await getChatList(localStorage.token));
await chats.set(await getChatList(localStorage.token));
};
};
const saveSettings = async (updated) => {
await settings.set({ ...$settings, ...updated });
localStorage.setItem('settings', JSON.stringify($settings));
location.href = '/';
};
</script>
</script>
<div
<div
...
@@ -159,253 +165,296 @@
...
@@ -159,253 +165,296 @@
</div>
</div>
{/if}
{/if}
<div class="px-2.5 mt-1 mb-2 flex justify-center space-x-2">
<div class="relative flex flex-col flex-1 overflow-y-auto">
<div class="flex w-full" id="chat-search">
{#if !($settings.saveChatHistory ?? true)}
<div class="self-center pl-3 py-2 rounded-l bg-gray-950">
<div class="absolute z-40 w-full h-full bg-black/90 flex justify-center">
<svg
<div class=" text-left px-5 py-2">
xmlns="http://www.w3.org/2000/svg"
<div class=" font-medium">Chat History is off for this browser.</div>
viewBox="0 0 20 20"
<div class="text-xs mt-2">
fill="currentColor"
When history is turned off, new chats on this browser won't appear in your history on
class="w-4 h-4"
any of your devices. <span class=" font-semibold"
>
>This setting does not sync across browsers or devices.</span
<path
>
fill-rule="evenodd"
</div>
d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
clip-rule="evenodd"
<div class="mt-3">
/>
<button
</svg>
class="flex justify-center items-center space-x-1.5 px-3 py-2.5 rounded-lg text-xs bg-gray-200 hover:bg-gray-300 transition text-gray-800 font-medium w-full"
type="button"
on:click={() => {
saveSettings({
saveChatHistory: true
});
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-3 h-3"
>
<path
fill-rule="evenodd"
d="M8 1a.75.75 0 0 1 .75.75v6.5a.75.75 0 0 1-1.5 0v-6.5A.75.75 0 0 1 8 1ZM4.11 3.05a.75.75 0 0 1 0 1.06 5.5 5.5 0 1 0 7.78 0 .75.75 0 0 1 1.06-1.06 7 7 0 1 1-9.9 0 .75.75 0 0 1 1.06 0Z"
clip-rule="evenodd"
/>
</svg>
<div>Enable Chat History</div>
</button>
</div>
</div>
</div>
</div>
{/if}
<input
<div class="px-2.5 mt-1 mb-2 flex justify-center space-x-2">
class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none"
<div class="flex w-full" id="chat-search">
placeholder="Search"
<div class="self-center pl-3 py-2 rounded-l bg-gray-950">
bind:value={search}
<svg
/>
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
clip-rule="evenodd"
/>
</svg>
</div>
<!-- <div class="self-center pr-3 py-2 bg-gray-900">
<input
<svg
class="w-full rounded-r py-1.5 pl-2.5 pr-4 text-sm text-gray-300 bg-gray-950 outline-none"
xmlns="http://www.w3.org/2000/svg"
placeholder="Search"
fill="none"
bind:value={search}
viewBox="0 0 24 24"
/>
stroke-width="1.5"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 01-.659 1.591l-5.432 5.432a2.25 2.25 0 00-.659 1.591v2.927a2.25 2.25 0 01-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 00-.659-1.591L3.659 7.409A2.25 2.25 0 013 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0112 3z"
/>
</svg>
</div> -->
</div>
</div>
<div class="pl-2.5 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto">
<!-- <div class="self-center pr-3 py-2 bg-gray-900">
{#each $chats.filter((chat) => {
<svg
if (search === '') {
xmlns="http://www.w3.org/2000/svg"
return true;
fill="none"
} else {
viewBox="0 0 24 24"
let title = chat.title.toLowerCase();
stroke-width="1.5"
stroke="currentColor"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 3c2.755 0 5.455.232 8.083.678.533.09.917.556.917 1.096v1.044a2.25 2.25 0 01-.659 1.591l-5.432 5.432a2.25 2.25 0 00-.659 1.591v2.927a2.25 2.25 0 01-1.244 2.013L9.75 21v-6.568a2.25 2.25 0 00-.659-1.591L3.659 7.409A2.25 2.25 0 013 5.818V4.774c0-.54.384-1.006.917-1.096A48.32 48.32 0 0112 3z"
/>
</svg>
</div> -->
</div>
</div>
if (title.includes(search)) {
<div class="pl-2.5 my-2 flex-1 flex flex-col space-y-1 overflow-y-auto">
{#each $chats.filter((chat) => {
if (search === '') {
return true;
return true;
} else {
} else {
return false;
let title = chat.title.toLowerCase();
if (title.includes(search)) {
return true;
} else {
return false;
}
}
}
}
}) as chat, i}
}) as chat, i}
<div class=" w-full pr-2 relative">
<div class=" w-full pr-2 relative">
<button
<button
class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id ===
class=" w-full flex justify-between rounded-md px-3 py-2 hover:bg-gray-900 {chat.id ===
$chatId
$chatId
? 'bg-gray-900'
? 'bg-gray-900'
: ''} transition whitespace-nowrap text-ellipsis"
: ''} transition whitespace-nowrap text-ellipsis"
on:click={() => {
on:click={() => {
// goto(`/c/${chat.id}`);
// goto(`/c/${chat.id}`);
if (chat.id !== chatTitleEditId) {
if (chat.id !== chatTitleEditId) {
chatTitleEditId = null;
chatTitleEditId = null;
chatTitle = '';
chatTitle = '';
}
}
if (chat.id !== $chatId) {
if (chat.id !== $chatId) {
loadChat(chat.id);
loadChat(chat.id);
}
}
}}
}}
>
>
<div class=" flex self-center flex-1">
<div class=" flex self-center flex-1">
<div class=" self-center mr-3">
<div class=" self-center mr-3">
<svg
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
fill="none"
fill="none"
viewBox="0 0 24 24"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke-width="1.5"
stroke="currentColor"
stroke="currentColor"
class="w-4 h-4"
class="w-4 h-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.087.16 2.185.283 3.293.369V21l4.076-4.076a1.526 1.526 0 011.037-.443 48.282 48.282 0 005.68-.494c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"
/>
</svg>
</div>
<div
class=" text-left self-center overflow-hidden {chat.id === $chatId
? 'w-[120px]'
: 'w-[180px]'} "
>
>
<path
{#if chatTitleEditId === chat.id}
stroke-linecap="round"
<input bind:value={chatTitle} class=" bg-transparent w-full" />
stroke-linejoin="round"
{:else}
d="M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.087.16 2.185.283 3.293.369V21l4.076-4.076a1.526 1.526 0 011.037-.443 48.282 48.282 0 005.68-.494c1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"
{chat.title}
/>
{/if}
</svg>
</div>
</div>
<div
class=" text-left self-center overflow-hidden {chat.id === $chatId
? 'w-[120px]'
: 'w-[180px]'} "
>
{#if chatTitleEditId === chat.id}
<input bind:value={chatTitle} class=" bg-transparent w-full" />
{:else}
{chat.title}
{/if}
</div>
</div>
</div>
</button>
</button>
{#if chat.id === $chatId}
{#if chat.id === $chatId}
<div class=" absolute right-[22px] top-[10px]">
<div class=" absolute right-[22px] top-[10px]">
{#if chatTitleEditId === chat.id}
{#if chatTitleEditId === chat.id}
<div class="flex self-center space-x-1.5">
<div class="flex self-center space-x-1.5">
<button
<button
class=" self-center hover:text-white transition"
class=" self-center hover:text-white transition"
on:click={() => {
on:click={() => {
editChatTitle(chat.id, chatTitle);
editChatTitle(chat.id, chatTitle);
chatTitleEditId = null;
chatTitleEditId = null;
chatTitle = '';
chatTitle = '';
}}
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
>
<
path
<
svg
fill-rule="evenodd
"
xmlns="http://www.w3.org/2000/svg
"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z
"
viewBox="0 0 20 20
"
clip-rule="evenodd
"
fill="currentColor
"
/>
class="w-4 h-4"
</svg
>
>
</button>
<path
<button
fill-rule="evenodd"
class=" self-center hover:text-white transition
"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z
"
on:click={() => {
clip-rule="evenodd"
chatTitleEditId = null;
/>
chatTitle = '';
</svg>
}}
</button>
>
<button
<svg
class=" self-center hover:text-white transition"
xmlns="http://www.w3.org/2000/svg"
on:click={() => {
viewBox="0 0 20 20"
chatTitleEditId = null;
fill="currentColor"
chatTitle = '';
class="w-4 h-4"
}}
>
>
<
path
<
svg
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z
"
xmlns="http://www.w3.org/2000/svg
"
/>
viewBox="0 0 20 20"
</svg>
fill="currentColor"
</button>
class="w-4 h-4"
</div
>
>
{:else if chatDeleteId === chat.id}
<path
<div class="flex self-center space-x-1.5">
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
<button
/>
class=" self-center hover:text-white transition"
</svg>
on:click={() => {
</button>
deleteChat(chat.id);
</div>
}
}
{:else if chatDeleteId === chat.id
}
>
<div class="flex self-center space-x-1.5"
>
<
svg
<
button
xmlns="http://www.w3.org/2000/svg
"
class=" self-center hover:text-white transition
"
viewBox="0 0 20 20"
on:click={() => {
fill="currentColor"
deleteChat(chat.id);
class="w-4 h-4"
}}
>
>
<
path
<
svg
fill-rule="evenodd
"
xmlns="http://www.w3.org/2000/svg
"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z
"
viewBox="0 0 20 20
"
clip-rule="evenodd
"
fill="currentColor
"
/>
class="w-4 h-4"
</svg
>
>
</button>
<path
<button
fill-rule="evenodd"
class=" self-center hover:text-white transition
"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z
"
on:click={() => {
clip-rule="evenodd"
chatDeleteId = null;
/>
}}
</svg>
>
</button
>
<
svg
<
button
xmlns="http://www.w3.org/2000/svg
"
class=" self-center hover:text-white transition
"
viewBox="0 0 20 20"
on:click={() => {
fill="currentColor"
chatDeleteId = null;
class="w-4 h-4"
}}
>
>
<path
<svg
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
xmlns="http://www.w3.org/2000/svg"
/>
viewBox="0 0 20 20"
</svg>
fill="currentColor"
</button>
class="w-4 h-4"
</div>
>
{:else}
<path
<div class="flex self-center space-x-1.5">
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
<button
/>
id="delete-chat-button"
</svg>
class=" hidden"
</button>
on:click={() => {
</div>
deleteChat(chat.id);
{:else}
}}
<div class="flex self-center space-x-1.5">
/>
<button
<button
id="delete-chat-button"
class=" self-center hover:text-white transition"
class=" hidden"
on:click={() => {
on:click={() => {
chatTitle = chat.title;
deleteChat(chat.id);
chatTitleEditId = chat.id;
}}
// editChatTitle(chat.id, 'a');
/>
}}
<button
>
class=" self-center hover:text-white transition"
<svg
on:click={() => {
xmlns="http://www.w3.org/2000/svg"
chatTitle = chat.title;
fill="none"
chatTitleEditId = chat.id;
viewBox="0 0 24 24"
// editChatTitle(chat.id, 'a');
stroke-width="1.5"
}}
stroke="currentColor"
class="w-4 h-4"
>
>
<
path
<
svg
stroke-linecap="round
"
xmlns="http://www.w3.org/2000/svg
"
stroke-linejoin="round
"
fill="none
"
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125
"
viewBox="0 0 24 24
"
/>
stroke-width="1.5"
</svg>
stroke="currentColor"
</button>
class="w-4 h-4"
<button
>
class=" self-center hover:text-white transition"
<path
on:click={() => {
stroke-linecap="round"
chatDeleteId = chat.id;
stroke-linejoin="round"
}}
d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
>
/
>
<
svg
</
svg
>
xmlns="http://www.w3.org/2000/svg"
</button>
fill="none"
<button
viewBox="0 0 24 24
"
class=" self-center hover:text-white transition
"
stroke-width="1.5"
on:click={() => {
stroke="currentColor"
chatDeleteId = chat.id;
class="w-4 h-4"
}}
>
>
<path
<svg
stroke-linecap="round"
xmlns="http://www.w3.org/2000/svg"
stroke-linejoin="round"
fill="none"
d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
viewBox="0 0 24 24"
/>
stroke-width="1.5"
</svg>
stroke="currentColor"
</button>
class="w-4 h-4"
</div>
>
{/if}
<path
</div>
stroke-linecap="round"
{/if}
stroke-linejoin="round"
</div>
d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
{/each}
/>
</svg>
</button>
</div>
{/if}
</div>
{/if}
</div>
{/each}
</div>
</div>
</div>
<div class="px-2.5">
<div class="px-2.5">
...
...
src/lib/constants.ts
View file @
7071716f
import
{
dev
,
browser
}
from
'
$app/environment
'
;
import
{
dev
}
from
'
$app/environment
'
;
import
{
PUBLIC_API_BASE_URL
}
from
'
$env/static/public
'
;
export
const
OLLAMA_API_BASE_URL
=
dev
?
`http://
${
location
.
hostname
}
:8080/ollama/api`
:
PUBLIC_API_BASE_URL
===
''
?
browser
?
`http://
${
location
.
hostname
}
:11434/api`
:
`http://localhost:11434/api`
:
PUBLIC_API_BASE_URL
;
export
const
WEBUI_BASE_URL
=
dev
?
`http://
${
location
.
hostname
}
:8080`
:
``
;
export
const
WEBUI_BASE_URL
=
dev
?
`http://
${
location
.
hostname
}
:8080`
:
``
;
export
const
WEBUI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/api/v1`
;
export
const
WEBUI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/api/v1`
;
export
const
OLLAMA_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/ollama/api`
;
export
const
OPENAI_API_BASE_URL
=
`
${
WEBUI_BASE_URL
}
/openai/api`
;
export
const
WEB_UI_VERSION
=
'
v1.0.0-alpha-static
'
;
export
const
WEB_UI_VERSION
=
'
v1.0.0-alpha-static
'
;
...
...
src/lib/utils/index.ts
View file @
7071716f
...
@@ -21,7 +21,7 @@ export const splitStream = (splitOn) => {
...
@@ -21,7 +21,7 @@ export const splitStream = (splitOn) => {
};
};
export
const
convertMessagesToHistory
=
(
messages
)
=>
{
export
const
convertMessagesToHistory
=
(
messages
)
=>
{
le
t
history
=
{
cons
t
history
=
{
messages
:
{},
messages
:
{},
currentId
:
null
currentId
:
null
};
};
...
@@ -114,7 +114,7 @@ export const checkVersion = (required, current) => {
...
@@ -114,7 +114,7 @@ export const checkVersion = (required, current) => {
export
const
findWordIndices
=
(
text
)
=>
{
export
const
findWordIndices
=
(
text
)
=>
{
const
regex
=
/
\[([^\]]
+
)\]
/g
;
const
regex
=
/
\[([^\]]
+
)\]
/g
;
le
t
matches
=
[];
cons
t
matches
=
[];
let
match
;
let
match
;
while
((
match
=
regex
.
exec
(
text
))
!==
null
)
{
while
((
match
=
regex
.
exec
(
text
))
!==
null
)
{
...
...
src/routes/(app)/+layout.svelte
View file @
7071716f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
import { getOpenAIModels } from '$lib/apis/openai';
import { getOpenAIModels } from '$lib/apis/openai';
import { user, showSettings, settings, models, modelfiles, prompts } from '$lib/stores';
import { user, showSettings, settings, models, modelfiles, prompts } from '$lib/stores';
import {
OLLAMA_API_BASE_URL,
REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import { REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
import Sidebar from '$lib/components/layout/Sidebar.svelte';
import Sidebar from '$lib/components/layout/Sidebar.svelte';
...
@@ -32,36 +32,28 @@
...
@@ -32,36 +32,28 @@
const getModels = async () => {
const getModels = async () => {
let models = [];
let models = [];
models.push(
models.push(
...(await getOllamaModels(
...(await getOllamaModels(localStorage.token).catch((error) => {
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token
).catch((error) => {
toast.error(error);
toast.error(error);
return [];
return [];
}))
}))
);
);
// If OpenAI API Key exists
if ($settings.OPENAI_API_KEY) {
const openAIModels = await getOpenAIModels(
$settings.OPENAI_API_BASE_URL ?? 'https://api.openai.com/v1',
$settings.OPENAI_API_KEY
).catch((error) => {
console.log(error);
toast.error(error);
return null;
});
models.push(...(openAIModels ? [{ name: 'hr' }, ...openAIModels] : []));
// $settings.OPENAI_API_BASE_URL ?? 'https://api.openai.com/v1',
}
// $settings.OPENAI_API_KEY
const openAIModels = await getOpenAIModels(localStorage.token).catch((error) => {
console.log(error);
return null;
});
models.push(...(openAIModels ? [{ name: 'hr' }, ...openAIModels] : []));
return models;
return models;
};
};
const setOllamaVersion = async (version: string = '') => {
const setOllamaVersion = async (version: string = '') => {
if (version === '') {
if (version === '') {
version = await getOllamaVersion(
version = await getOllamaVersion(localStorage.token).catch((error) => {
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token
).catch((error) => {
return '';
return '';
});
});
}
}
...
...
src/routes/(app)/+page.svelte
View file @
7071716f
...
@@ -7,7 +7,6 @@
...
@@ -7,7 +7,6 @@
import { page } from '$app/stores';
import { page } from '$app/stores';
import { models, modelfiles, user, settings, chats, chatId, config } from '$lib/stores';
import { models, modelfiles, user, settings, chats, chatId, config } from '$lib/stores';
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { generateChatCompletion, generateTitle } from '$lib/apis/ollama';
import { generateChatCompletion, generateTitle } from '$lib/apis/ollama';
import { copyToClipboard, splitStream } from '$lib/utils';
import { copyToClipboard, splitStream } from '$lib/utils';
...
@@ -17,6 +16,7 @@
...
@@ -17,6 +16,7 @@
import ModelSelector from '$lib/components/chat/ModelSelector.svelte';
import ModelSelector from '$lib/components/chat/ModelSelector.svelte';
import Navbar from '$lib/components/layout/Navbar.svelte';
import Navbar from '$lib/components/layout/Navbar.svelte';
import { createNewChat, getChatList, updateChatById } from '$lib/apis/chats';
import { createNewChat, getChatList, updateChatById } from '$lib/apis/chats';
import { generateOpenAIChatCompletion } from '$lib/apis/openai';
let stopResponseFlag = false;
let stopResponseFlag = false;
let autoScroll = true;
let autoScroll = true;
...
@@ -163,36 +163,32 @@
...
@@ -163,36 +163,32 @@
// Scroll down
// Scroll down
window.scrollTo({ top: document.body.scrollHeight });
window.scrollTo({ top: document.body.scrollHeight });
const res = await generateChatCompletion(
const res = await generateChatCompletion(localStorage.token, {
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
model: model,
localStorage.token,
messages: [
{
$settings.system
model: model,
? {
messages: [
role: 'system',
$settings.system
content: $settings.system
? {
}
role: 'system',
: undefined,
content: $settings.system
...messages
}
]
: undefined,
.filter((message) => message)
...messages
.map((message) => ({
]
role: message.role,
.filter((message) => message)
content: message.content,
.map((message) => ({
...(message.files && {
role: message.role,
images: message.files
content: message.content,
.filter((file) => file.type === 'image')
...(message.files && {
.map((file) => file.url.slice(file.url.indexOf(',') + 1))
images: message.files
})
.filter((file) => file.type === 'image')
})),
.map((file) => file.url.slice(file.url.indexOf(',') + 1))
options: {
})
...($settings.options ?? {})
})),
},
options: {
format: $settings.requestFormat ?? undefined
...($settings.options ?? {})
});
},
format: $settings.requestFormat ?? undefined
}
);
if (res && res.ok) {
if (res && res.ok) {
const reader = res.body
const reader = res.body
...
@@ -284,11 +280,13 @@
...
@@ -284,11 +280,13 @@
}
}
if ($chatId == _chatId) {
if ($chatId == _chatId) {
chat = await updateChatById(localStorage.token, _chatId, {
if ($settings.saveChatHistory ?? true) {
messages: messages,
chat = await updateChatById(localStorage.token, _chatId, {
history: history
messages: messages,
});
history: history
await chats.set(await getChatList(localStorage.token));
});
await chats.set(await getChatList(localStorage.token));
}
}
}
} else {
} else {
if (res !== null) {
if (res !== null) {
...
@@ -326,188 +324,173 @@
...
@@ -326,188 +324,173 @@
};
};
const sendPromptOpenAI = async (model, userPrompt, parentId, _chatId) => {
const sendPromptOpenAI = async (model, userPrompt, parentId, _chatId) => {
if ($settings.OPENAI_API_KEY) {
let responseMessageId = uuidv4();
if (models) {
let responseMessageId = uuidv4();
let responseMessage = {
parentId: parentId,
id: responseMessageId,
childrenIds: [],
role: 'assistant',
content: '',
model: model
};
history.messages[responseMessageId] = responseMessage;
history.currentId = responseMessageId;
if (parentId !== null) {
history.messages[parentId].childrenIds = [
...history.messages[parentId].childrenIds,
responseMessageId
];
}
window.scrollTo({ top: document.body.scrollHeight });
let responseMessage = {
parentId: parentId,
id: responseMessageId,
childrenIds: [],
role: 'assistant',
content: '',
model: model
};
const res = await fetch(
history.messages[responseMessageId] = responseMessage;
`${$settings.OPENAI_API_BASE_URL ?? 'https://api.openai.com/v1'}/chat/completions`,
history.currentId = responseMessageId;
{
if (parentId !== null) {
method: 'POST',
history.messages[parentId].childrenIds = [
headers: {
...history.messages[parentId].childrenIds,
Authorization: `Bearer ${$settings.OPENAI_API_KEY}`,
responseMessageId
'Content-Type': 'application/json'
];
},
}
body: JSON.stringify({
model: model,
stream: true,
messages: [
$settings.system
? {
role: 'system',
content: $settings.system
}
: undefined,
...messages
]
.filter((message) => message)
.map((message) => ({
role: message.role,
...(message.files
? {
content: [
{
type: 'text',
text: message.content
},
...message.files
.filter((file) => file.type === 'image')
.map((file) => ({
type: 'image_url',
image_url: {
url: file.url
}
}))
]
}
: { content: message.content })
})),
seed: $settings?.options?.seed ?? undefined,
stop: $settings?.options?.stop ?? undefined,
temperature: $settings?.options?.temperature ?? undefined,
top_p: $settings?.options?.top_p ?? undefined,
num_ctx: $settings?.options?.num_ctx ?? undefined,
frequency_penalty: $settings?.options?.repeat_penalty ?? undefined,
max_tokens: $settings?.options?.num_predict ?? undefined
})
}
).catch((err) => {
console.log(err);
return null;
});
if (res && res.ok) {
const reader = res.body
.pipeThrough(new TextDecoderStream())
.pipeThrough(splitStream('\n'))
.getReader();
while (true) {
const { value, done } = await reader.read();
if (done || stopResponseFlag || _chatId !== $chatId) {
responseMessage.done = true;
messages = messages;
break;
}
try {
window.scrollTo({ top: document.body.scrollHeight });
let lines = value.split('\n');
for (const line of lines) {
if (line !== '') {
console.log(line);
if (line === 'data: [DONE]') {
responseMessage.done = true;
messages = messages;
} else {
let data = JSON.parse(line.replace(/^data: /, ''));
console.log(data);
if (responseMessage.content == '' && data.choices[0].delta.content == '\n') {
continue;
} else {
responseMessage.content += data.choices[0].delta.content ?? '';
messages = messages;
}
}
}
}
} catch (error) {
console.log(error);
}
if ($settings.notificationEnabled && !document.hasFocus()) {
const res = await generateOpenAIChatCompletion(localStorage.token, {
const notification = new Notification(`OpenAI ${model}`, {
model: model,
body: responseMessage.content,
stream: true,
icon: '/favicon.png'
messages: [
});
$settings.system
}
? {
role: 'system',
content: $settings.system
}
: undefined,
...messages
]
.filter((message) => message)
.map((message) => ({
role: message.role,
...(message.files
? {
content: [
{
type: 'text',
text: message.content
},
...message.files
.filter((file) => file.type === 'image')
.map((file) => ({
type: 'image_url',
image_url: {
url: file.url
}
}))
]
}
: { content: message.content })
})),
seed: $settings?.options?.seed ?? undefined,
stop: $settings?.options?.stop ?? undefined,
temperature: $settings?.options?.temperature ?? undefined,
top_p: $settings?.options?.top_p ?? undefined,
num_ctx: $settings?.options?.num_ctx ?? undefined,
frequency_penalty: $settings?.options?.repeat_penalty ?? undefined,
max_tokens: $settings?.options?.num_predict ?? undefined
});
if ($settings.responseAutoCopy) {
if (res && res.ok) {
copyToClipboard(responseMessage.content);
const reader = res.body
}
.pipeThrough(new TextDecoderStream())
.pipeThrough(splitStream('\n'))
.getReader();
if (autoScroll) {
while (true) {
window.scrollTo({ top: document.body.scrollHeight });
const { value, done } = await reader.read();
}
if (done || stopResponseFlag || _chatId !== $chatId) {
}
responseMessage.done = true;
messages = messages;
break;
}
if ($chatId == _chatId) {
try {
chat = await updateChatById(localStorage.token, _chatId, {
let lines = value.split('\n');
messages: messages,
history: history
for (const line of lines) {
});
if (line !== '') {
await chats.set(await getChatList(localStorage.token));
console.log(line);
}
if (line === 'data: [DONE]') {
} else {
responseMessage.done = true;
if (res !== null) {
messages = messages;
const error = await res.json();
console.log(error);
if ('detail' in error) {
toast.error(error.detail);
responseMessage.content = error.detail;
} else {
if ('message' in error.error) {
toast.error(error.error.message);
responseMessage.content = error.error.message;
} else {
} else {
toast.error(error.error);
let data = JSON.parse(line.replace(/^data: /, ''));
responseMessage.content = error.error;
console.log(data);
if (responseMessage.content == '' && data.choices[0].delta.content == '\n') {
continue;
} else {
responseMessage.content += data.choices[0].delta.content ?? '';
messages = messages;
}
}
}
}
}
} else {
toast.error(`Uh-oh! There was an issue connecting to ${model}.`);
responseMessage.content = `Uh-oh! There was an issue connecting to ${model}.`;
}
}
} catch (error) {
console.log(error);
}
responseMessage.error = true;
if ($settings.notificationEnabled && !document.hasFocus()) {
responseMessage.content = `Uh-oh! There was an issue connecting to ${model}.`;
const notification = new Notification(`OpenAI ${model}`, {
responseMessage.done = true;
body: responseMessage.content,
messages = messages;
icon: '/favicon.png'
});
}
}
stopResponseFlag = false;
if ($settings.responseAutoCopy) {
await tick();
copyToClipboard(responseMessage.content);
}
if (autoScroll) {
if (autoScroll) {
window.scrollTo({ top: document.body.scrollHeight });
window.scrollTo({ top: document.body.scrollHeight });
}
}
}
if (messages.length == 2) {
if ($chatId == _chatId) {
window.history.replaceState(history.state, '', `/c/${_chatId}`);
if ($settings.saveChatHistory ?? true) {
await setChatTitle(_chatId, userPrompt);
chat = await updateChatById(localStorage.token, _chatId, {
messages: messages,
history: history
});
await chats.set(await getChatList(localStorage.token));
}
}
}
}
} else {
if (res !== null) {
const error = await res.json();
console.log(error);
if ('detail' in error) {
toast.error(error.detail);
responseMessage.content = error.detail;
} else {
if ('message' in error.error) {
toast.error(error.error.message);
responseMessage.content = error.error.message;
} else {
toast.error(error.error);
responseMessage.content = error.error;
}
}
} else {
toast.error(`Uh-oh! There was an issue connecting to ${model}.`);
responseMessage.content = `Uh-oh! There was an issue connecting to ${model}.`;
}
responseMessage.error = true;
responseMessage.content = `Uh-oh! There was an issue connecting to ${model}.`;
responseMessage.done = true;
messages = messages;
}
stopResponseFlag = false;
await tick();
if (autoScroll) {
window.scrollTo({ top: document.body.scrollHeight });
}
if (messages.length == 2) {
window.history.replaceState(history.state, '', `/c/${_chatId}`);
await setChatTitle(_chatId, userPrompt);
}
}
};
};
...
@@ -548,20 +531,24 @@
...
@@ -548,20 +531,24 @@
// Create new chat if only one message in messages
// Create new chat if only one message in messages
if (messages.length == 1) {
if (messages.length == 1) {
chat = await createNewChat(localStorage.token, {
if ($settings.saveChatHistory ?? true) {
id: $chatId,
chat = await createNewChat(localStorage.token, {
title: 'New Chat',
id: $chatId,
models: selectedModels,
title: 'New Chat',
system: $settings.system ?? undefined,
models: selectedModels,
options: {
system: $settings.system ?? undefined,
...($settings.options ?? {})
options: {
},
...($settings.options ?? {})
messages: messages,
},
history: history,
messages: messages,
timestamp: Date.now()
history: history,
});
timestamp: Date.now()
await chats.set(await getChatList(localStorage.token));
});
await chatId.set(chat.id);
await chats.set(await getChatList(localStorage.token));
await chatId.set(chat.id);
} else {
await chatId.set('local');
}
await tick();
await tick();
}
}
...
@@ -595,7 +582,6 @@
...
@@ -595,7 +582,6 @@
const generateChatTitle = async (_chatId, userPrompt) => {
const generateChatTitle = async (_chatId, userPrompt) => {
if ($settings.titleAutoGenerate ?? true) {
if ($settings.titleAutoGenerate ?? true) {
const title = await generateTitle(
const title = await generateTitle(
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token,
localStorage.token,
$settings?.titleAutoGenerateModel ?? selectedModels[0],
$settings?.titleAutoGenerateModel ?? selectedModels[0],
userPrompt
userPrompt
...
@@ -614,8 +600,10 @@
...
@@ -614,8 +600,10 @@
title = _title;
title = _title;
}
}
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
if ($settings.saveChatHistory ?? true) {
await chats.set(await getChatList(localStorage.token));
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
await chats.set(await getChatList(localStorage.token));
}
};
};
</script>
</script>
...
...
src/routes/(app)/admin/+page.svelte
View file @
7071716f
...
@@ -8,11 +8,15 @@
...
@@ -8,11 +8,15 @@
import { updateUserRole, getUsers, deleteUserById } from '$lib/apis/users';
import { updateUserRole, getUsers, deleteUserById } from '$lib/apis/users';
import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths';
import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths';
import EditUserModal from '$lib/components/admin/EditUserModal.svelte';
let loaded = false;
let loaded = false;
let users = [];
let users = [];
let selectedUser = null;
let signUpEnabled = true;
let signUpEnabled = true;
let showEditUserModal = false;
const updateRoleHandler = async (id, role) => {
const updateRoleHandler = async (id, role) => {
const res = await updateUserRole(localStorage.token, id, role).catch((error) => {
const res = await updateUserRole(localStorage.token, id, role).catch((error) => {
...
@@ -25,6 +29,17 @@
...
@@ -25,6 +29,17 @@
}
}
};
};
const editUserPasswordHandler = async (id, password) => {
const res = await deleteUserById(localStorage.token, id).catch((error) => {
toast.error(error);
return null;
});
if (res) {
users = await getUsers(localStorage.token);
toast.success('Successfully updated');
}
};
const deleteUserHandler = async (id) => {
const deleteUserHandler = async (id) => {
const res = await deleteUserById(localStorage.token, id).catch((error) => {
const res = await deleteUserById(localStorage.token, id).catch((error) => {
toast.error(error);
toast.error(error);
...
@@ -51,6 +66,17 @@
...
@@ -51,6 +66,17 @@
});
});
</script>
</script>
{#key selectedUser}
<EditUserModal
bind:show={showEditUserModal}
{selectedUser}
sessionUser={$user}
on:save={async () => {
users = await getUsers(localStorage.token);
}}
/>
{/key}
<div
<div
class=" bg-white dark:bg-gray-800 dark:text-gray-100 min-h-screen w-full flex justify-center font-mona"
class=" bg-white dark:bg-gray-800 dark:text-gray-100 min-h-screen w-full flex justify-center font-mona"
>
>
...
@@ -154,7 +180,28 @@
...
@@ -154,7 +180,28 @@
}}>{user.role}</button
}}>{user.role}</button
>
>
</td>
</td>
<td class="px-6 py-4 text-center flex justify-center">
<td class="px-6 py-4 space-x-1 text-center flex justify-center">
<button
class="self-center w-fit text-sm p-1.5 border dark:border-gray-600 rounded-xl flex"
on:click={async () => {
showEditUserModal = !showEditUserModal;
selectedUser = user;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M11.013 2.513a1.75 1.75 0 0 1 2.475 2.474L6.226 12.25a2.751 2.751 0 0 1-.892.596l-2.047.848a.75.75 0 0 1-.98-.98l.848-2.047a2.75 2.75 0 0 1 .596-.892l7.262-7.261Z"
clip-rule="evenodd"
/>
</svg>
</button>
<button
<button
class="self-center w-fit text-sm p-1.5 border dark:border-gray-600 rounded-xl flex"
class="self-center w-fit text-sm p-1.5 border dark:border-gray-600 rounded-xl flex"
on:click={async () => {
on:click={async () => {
...
...
src/routes/(app)/c/[id]/+page.svelte
View file @
7071716f
This diff is collapsed.
Click to expand it.
src/routes/(app)/modelfiles/+page.svelte
View file @
7071716f
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
import { onMount } from 'svelte';
import { onMount } from 'svelte';
import { modelfiles, settings, user } from '$lib/stores';
import { modelfiles, settings, user } from '$lib/stores';
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { createModel, deleteModel } from '$lib/apis/ollama';
import { createModel, deleteModel } from '$lib/apis/ollama';
import {
import {
createNewModelfile,
createNewModelfile,
...
@@ -20,11 +19,7 @@
...
@@ -20,11 +19,7 @@
const deleteModelHandler = async (tagName) => {
const deleteModelHandler = async (tagName) => {
let success = null;
let success = null;
success = await deleteModel(
success = await deleteModel(localStorage.token, tagName);
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token,
tagName
);
if (success) {
if (success) {
toast.success(`Deleted ${tagName}`);
toast.success(`Deleted ${tagName}`);
...
...
src/routes/(app)/modelfiles/create/+page.svelte
View file @
7071716f
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-french-toast';
import { toast } from 'svelte-french-toast';
import { goto } from '$app/navigation';
import { goto } from '$app/navigation';
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { settings, user, config, modelfiles, models } from '$lib/stores';
import { settings, user, config, modelfiles, models } from '$lib/stores';
import Advanced from '$lib/components/chat/Settings/Advanced.svelte';
import Advanced from '$lib/components/chat/Settings/Advanced.svelte';
...
@@ -132,12 +131,7 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
...
@@ -132,12 +131,7 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
Object.keys(categories).filter((category) => categories[category]).length > 0 &&
Object.keys(categories).filter((category) => categories[category]).length > 0 &&
!$models.includes(tagName)
!$models.includes(tagName)
) {
) {
const res = await createModel(
const res = await createModel(localStorage.token, tagName, content);
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token,
tagName,
content
);
if (res) {
if (res) {
const reader = res.body
const reader = res.body
...
@@ -641,7 +635,7 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
...
@@ -641,7 +635,7 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
<div class=" text-sm font-semibold mb-2">Pull Progress</div>
<div class=" text-sm font-semibold mb-2">Pull Progress</div>
<div class="w-full rounded-full dark:bg-gray-800">
<div class="w-full rounded-full dark:bg-gray-800">
<div
<div
class="dark:bg-gray-600 text-xs font-medium text-
blue
-100 text-center p-0.5 leading-none rounded-full"
class="dark:bg-gray-600
bg-gray-500
text-xs font-medium text-
gray
-100 text-center p-0.5 leading-none rounded-full"
style="width: {Math.max(15, pullProgress ?? 0)}%"
style="width: {Math.max(15, pullProgress ?? 0)}%"
>
>
{pullProgress ?? 0}%
{pullProgress ?? 0}%
...
...
src/routes/(app)/modelfiles/edit/+page.svelte
View file @
7071716f
...
@@ -7,8 +7,6 @@
...
@@ -7,8 +7,6 @@
import { page } from '$app/stores';
import { page } from '$app/stores';
import { settings, user, config, modelfiles } from '$lib/stores';
import { settings, user, config, modelfiles } from '$lib/stores';
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { splitStream } from '$lib/utils';
import { splitStream } from '$lib/utils';
import { createModel } from '$lib/apis/ollama';
import { createModel } from '$lib/apis/ollama';
...
@@ -104,12 +102,7 @@
...
@@ -104,12 +102,7 @@
content !== '' &&
content !== '' &&
Object.keys(categories).filter((category) => categories[category]).length > 0
Object.keys(categories).filter((category) => categories[category]).length > 0
) {
) {
const res = await createModel(
const res = await createModel(localStorage.token, tagName, content);
$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL,
localStorage.token,
tagName,
content
);
if (res) {
if (res) {
const reader = res.body
const reader = res.body
...
...
static/manifest.json
View file @
7071716f
{
{
"name"
:
"Ollama Web UI"
,
"name"
:
"Ollama Web UI"
,
"short_name"
:
"Ollama"
,
"short_name"
:
"Ollama"
,
"start_url"
:
"/"
,
"start_url"
:
"/"
,
"display"
:
"standalone"
,
"display"
:
"standalone"
,
"background_color"
:
"#343541"
,
"background_color"
:
"#343541"
,
"theme_color"
:
"#343541"
,
"theme_color"
:
"#343541"
,
"orientation"
:
"portrait-primary"
,
"orientation"
:
"portrait-primary"
,
"icons"
:
[
"icons"
:
[
{
{
"src"
:
"/favicon.png"
,
"src"
:
"/favicon.png"
,
"type"
:
"image/png"
,
"type"
:
"image/png"
,
"sizes"
:
"844x884"
"sizes"
:
"844x884"
}
}
]
]
}
}
\ No newline at end of file
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment