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
05fade14
Unverified
Commit
05fade14
authored
Jan 04, 2024
by
ThatOneCalculator
Browse files
chore:
🎨
format backend
parent
8480a9b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
21 deletions
+26
-21
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+10
-9
backend/apps/ollama/old_main.py
backend/apps/ollama/old_main.py
+13
-11
backend/main.py
backend/main.py
+3
-1
No files found.
backend/apps/ollama/main.py
View file @
05fade14
...
@@ -30,7 +30,8 @@ async def get_ollama_api_url(user=Depends(get_current_user)):
...
@@ -30,7 +30,8 @@ async def get_ollama_api_url(user=Depends(get_current_user)):
if
user
and
user
.
role
==
"admin"
:
if
user
and
user
.
role
==
"admin"
:
return
{
"OLLAMA_API_BASE_URL"
:
app
.
state
.
OLLAMA_API_BASE_URL
}
return
{
"OLLAMA_API_BASE_URL"
:
app
.
state
.
OLLAMA_API_BASE_URL
}
else
:
else
:
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
class
UrlUpdateForm
(
BaseModel
):
class
UrlUpdateForm
(
BaseModel
):
...
@@ -38,14 +39,14 @@ class UrlUpdateForm(BaseModel):
...
@@ -38,14 +39,14 @@ class UrlUpdateForm(BaseModel):
@
app
.
post
(
"/url/update"
)
@
app
.
post
(
"/url/update"
)
async
def
update_ollama_api_url
(
async
def
update_ollama_api_url
(
form_data
:
UrlUpdateForm
,
form_data
:
UrlUpdateForm
,
user
=
Depends
(
get_current_user
)
user
=
Depends
(
get_current_user
)):
):
if
user
and
user
.
role
==
"admin"
:
if
user
and
user
.
role
==
"admin"
:
app
.
state
.
OLLAMA_API_BASE_URL
=
form_data
.
url
app
.
state
.
OLLAMA_API_BASE_URL
=
form_data
.
url
return
{
"OLLAMA_API_BASE_URL"
:
app
.
state
.
OLLAMA_API_BASE_URL
}
return
{
"OLLAMA_API_BASE_URL"
:
app
.
state
.
OLLAMA_API_BASE_URL
}
else
:
else
:
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
@
app
.
api_route
(
"/{path:path}"
,
methods
=
[
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
])
@
app
.
api_route
(
"/{path:path}"
,
methods
=
[
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
])
...
@@ -58,11 +59,11 @@ async def proxy(path: str, request: Request, user=Depends(get_current_user)):
...
@@ -58,11 +59,11 @@ async def proxy(path: str, request: Request, user=Depends(get_current_user)):
if
user
.
role
in
[
"user"
,
"admin"
]:
if
user
.
role
in
[
"user"
,
"admin"
]:
if
path
in
[
"pull"
,
"delete"
,
"push"
,
"copy"
,
"create"
]:
if
path
in
[
"pull"
,
"delete"
,
"push"
,
"copy"
,
"create"
]:
if
user
.
role
!=
"admin"
:
if
user
.
role
!=
"admin"
:
raise
HTTPException
(
raise
HTTPException
(
status_code
=
401
,
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
)
else
:
else
:
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
raise
HTTPException
(
status_code
=
401
,
detail
=
ERROR_MESSAGES
.
ACCESS_PROHIBITED
)
headers
.
pop
(
"Host"
,
None
)
headers
.
pop
(
"Host"
,
None
)
headers
.
pop
(
"Authorization"
,
None
)
headers
.
pop
(
"Authorization"
,
None
)
...
...
backend/apps/ollama/old_main.py
View file @
05fade14
from
flask
import
Flask
,
request
,
Response
,
jsonify
from
flask
import
Flask
,
request
,
Response
,
jsonify
from
flask_cors
import
CORS
from
flask_cors
import
CORS
import
requests
import
requests
import
json
import
json
from
apps.web.models.users
import
Users
from
apps.web.models.users
import
Users
from
constants
import
ERROR_MESSAGES
from
constants
import
ERROR_MESSAGES
from
utils.utils
import
decode_token
from
utils.utils
import
decode_token
...
@@ -77,7 +75,9 @@ def update_ollama_api_url():
...
@@ -77,7 +75,9 @@ def update_ollama_api_url():
)
)
@
app
.
route
(
"/"
,
defaults
=
{
"path"
:
""
},
methods
=
[
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
])
@
app
.
route
(
"/"
,
defaults
=
{
"path"
:
""
},
methods
=
[
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
])
@
app
.
route
(
"/<path:path>"
,
methods
=
[
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
])
@
app
.
route
(
"/<path:path>"
,
methods
=
[
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
])
def
proxy
(
path
):
def
proxy
(
path
):
# Combine the base URL of the target server with the requested path
# Combine the base URL of the target server with the requested path
...
@@ -106,13 +106,17 @@ def proxy(path):
...
@@ -106,13 +106,17 @@ def proxy(path):
pass
pass
else
:
else
:
return
(
return
(
jsonify
({
"detail"
:
ERROR_MESSAGES
.
ACCESS_PROHIBITED
}),
jsonify
({
"detail"
:
ERROR_MESSAGES
.
ACCESS_PROHIBITED
}),
401
,
401
,
)
)
else
:
else
:
pass
pass
else
:
else
:
return
jsonify
({
"detail"
:
ERROR_MESSAGES
.
ACCESS_PROHIBITED
}),
401
return
jsonify
(
{
"detail"
:
ERROR_MESSAGES
.
ACCESS_PROHIBITED
}),
401
else
:
else
:
return
jsonify
({
"detail"
:
ERROR_MESSAGES
.
UNAUTHORIZED
}),
401
return
jsonify
({
"detail"
:
ERROR_MESSAGES
.
UNAUTHORIZED
}),
401
else
:
else
:
...
@@ -162,12 +166,10 @@ def proxy(path):
...
@@ -162,12 +166,10 @@ def proxy(path):
print
(
res
)
print
(
res
)
return
(
return
(
jsonify
(
jsonify
({
{
"detail"
:
error_detail
,
"detail"
:
error_detail
,
"message"
:
str
(
e
),
"message"
:
str
(
e
),
}),
}
),
400
,
400
,
)
)
...
...
backend/main.py
View file @
05fade14
...
@@ -50,4 +50,6 @@ app.mount("/api/v1", webui_app)
...
@@ -50,4 +50,6 @@ app.mount("/api/v1", webui_app)
# app.mount("/ollama/api", WSGIMiddleware(ollama_app))
# app.mount("/ollama/api", WSGIMiddleware(ollama_app))
app
.
mount
(
"/ollama/api"
,
ollama_app
)
app
.
mount
(
"/ollama/api"
,
ollama_app
)
app
.
mount
(
"/"
,
SPAStaticFiles
(
directory
=
"../build"
,
html
=
True
),
name
=
"spa-static-files"
)
app
.
mount
(
"/"
,
SPAStaticFiles
(
directory
=
"../build"
,
html
=
True
),
name
=
"spa-static-files"
)
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