refac
This commit is contained in:
@@ -159,6 +159,39 @@ export const getModels = async (
|
||||
return models;
|
||||
};
|
||||
|
||||
export const unloadModel = async (token: string, model: string) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_BASE_URL}/api/models/unload`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { authorization: `Bearer ${token}` })
|
||||
},
|
||||
body: JSON.stringify({ model })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
if ('detail' in err) {
|
||||
error = err.detail;
|
||||
} else {
|
||||
error = err;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
type ChatCompletedForm = {
|
||||
model: string;
|
||||
messages: Record<string, unknown>[];
|
||||
|
||||
@@ -36,9 +36,10 @@
|
||||
let auth_type = 'bearer';
|
||||
|
||||
let connectionType = 'external';
|
||||
let azure = false;
|
||||
let provider = '';
|
||||
$: azure =
|
||||
(url.includes('azure.') || url.includes('cognitive.microsoft.com')) && !direct ? true : false;
|
||||
provider === 'azure' ||
|
||||
((url.includes('azure.') || url.includes('cognitive.microsoft.com')) && !direct && provider === '');
|
||||
|
||||
let prefixId = '';
|
||||
let enable = true;
|
||||
@@ -98,7 +99,7 @@
|
||||
key,
|
||||
config: {
|
||||
auth_type,
|
||||
azure: azure,
|
||||
...(provider ? { provider } : azure ? { azure: true } : {}),
|
||||
api_version: apiVersion,
|
||||
...(_headers ? { headers: _headers } : {})
|
||||
}
|
||||
@@ -186,7 +187,8 @@
|
||||
connection_type: connectionType,
|
||||
auth_type,
|
||||
headers: headers ? JSON.parse(headers) : undefined,
|
||||
...(!ollama && azure ? { azure: true, api_version: apiVersion } : {}),
|
||||
...(provider ? { provider } : !ollama && azure ? { azure: true } : {}),
|
||||
...(azure ? { api_version: apiVersion } : {}),
|
||||
...(apiType ? { api_type: apiType } : {})
|
||||
}
|
||||
};
|
||||
@@ -223,7 +225,7 @@
|
||||
connectionType = connection.config?.connection_type ?? 'local';
|
||||
} else {
|
||||
connectionType = connection.config?.connection_type ?? 'external';
|
||||
azure = connection.config?.azure ?? false;
|
||||
provider = connection.config?.provider ?? (connection.config?.azure ? 'azure' : '');
|
||||
apiVersion = connection.config?.api_version ?? '';
|
||||
apiType = connection.config?.api_type ?? '';
|
||||
}
|
||||
@@ -491,22 +493,22 @@
|
||||
{#if !ollama && !direct}
|
||||
<div class="flex flex-row justify-between items-center w-full mt-2">
|
||||
<label
|
||||
for="prefix-id-input"
|
||||
for="provider-select"
|
||||
class={`mb-0.5 text-xs text-gray-500
|
||||
${($settings?.highContrastMode ?? false) ? 'text-gray-800 dark:text-gray-100' : ''}`}
|
||||
>{$i18n.t('Provider Type')}</label
|
||||
>{$i18n.t('Provider')}</label
|
||||
>
|
||||
|
||||
<div>
|
||||
<button
|
||||
on:click={() => {
|
||||
azure = !azure;
|
||||
}}
|
||||
type="button"
|
||||
class=" text-xs text-gray-700 dark:text-gray-300"
|
||||
<select
|
||||
id="provider-select"
|
||||
bind:value={provider}
|
||||
class="text-xs text-gray-700 dark:text-gray-300 bg-transparent outline-hidden"
|
||||
>
|
||||
{azure ? $i18n.t('Azure OpenAI') : $i18n.t('OpenAI')}
|
||||
</button>
|
||||
<option value="">{$i18n.t('Default')}</option>
|
||||
<option value="azure">{$i18n.t('Azure OpenAI')}</option>
|
||||
<option value="llama.cpp">{$i18n.t('llama.cpp')}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -120,25 +120,28 @@
|
||||
</Tooltip>
|
||||
</div>
|
||||
{/if}
|
||||
{#if item.model.ollama?.expires_at && new Date(item.model.ollama?.expires_at * 1000) > new Date()}
|
||||
<div class="flex items-center translate-y-[0.5px] px-0.5">
|
||||
<Tooltip
|
||||
content={`${$i18n.t('Unloads {{FROM_NOW}}', {
|
||||
{/if}
|
||||
|
||||
{#if item.model.loaded}
|
||||
<div class="flex items-center translate-y-[0.5px] px-0.5">
|
||||
<Tooltip
|
||||
content={item.model.ollama?.expires_at && new Date(item.model.ollama?.expires_at * 1000) > new Date()
|
||||
? `${$i18n.t('Unloads {{FROM_NOW}}', {
|
||||
FROM_NOW: dayjs(item.model.ollama?.expires_at * 1000).fromNow()
|
||||
})}`}
|
||||
className="self-end"
|
||||
>
|
||||
<div class=" flex items-center">
|
||||
<span class="relative flex size-2">
|
||||
<span
|
||||
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
|
||||
/>
|
||||
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
|
||||
</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
{/if}
|
||||
})}`
|
||||
: `${$i18n.t('Loaded')}`}
|
||||
className="self-end"
|
||||
>
|
||||
<div class=" flex items-center">
|
||||
<span class="relative flex size-2">
|
||||
<span
|
||||
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
|
||||
/>
|
||||
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
|
||||
</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- {JSON.stringify(item.info)} -->
|
||||
@@ -233,7 +236,7 @@
|
||||
</div>
|
||||
|
||||
<div class="ml-auto pl-2 pr-1 flex items-center gap-1.5 shrink-0">
|
||||
{#if $user?.role === 'admin' && item.model.owned_by === 'ollama' && item.model.ollama?.expires_at && new Date(item.model.ollama?.expires_at * 1000) > new Date()}
|
||||
{#if $user?.role === 'admin' && item.model.loaded}
|
||||
<Tooltip
|
||||
content={`${$i18n.t('Eject')}`}
|
||||
className="flex-shrink-0 group-hover/item:opacity-100 opacity-0 "
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
import { createEventDispatcher, onMount, getContext, tick } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { deleteModel, getOllamaVersion, pullModel, unloadModel } from '$lib/apis/ollama';
|
||||
import { deleteModel, getOllamaVersion, pullModel } from '$lib/apis/ollama';
|
||||
import { unloadModel } from '$lib/apis';
|
||||
|
||||
import {
|
||||
user,
|
||||
|
||||
@@ -824,7 +824,8 @@
|
||||
if (event.data.action === 'add') {
|
||||
await addOpenAIConnection(token, {
|
||||
url: event.data.url,
|
||||
key: event.data.key
|
||||
key: event.data.key,
|
||||
config: event.data.config
|
||||
});
|
||||
} else if (event.data.action === 'remove') {
|
||||
await removeOpenAIConnection(token, event.data.url);
|
||||
|
||||
Reference in New Issue
Block a user