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
e8d4e03c
Commit
e8d4e03c
authored
May 29, 2024
by
Timothy J. Baek
Browse files
refac: openai allow empty key
parent
943baad6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
44 deletions
+91
-44
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+4
-0
backend/apps/openai/main.py
backend/apps/openai/main.py
+0
-3
src/lib/apis/ollama/index.ts
src/lib/apis/ollama/index.ts
+2
-2
src/lib/apis/openai/index.ts
src/lib/apis/openai/index.ts
+3
-16
src/lib/components/chat/Settings/Connections.svelte
src/lib/components/chat/Settings/Connections.svelte
+82
-23
No files found.
backend/apps/ollama/main.py
View file @
e8d4e03c
...
...
@@ -219,6 +219,8 @@ async def get_ollama_tags(
return
models
else
:
url
=
app
.
state
.
config
.
OLLAMA_BASE_URLS
[
url_idx
]
r
=
None
try
:
r
=
requests
.
request
(
method
=
"GET"
,
url
=
f
"
{
url
}
/api/tags"
)
r
.
raise_for_status
()
...
...
@@ -270,6 +272,8 @@ async def get_ollama_versions(url_idx: Optional[int] = None):
)
else
:
url
=
app
.
state
.
config
.
OLLAMA_BASE_URLS
[
url_idx
]
r
=
None
try
:
r
=
requests
.
request
(
method
=
"GET"
,
url
=
f
"
{
url
}
/api/version"
)
r
.
raise_for_status
()
...
...
backend/apps/openai/main.py
View file @
e8d4e03c
...
...
@@ -407,9 +407,6 @@ async def proxy(path: str, request: Request, user=Depends(get_verified_user)):
target_url
=
f
"
{
url
}
/
{
path
}
"
if
key
==
""
:
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
API_KEY_NOT_FOUND
)
headers
=
{}
headers
[
"Authorization"
]
=
f
"Bearer
{
key
}
"
headers
[
"Content-Type"
]
=
"application/json"
...
...
src/lib/apis/ollama/index.ts
View file @
e8d4e03c
...
...
@@ -135,10 +135,10 @@ export const updateOllamaUrls = async (token: string = '', urls: string[]) => {
return
res
.
OLLAMA_BASE_URLS
;
};
export
const
getOllamaVersion
=
async
(
token
:
string
=
''
)
=>
{
export
const
getOllamaVersion
=
async
(
token
:
string
,
urlIdx
?:
number
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
OLLAMA_API_BASE_URL
}
/api/version`
,
{
const
res
=
await
fetch
(
`
${
OLLAMA_API_BASE_URL
}
/api/version
${
urlIdx
?
`/
${
urlIdx
}
`
:
''
}
`
,
{
method
:
'
GET
'
,
headers
:
{
Accept
:
'
application/json
'
,
...
...
src/lib/apis/openai/index.ts
View file @
e8d4e03c
...
...
@@ -203,10 +203,10 @@ export const updateOpenAIKeys = async (token: string = '', keys: string[]) => {
return
res
.
OPENAI_API_KEYS
;
};
export
const
getOpenAIModels
=
async
(
token
:
string
=
''
)
=>
{
export
const
getOpenAIModels
=
async
(
token
:
string
,
urlIdx
?:
number
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
OPENAI_API_BASE_URL
}
/models`
,
{
const
res
=
await
fetch
(
`
${
OPENAI_API_BASE_URL
}
/models
${
urlIdx
?
`/
${
urlIdx
}
`
:
''
}
`
,
{
method
:
'
GET
'
,
headers
:
{
Accept
:
'
application/json
'
,
...
...
@@ -227,20 +227,7 @@ export const getOpenAIModels = async (token: string = '') => {
throw
error
;
}
const
models
=
Array
.
isArray
(
res
)
?
res
:
res
?.
data
??
null
;
return
models
?
models
.
map
((
model
)
=>
({
id
:
model
.
id
,
name
:
model
.
name
??
model
.
id
,
external
:
true
,
custom_info
:
model
.
custom_info
}))
.
sort
((
a
,
b
)
=>
{
return
a
.
name
.
localeCompare
(
b
.
name
);
})
:
models
;
return
res
;
};
export
const
getOpenAIModelsDirect
=
async
(
...
...
src/lib/components/chat/Settings/Connections.svelte
View file @
e8d4e03c
...
...
@@ -13,6 +13,7 @@
import {
getOpenAIConfig,
getOpenAIKeys,
getOpenAIModels,
getOpenAIUrls,
updateOpenAIConfig,
updateOpenAIKeys,
...
...
@@ -21,6 +22,7 @@
import { toast } from 'svelte-sonner';
import Switch from '$lib/components/common/Switch.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
const i18n = getContext('i18n');
...
...
@@ -35,6 +37,34 @@
let ENABLE_OPENAI_API = null;
let ENABLE_OLLAMA_API = null;
const verifyOpenAIHandler = async (idx) => {
OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS);
OPENAI_API_KEYS = await updateOpenAIKeys(localStorage.token, OPENAI_API_KEYS);
const res = await getOpenAIModels(localStorage.token, idx).catch((error) => {
toast.error(error);
return null;
});
if (res) {
toast.success($i18n.t('Server connection verified'));
console.log(res);
}
};
const verifyOllamaHandler = async (idx) => {
OLLAMA_BASE_URLS = await updateOllamaUrls(localStorage.token, OLLAMA_BASE_URLS);
const res = await getOllamaVersion(localStorage.token, idx).catch((error) => {
toast.error(error);
return null;
});
if (res) {
toast.success($i18n.t('Server connection verified'));
}
};
const updateOpenAIHandler = async () => {
OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS);
OPENAI_API_KEYS = await updateOpenAIKeys(localStorage.token, OPENAI_API_KEYS);
...
...
@@ -83,6 +113,8 @@
class="flex flex-col h-full justify-between text-sm"
on:submit|preventDefault={() => {
updateOpenAIHandler();
updateOllamaUrlsHandler();
dispatch('save');
}}
>
...
...
@@ -167,6 +199,31 @@
</button>
{/if}
</div>
<div class="flex">
<Tooltip content="Verify connection" className="self-start mt-0.5">
<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={() => {
verifyOpenAIHandler(idx);
}}
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>
</Tooltip>
</div>
</div>
<div class=" mb-1 text-xs text-gray-400 dark:text-gray-500">
{$i18n.t('WebUI will make requests to')}
...
...
@@ -245,15 +302,13 @@
</button>
{/if}
</div>
</div>
{/each}
</div>
<div class="flex">
<Tooltip content="Verify connection" className="self-start mt-0.5">
<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={() => {
update
Ollama
Urls
Handler();
verify
OllamaHandler(
idx
);
}}
type="button"
>
...
...
@@ -270,6 +325,10 @@
/>
</svg>
</button>
</Tooltip>
</div>
</div>
{/each}
</div>
</div>
...
...
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