Merge branch 'dev' into feat/model-config

This commit is contained in:
Timothy Jaeryang Baek
2024-05-21 21:37:04 -10:00
committed by GitHub
54 changed files with 2020 additions and 157 deletions

View File

@@ -1,6 +1,73 @@
import { OLLAMA_API_BASE_URL } from '$lib/constants';
import { promptTemplate } from '$lib/utils';
export const getOllamaConfig = async (token: string = '') => {
let error = null;
const res = await fetch(`${OLLAMA_API_BASE_URL}/config`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.log(err);
if ('detail' in err) {
error = err.detail;
} else {
error = 'Server connection failed';
}
return null;
});
if (error) {
throw error;
}
return res;
};
export const updateOllamaConfig = async (token: string = '', enable_ollama_api: boolean) => {
let error = null;
const res = await fetch(`${OLLAMA_API_BASE_URL}/config/update`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
},
body: JSON.stringify({
enable_ollama_api: enable_ollama_api
})
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
console.log(err);
if ('detail' in err) {
error = err.detail;
} else {
error = 'Server connection failed';
}
return null;
});
if (error) {
throw error;
}
return res;
};
export const getOllamaUrls = async (token: string = '') => {
let error = null;

View File

@@ -123,7 +123,7 @@
}
onMount(async () => {
if (!chatId) {
if (!$chatId) {
await initNewChat();
} else {
if (!($settings.saveChatHistory ?? true)) {
@@ -442,8 +442,7 @@
: undefined,
...messages
]
.filter((message) => message)
.filter((message) => message.content != '')
.filter((message) => message?.content?.trim())
.map((message, idx, arr) => {
// Prepare the base message object
const baseMessage = {
@@ -703,7 +702,7 @@
: undefined,
...messages
]
.filter((message) => message)
.filter((message) => message?.content?.trim())
.map((message, idx, arr) => ({
role: message.role,
...((message.files?.filter((file) => file.type === 'image').length > 0 ?? false) &&

View File

@@ -3,7 +3,13 @@
import { createEventDispatcher, onMount, getContext } from 'svelte';
const dispatch = createEventDispatcher();
import { getOllamaUrls, getOllamaVersion, updateOllamaUrls } from '$lib/apis/ollama';
import {
getOllamaConfig,
getOllamaUrls,
getOllamaVersion,
updateOllamaConfig,
updateOllamaUrls
} from '$lib/apis/ollama';
import {
getOpenAIConfig,
getOpenAIKeys,
@@ -26,6 +32,7 @@
let OPENAI_API_BASE_URLS = [''];
let ENABLE_OPENAI_API = false;
let ENABLE_OLLAMA_API = false;
const updateOpenAIHandler = async () => {
OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS);
@@ -50,10 +57,13 @@
onMount(async () => {
if ($user.role === 'admin') {
OLLAMA_BASE_URLS = await getOllamaUrls(localStorage.token);
const ollamaConfig = await getOllamaConfig(localStorage.token);
const openaiConfig = await getOpenAIConfig(localStorage.token);
const config = await getOpenAIConfig(localStorage.token);
ENABLE_OPENAI_API = config.ENABLE_OPENAI_API;
ENABLE_OPENAI_API = openaiConfig.ENABLE_OPENAI_API;
ENABLE_OLLAMA_API = ollamaConfig.ENABLE_OLLAMA_API;
OLLAMA_BASE_URLS = await getOllamaUrls(localStorage.token);
OPENAI_API_BASE_URLS = await getOpenAIUrls(localStorage.token);
OPENAI_API_KEYS = await getOpenAIKeys(localStorage.token);
@@ -161,95 +171,108 @@
<hr class=" dark:border-gray-700" />
<div>
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Ollama Base URL')}</div>
<div class="flex w-full gap-1.5">
<div class="flex-1 flex flex-col gap-2">
{#each OLLAMA_BASE_URLS as url, idx}
<div class="flex gap-1.5">
<input
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
placeholder={$i18n.t('Enter URL (e.g. http://localhost:11434)')}
bind:value={url}
/>
<div class="pr-1.5 space-y-2">
<div class="flex justify-between items-center text-sm">
<div class=" font-medium">{$i18n.t('Ollama API')}</div>
<div class="self-center flex items-center">
{#if idx === 0}
<button
class="px-1"
on:click={() => {
OLLAMA_BASE_URLS = [...OLLAMA_BASE_URLS, ''];
}}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path
d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z"
/>
</svg>
</button>
{:else}
<button
class="px-1"
on:click={() => {
OLLAMA_BASE_URLS = OLLAMA_BASE_URLS.filter((url, urlIdx) => idx !== urlIdx);
}}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path d="M3.75 7.25a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5Z" />
</svg>
</button>
{/if}
</div>
</div>
{/each}
</div>
<div class="">
<button
class="p-2.5 bg-gray-200 hover:bg-gray-300 dark:bg-gray-850 dark:hover:bg-gray-800 rounded-lg transition"
on:click={() => {
updateOllamaUrlsHandler();
<div class="mt-1">
<Switch
bind:state={ENABLE_OLLAMA_API}
on:change={async () => {
updateOllamaConfig(localStorage.token, ENABLE_OLLAMA_API);
}}
type="button"
>
<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="M15.312 11.424a5.5 5.5 0 01-9.201 2.466l-.312-.311h2.433a.75.75 0 000-1.5H3.989a.75.75 0 00-.75.75v4.242a.75.75 0 001.5 0v-2.43l.31.31a7 7 0 0011.712-3.138.75.75 0 00-1.449-.39zm1.23-3.723a.75.75 0 00.219-.53V2.929a.75.75 0 00-1.5 0V5.36l-.31-.31A7 7 0 003.239 8.188a.75.75 0 101.448.389A5.5 5.5 0 0113.89 6.11l.311.31h-2.432a.75.75 0 000 1.5h4.243a.75.75 0 00.53-.219z"
clip-rule="evenodd"
/>
</svg>
</button>
/>
</div>
</div>
{#if ENABLE_OLLAMA_API}
<div class="flex w-full gap-1.5">
<div class="flex-1 flex flex-col gap-2">
{#each OLLAMA_BASE_URLS as url, idx}
<div class="flex gap-1.5">
<input
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
placeholder={$i18n.t('Enter URL (e.g. http://localhost:11434)')}
bind:value={url}
/>
<div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
{$i18n.t('Trouble accessing Ollama?')}
<a
class=" text-gray-300 font-medium underline"
href="https://github.com/open-webui/open-webui#troubleshooting"
target="_blank"
>
{$i18n.t('Click here for help.')}
</a>
</div>
<div class="self-center flex items-center">
{#if idx === 0}
<button
class="px-1"
on:click={() => {
OLLAMA_BASE_URLS = [...OLLAMA_BASE_URLS, ''];
}}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path
d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z"
/>
</svg>
</button>
{:else}
<button
class="px-1"
on:click={() => {
OLLAMA_BASE_URLS = OLLAMA_BASE_URLS.filter((url, urlIdx) => idx !== urlIdx);
}}
type="button"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path d="M3.75 7.25a.75.75 0 0 0 0 1.5h8.5a.75.75 0 0 0 0-1.5h-8.5Z" />
</svg>
</button>
{/if}
</div>
</div>
{/each}
</div>
<div class="flex">
<button
class="self-center p-2 bg-gray-200 hover:bg-gray-300 dark:bg-gray-900 dark:hover:bg-gray-850 rounded-lg transition"
on:click={() => {
updateOllamaUrlsHandler();
}}
type="button"
>
<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="M15.312 11.424a5.5 5.5 0 01-9.201 2.466l-.312-.311h2.433a.75.75 0 000-1.5H3.989a.75.75 0 00-.75.75v4.242a.75.75 0 001.5 0v-2.43l.31.31a7 7 0 0011.712-3.138.75.75 0 00-1.449-.39zm1.23-3.723a.75.75 0 00.219-.53V2.929a.75.75 0 00-1.5 0V5.36l-.31-.31A7 7 0 003.239 8.188a.75.75 0 101.448.389A5.5 5.5 0 0113.89 6.11l.311.31h-2.432a.75.75 0 000 1.5h4.243a.75.75 0 00.53-.219z"
clip-rule="evenodd"
/>
</svg>
</button>
</div>
</div>
<div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
{$i18n.t('Trouble accessing Ollama?')}
<a
class=" text-gray-300 font-medium underline"
href="https://github.com/open-webui/open-webui#troubleshooting"
target="_blank"
>
{$i18n.t('Click here for help.')}
</a>
</div>
{/if}
</div>
</div>

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "حسنا دعنا نذهب!",
"OLED Dark": "OLED داكن",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama الرابط الافتراضي",
"Ollama API": "",
"Ollama Version": "Ollama الاصدار",
"On": "تشغيل",
"Only": "فقط",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "ОК, Нека започваме!",
"OLED Dark": "OLED тъмно",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama Базов URL",
"Ollama API": "",
"Ollama Version": "Ollama Версия",
"On": "Вкл.",
"Only": "Само",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "ঠিক আছে, চলুন যাই!",
"OLED Dark": "OLED ডার্ক",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama বেজ ইউআরএল",
"Ollama API": "",
"Ollama Version": "Ollama ভার্সন",
"On": "চালু",
"Only": "শুধুমাত্র",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "D'acord, Anem!",
"OLED Dark": "OLED Fosc",
"Ollama": "Ollama",
"Ollama Base URL": "URL Base d'Ollama",
"Ollama API": "",
"Ollama Version": "Versió d'Ollama",
"On": "Activat",
"Only": "Només",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Okay, los geht's!",
"OLED Dark": "OLED Dunkel",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama Basis URL",
"Ollama API": "",
"Ollama Version": "Ollama-Version",
"On": "Ein",
"Only": "Nur",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Okay, Let's Go!",
"OLED Dark": "OLED Dark",
"Ollama": "",
"Ollama Base URL": "Ollama Base Bark",
"Ollama API": "",
"Ollama Version": "Ollama Version",
"On": "On",
"Only": "Only",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "",
"OLED Dark": "",
"Ollama": "",
"Ollama Base URL": "",
"Ollama API": "",
"Ollama Version": "",
"On": "",
"Only": "",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "",
"OLED Dark": "",
"Ollama": "",
"Ollama Base URL": "",
"Ollama API": "",
"Ollama Version": "",
"On": "",
"Only": "",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Bien, ¡Vamos!",
"OLED Dark": "OLED oscuro",
"Ollama": "Ollama",
"Ollama Base URL": "URL base de Ollama",
"Ollama API": "",
"Ollama Version": "Versión de Ollama",
"On": "Activado",
"Only": "Solamente",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "باشه، بزن بریم!",
"OLED Dark": "OLED تیره",
"Ollama": "Ollama",
"Ollama Base URL": "URL پایه اولاما",
"Ollama API": "",
"Ollama Version": "نسخه اولاما",
"On": "روشن",
"Only": "فقط",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Eikun menoksi!",
"OLED Dark": "OLED-tumma",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama-perus-URL",
"Ollama API": "",
"Ollama Version": "Ollama-versio",
"On": "Päällä",
"Only": "Vain",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Okay, Allons-y !",
"OLED Dark": "OLED Sombre",
"Ollama": "Ollama",
"Ollama Base URL": "URL de Base Ollama",
"Ollama API": "",
"Ollama Version": "Version Ollama",
"On": "Activé",
"Only": "Seulement",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "D'accord, allons-y !",
"OLED Dark": "OLED Sombre",
"Ollama": "Ollama",
"Ollama Base URL": "URL de Base Ollama",
"Ollama API": "",
"Ollama Version": "Version Ollama",
"On": "Activé",
"Only": "Seulement",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "בסדר, בואו נתחיל!",
"OLED Dark": "OLED כהה",
"Ollama": "Ollama",
"Ollama Base URL": "כתובת URL בסיסית של Ollama",
"Ollama API": "",
"Ollama Version": "גרסת Ollama",
"On": "פועל",
"Only": "רק",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "ठीक है, चलिए चलते हैं!",
"OLED Dark": "OLEDescuro",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama URL",
"Ollama API": "",
"Ollama Version": "Ollama Version",
"On": "चालू",
"Only": "केवल",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "U redu, idemo!",
"OLED Dark": "OLED Tamno",
"Ollama": "Ollama",
"Ollama Base URL": "Osnovni URL Ollama",
"Ollama API": "",
"Ollama Version": "Verzija Ollama",
"On": "Uključeno",
"Only": "Samo",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Ok, andiamo!",
"OLED Dark": "OLED scuro",
"Ollama": "Ollama",
"Ollama Base URL": "URL base Ollama",
"Ollama API": "",
"Ollama Version": "Versione Ollama",
"On": "Attivato",
"Only": "Solo",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "OK、始めましょう",
"OLED Dark": "OLED ダーク",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama ベース URL",
"Ollama API": "",
"Ollama Version": "Ollama バージョン",
"On": "オン",
"Only": "のみ",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "კარგი, წავედით!",
"OLED Dark": "OLED მუქი",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama ბაზისური მისამართი",
"Ollama API": "",
"Ollama Version": "Ollama ვერსია",
"On": "ჩართვა",
"Only": "მხოლოდ",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "그렇습니다, 시작합시다!",
"OLED Dark": "OLED 어두운",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama 기본 URL",
"Ollama API": "",
"Ollama Version": "Ollama 버전",
"On": "켜기",
"Only": "오직",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Okay, Laten we gaan!",
"OLED Dark": "OLED Donker",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama Basis URL",
"Ollama API": "",
"Ollama Version": "Ollama Versie",
"On": "Aan",
"Only": "Alleen",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "ਠੀਕ ਹੈ, ਚੱਲੋ ਚੱਲੀਏ!",
"OLED Dark": "OLED ਗੂੜ੍ਹਾ",
"Ollama": "ਓਲਾਮਾ",
"Ollama Base URL": "ਓਲਾਮਾ ਬੇਸ URL",
"Ollama API": "",
"Ollama Version": "ਓਲਾਮਾ ਵਰਜਨ",
"On": "ਚਾਲੂ",
"Only": "ਸਿਰਫ਼",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Okej, zaczynamy!",
"OLED Dark": "Ciemny OLED",
"Ollama": "Ollama",
"Ollama Base URL": "Adres bazowy URL Ollama",
"Ollama API": "",
"Ollama Version": "Wersja Ollama",
"On": "Włączony",
"Only": "Tylko",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Ok, Vamos Lá!",
"OLED Dark": "OLED Escuro",
"Ollama": "Ollama",
"Ollama Base URL": "URL Base do Ollama",
"Ollama API": "",
"Ollama Version": "Versão do Ollama",
"On": "Ligado",
"Only": "Somente",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Ok, Vamos Lá!",
"OLED Dark": "OLED Escuro",
"Ollama": "Ollama",
"Ollama Base URL": "URL Base do Ollama",
"Ollama API": "",
"Ollama Version": "Versão do Ollama",
"On": "Ligado",
"Only": "Somente",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Давайте начнём!",
"OLED Dark": "OLED темная",
"Ollama": "Ollama",
"Ollama Base URL": "Базовый адрес URL Ollama",
"Ollama API": "",
"Ollama Version": "Версия Ollama",
"On": "Включено.",
"Only": "Только",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "У реду, хајде да кренемо!",
"OLED Dark": "OLED тамна",
"Ollama": "Ollama",
"Ollama Base URL": "Основна адреса Ollama-е",
"Ollama API": "",
"Ollama Version": "Издање Ollama-е",
"On": "Укључено",
"Only": "Само",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Okej, nu kör vi!",
"OLED Dark": "OLED mörkt",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama bas-URL",
"Ollama API": "",
"Ollama Version": "Ollama-version",
"On": "På",
"Only": "Endast",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Tamam, Hadi Başlayalım!",
"OLED Dark": "OLED Koyu",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama Temel URL",
"Ollama API": "",
"Ollama Version": "Ollama Sürümü",
"On": "Açık",
"Only": "Yalnızca",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Гаразд, давайте почнемо!",
"OLED Dark": "Темний OLED",
"Ollama": "Ollama",
"Ollama Base URL": "URL-адреса Ollama",
"Ollama API": "",
"Ollama Version": "Версія Ollama",
"On": "Увімк",
"Only": "Тільки",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "Được rồi, Bắt đầu thôi!",
"OLED Dark": "OLED Dark",
"Ollama": "Ollama",
"Ollama Base URL": "Đường dẫn tới API của Ollama (Ollama Base URL)",
"Ollama API": "",
"Ollama Version": "Phiên bản Ollama",
"On": "Bật",
"Only": "Only",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "好的,我们开始吧!",
"OLED Dark": "暗黑色",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama 基础 URL",
"Ollama API": "",
"Ollama Version": "Ollama 版本",
"On": "开",
"Only": "仅",

View File

@@ -314,7 +314,7 @@
"Okay, Let's Go!": "好的,啟動吧!",
"OLED Dark": "`",
"Ollama": "Ollama",
"Ollama Base URL": "Ollama 基本 URL",
"Ollama API": "",
"Ollama Version": "Ollama 版本",
"On": "開啟",
"Only": "僅有",