mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
feat: azure openai support
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import { OLLAMA_API_BASE_URL } from '$lib/constants';
|
||||
|
||||
export const verifyOllamaConnection = async (
|
||||
token: string = '',
|
||||
url: string = '',
|
||||
key: string = ''
|
||||
) => {
|
||||
export const verifyOllamaConnection = async (token: string = '', connection: dict = {}) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${OLLAMA_API_BASE_URL}/verify`, {
|
||||
@@ -15,8 +11,7 @@ export const verifyOllamaConnection = async (
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url,
|
||||
key
|
||||
...connection
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -267,10 +267,10 @@ export const getOpenAIModels = async (token: string, urlIdx?: number) => {
|
||||
|
||||
export const verifyOpenAIConnection = async (
|
||||
token: string = '',
|
||||
url: string = 'https://api.openai.com/v1',
|
||||
key: string = '',
|
||||
connection: dict = {},
|
||||
direct: boolean = false
|
||||
) => {
|
||||
const { url, key, config } = connection;
|
||||
if (!url) {
|
||||
throw 'OpenAI: URL is required';
|
||||
}
|
||||
@@ -309,7 +309,8 @@ export const verifyOpenAIConnection = async (
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url,
|
||||
key
|
||||
key,
|
||||
config
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -33,7 +33,9 @@
|
||||
let connectionType = 'external';
|
||||
let azure = false;
|
||||
$: azure =
|
||||
url.includes('openai.azure.com') || url.includes('cognitive.microsoft.com') ? true : false;
|
||||
(url.includes('openai.azure.com') || url.includes('cognitive.microsoft.com')) && !direct
|
||||
? true
|
||||
: false;
|
||||
|
||||
let prefixId = '';
|
||||
let enable = true;
|
||||
@@ -47,7 +49,10 @@
|
||||
let loading = false;
|
||||
|
||||
const verifyOllamaHandler = async () => {
|
||||
const res = await verifyOllamaConnection(localStorage.token, url, key).catch((error) => {
|
||||
const res = await verifyOllamaConnection(localStorage.token, {
|
||||
url,
|
||||
key
|
||||
}).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
});
|
||||
|
||||
@@ -57,11 +62,20 @@
|
||||
};
|
||||
|
||||
const verifyOpenAIHandler = async () => {
|
||||
const res = await verifyOpenAIConnection(localStorage.token, url, key, direct).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
);
|
||||
const res = await verifyOpenAIConnection(
|
||||
localStorage.token,
|
||||
{
|
||||
url,
|
||||
key,
|
||||
config: {
|
||||
azure: azure,
|
||||
api_version: apiVersion
|
||||
}
|
||||
},
|
||||
direct
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
});
|
||||
|
||||
if (res) {
|
||||
toast.success($i18n.t('Server connection verified'));
|
||||
@@ -187,27 +201,29 @@
|
||||
}}
|
||||
>
|
||||
<div class="px-1">
|
||||
<div class="flex gap-2">
|
||||
<div class="flex w-full justify-between items-center">
|
||||
<div class=" text-xs text-gray-500">{$i18n.t('Connection Type')}</div>
|
||||
{#if !direct}
|
||||
<div class="flex gap-2">
|
||||
<div class="flex w-full justify-between items-center">
|
||||
<div class=" text-xs text-gray-500">{$i18n.t('Connection Type')}</div>
|
||||
|
||||
<div class="">
|
||||
<button
|
||||
on:click={() => {
|
||||
connectionType = connectionType === 'local' ? 'external' : 'local';
|
||||
}}
|
||||
type="button"
|
||||
class=" text-xs text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
{#if connectionType === 'local'}
|
||||
{$i18n.t('Local')}
|
||||
{:else}
|
||||
{$i18n.t('External')}
|
||||
{/if}
|
||||
</button>
|
||||
<div class="">
|
||||
<button
|
||||
on:click={() => {
|
||||
connectionType = connectionType === 'local' ? 'external' : 'local';
|
||||
}}
|
||||
type="button"
|
||||
class=" text-xs text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
{#if connectionType === 'local'}
|
||||
{$i18n.t('Local')}
|
||||
{:else}
|
||||
{$i18n.t('External')}
|
||||
{/if}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex gap-2 mt-1.5">
|
||||
<div class="flex flex-col w-full">
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
import { getContext, onMount } from 'svelte';
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import { models } from '$lib/stores';
|
||||
import { verifyOpenAIConnection } from '$lib/apis/openai';
|
||||
import { verifyOllamaConnection } from '$lib/apis/ollama';
|
||||
|
||||
import Modal from '$lib/components/common/Modal.svelte';
|
||||
import Plus from '$lib/components/icons/Plus.svelte';
|
||||
import Minus from '$lib/components/icons/Minus.svelte';
|
||||
|
||||
Reference in New Issue
Block a user