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
d72653cd
Commit
d72653cd
authored
Apr 01, 2024
by
Timothy J. Baek
Browse files
fix: download allowed hosts
parent
554e5668
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
7 deletions
+12
-7
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+9
-7
src/lib/components/chat/Settings/Models.svelte
src/lib/components/chat/Settings/Models.svelte
+3
-0
No files found.
backend/apps/ollama/main.py
View file @
d72653cd
...
...
@@ -970,13 +970,6 @@ def parse_huggingface_url(hf_url):
async
def
download_file_stream
(
ollama_url
,
file_url
,
file_path
,
file_name
,
chunk_size
=
1024
*
1024
):
allowed_hosts
=
[
"https://huggingface.co/"
,
"https://github.com/"
]
if
not
any
(
file_url
.
startswith
(
host
)
for
host
in
allowed_hosts
):
raise
ValueError
(
"Invalid file_url. Only URLs from allowed hosts are permitted."
)
done
=
False
if
os
.
path
.
exists
(
file_path
):
...
...
@@ -1036,6 +1029,14 @@ async def download_model(
url_idx
:
Optional
[
int
]
=
None
,
):
allowed_hosts
=
[
"https://huggingface.co/"
,
"https://github.com/"
]
if
not
any
(
form_data
.
url
.
startswith
(
host
)
for
host
in
allowed_hosts
):
raise
HTTPException
(
status_code
=
400
,
detail
=
"Invalid file_url. Only URLs from allowed hosts are permitted."
,
)
if
url_idx
==
None
:
url_idx
=
0
url
=
app
.
state
.
OLLAMA_BASE_URLS
[
url_idx
]
...
...
@@ -1044,6 +1045,7 @@ async def download_model(
if
file_name
:
file_path
=
f
"
{
UPLOAD_DIR
}
/
{
file_name
}
"
return
StreamingResponse
(
download_file_stream
(
url
,
form_data
.
url
,
file_path
,
file_name
),
)
...
...
src/lib/components/chat/Settings/Models.svelte
View file @
d72653cd
...
...
@@ -258,6 +258,9 @@
console.log(error);
}
}
} else {
const error = await fileResponse?.json();
toast.error(error?.detail ?? error);
}
if (uploaded) {
...
...
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