From d9dc04f1a10efb36535c7c349dd05c6c1f3b42be Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 15 Nov 2024 02:05:43 -0800 Subject: [PATCH] refac: frontend --- src/lib/apis/models/index.ts | 69 +- src/lib/apis/ollama/index.ts | 6 +- src/lib/apis/users/index.ts | 4 +- .../admin/Settings/Connections.svelte | 1 + .../Connections/ManageOllamaModal.svelte | 1019 ++++++++++++++++ .../Connections/OllamaConnection.svelte | 21 +- .../components/admin/Settings/Models.svelte | 1076 +---------------- src/lib/components/admin/Users/Groups.svelte | 32 +- .../admin/Users/Groups/EditGroupModal.svelte | 27 +- .../admin/Users/Groups/Permissions.svelte | 18 +- src/lib/components/chat/MessageInput.svelte | 1 - .../chat/MessageInput/InputMenu.svelte | 12 +- src/lib/components/icons/Wrench.svelte | 20 + src/lib/components/workspace/Knowledge.svelte | 2 +- src/lib/components/workspace/Models.svelte | 186 +-- .../workspace/Models/ModelEditor.svelte | 73 +- .../workspace/Models/ModelMenu.svelte | 66 - .../common/AccessPermissionsModal.svelte | 101 ++ .../workspace/models/create/+page.svelte | 4 +- .../(app)/workspace/models/edit/+page.svelte | 9 +- 20 files changed, 1340 insertions(+), 1407 deletions(-) create mode 100644 src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte create mode 100644 src/lib/components/icons/Wrench.svelte create mode 100644 src/lib/components/workspace/common/AccessPermissionsModal.svelte diff --git a/src/lib/apis/models/index.ts b/src/lib/apis/models/index.ts index 9faa358d3..14014ce99 100644 --- a/src/lib/apis/models/index.ts +++ b/src/lib/apis/models/index.ts @@ -1,35 +1,7 @@ import { WEBUI_API_BASE_URL } from '$lib/constants'; -export const addNewModel = async (token: string, model: object) => { - let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/models/add`, { - method: 'POST', - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', - authorization: `Bearer ${token}` - }, - body: JSON.stringify(model) - }) - .then(async (res) => { - if (!res.ok) throw await res.json(); - return res.json(); - }) - .catch((err) => { - error = err.detail; - console.log(err); - return null; - }); - - if (error) { - throw error; - } - - return res; -}; - -export const getModelInfos = async (token: string = '') => { +export const getWorkspaceModels = async (token: string = '') => { let error = null; const res = await fetch(`${WEBUI_API_BASE_URL}/models`, { @@ -60,13 +32,46 @@ export const getModelInfos = async (token: string = '') => { return res; }; + + +export const createNewModel = async (token: string, model: object) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/models/create`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + authorization: `Bearer ${token}` + }, + body: JSON.stringify(model) + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .catch((err) => { + error = err.detail; + console.log(err); + return null; + }); + + if (error) { + throw error; + } + + return res; +}; + + + export const getModelById = async (token: string, id: string) => { let error = null; const searchParams = new URLSearchParams(); searchParams.append('id', id); - const res = await fetch(`${WEBUI_API_BASE_URL}/models?${searchParams.toString()}`, { + const res = await fetch(`${WEBUI_API_BASE_URL}/models/id/${id}`, { method: 'GET', headers: { Accept: 'application/json', @@ -101,7 +106,7 @@ export const updateModelById = async (token: string, id: string, model: object) const searchParams = new URLSearchParams(); searchParams.append('id', id); - const res = await fetch(`${WEBUI_API_BASE_URL}/models/update?${searchParams.toString()}`, { + const res = await fetch(`${WEBUI_API_BASE_URL}/models/id/${id}/update`, { method: 'POST', headers: { Accept: 'application/json', @@ -137,7 +142,7 @@ export const deleteModelById = async (token: string, id: string) => { const searchParams = new URLSearchParams(); searchParams.append('id', id); - const res = await fetch(`${WEBUI_API_BASE_URL}/models/delete?${searchParams.toString()}`, { + const res = await fetch(`${WEBUI_API_BASE_URL}/models/id/${id}/delete`, { method: 'DELETE', headers: { Accept: 'application/json', diff --git a/src/lib/apis/ollama/index.ts b/src/lib/apis/ollama/index.ts index 4ad2ba596..84f3106c2 100644 --- a/src/lib/apis/ollama/index.ts +++ b/src/lib/apis/ollama/index.ts @@ -211,10 +211,12 @@ export const getOllamaVersion = async (token: string, urlIdx?: number) => { return res?.version ?? false; }; -export const getOllamaModels = async (token: string = '') => { +export const getOllamaModels = async (token: string = '', urlIdx: null|number = null) => { let error = null; - const res = await fetch(`${OLLAMA_API_BASE_URL}/api/tags`, { + const res = await fetch(`${OLLAMA_API_BASE_URL}/api/tags${ + urlIdx !== null ? `/${urlIdx}` : '' + }`, { method: 'GET', headers: { Accept: 'application/json', diff --git a/src/lib/apis/users/index.ts b/src/lib/apis/users/index.ts index 0b22b7171..4ae440ed7 100644 --- a/src/lib/apis/users/index.ts +++ b/src/lib/apis/users/index.ts @@ -4,7 +4,7 @@ import { getUserPosition } from '$lib/utils'; export const getUserPermissions = async (token: string) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/users/permissions/user`, { + const res = await fetch(`${WEBUI_API_BASE_URL}/users/permissions`, { method: 'GET', headers: { 'Content-Type': 'application/json', @@ -31,7 +31,7 @@ export const getUserPermissions = async (token: string) => { export const updateUserPermissions = async (token: string, permissions: object) => { let error = null; - const res = await fetch(`${WEBUI_API_BASE_URL}/users/permissions/user`, { + const res = await fetch(`${WEBUI_API_BASE_URL}/users/permissions`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/lib/components/admin/Settings/Connections.svelte b/src/lib/components/admin/Settings/Connections.svelte index 407810c9f..ddc19bb8f 100644 --- a/src/lib/components/admin/Settings/Connections.svelte +++ b/src/lib/components/admin/Settings/Connections.svelte @@ -302,6 +302,7 @@ { updateOllamaHandler(); }} diff --git a/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte b/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte new file mode 100644 index 000000000..ffd282fde --- /dev/null +++ b/src/lib/components/admin/Settings/Connections/ManageOllamaModal.svelte @@ -0,0 +1,1019 @@ + + + { + deleteModelHandler(); + }} +/> + + +
+
+
+ {$i18n.t('Manage Ollama')} ({urlIdx}) +
+ +
+ +
+ {#if !loading} +
+
+
+
+
+ {$i18n.t('Pull a model from Ollama.com')} +
+
+
+ +
+ +
+ +
+ {$i18n.t('To access the available model names for downloading,')} + {$i18n.t('click here.')} +
+ + {#if Object.keys($MODEL_DOWNLOAD_POOL).length > 0} + {#each Object.keys($MODEL_DOWNLOAD_POOL) as model} + {#if 'pullProgress' in $MODEL_DOWNLOAD_POOL[model]} +
+
{model}
+
+
+
+
+ {$MODEL_DOWNLOAD_POOL[model].pullProgress ?? 0}% +
+
+ + + + +
+ {#if 'digest' in $MODEL_DOWNLOAD_POOL[model]} +
+ {$MODEL_DOWNLOAD_POOL[model].digest} +
+ {/if} +
+
+ {/if} + {/each} + {/if} +
+ +
+
{$i18n.t('Delete a model')}
+
+
+ +
+ +
+
+ +
+
{$i18n.t('Create a model')}
+
+
+ + +