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
ff1cd306
"test/git@developer.sourcefind.cn:OpenDAS/torchaudio.git" did not exist on "cf11427643edc4bf7681c0e425f0409eb21a7d28"
Commit
ff1cd306
authored
Jun 10, 2024
by
Timothy J. Baek
Browse files
refac
parent
aa7d2560
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
backend/apps/webui/main.py
backend/apps/webui/main.py
+2
-1
backend/apps/webui/routers/tools.py
backend/apps/webui/routers/tools.py
+15
-6
No files found.
backend/apps/webui/main.py
View file @
ff1cd306
...
@@ -39,6 +39,7 @@ app.state.config = AppConfig()
...
@@ -39,6 +39,7 @@ app.state.config = AppConfig()
app
.
state
.
config
.
ENABLE_SIGNUP
=
ENABLE_SIGNUP
app
.
state
.
config
.
ENABLE_SIGNUP
=
ENABLE_SIGNUP
app
.
state
.
config
.
JWT_EXPIRES_IN
=
JWT_EXPIRES_IN
app
.
state
.
config
.
JWT_EXPIRES_IN
=
JWT_EXPIRES_IN
app
.
state
.
AUTH_TRUSTED_EMAIL_HEADER
=
WEBUI_AUTH_TRUSTED_EMAIL_HEADER
app
.
state
.
config
.
SHOW_ADMIN_DETAILS
=
SHOW_ADMIN_DETAILS
app
.
state
.
config
.
SHOW_ADMIN_DETAILS
=
SHOW_ADMIN_DETAILS
...
@@ -55,7 +56,7 @@ app.state.config.BANNERS = WEBUI_BANNERS
...
@@ -55,7 +56,7 @@ app.state.config.BANNERS = WEBUI_BANNERS
app
.
state
.
config
.
ENABLE_COMMUNITY_SHARING
=
ENABLE_COMMUNITY_SHARING
app
.
state
.
config
.
ENABLE_COMMUNITY_SHARING
=
ENABLE_COMMUNITY_SHARING
app
.
state
.
MODELS
=
{}
app
.
state
.
MODELS
=
{}
app
.
state
.
AUTH_TRUSTED_EMAIL_HEADER
=
WEBUI_AUTH_TRUSTED_EMAIL_HEADER
app
.
state
.
TOOLS
=
{}
app
.
add_middleware
(
app
.
add_middleware
(
...
...
backend/apps/webui/routers/tools.py
View file @
ff1cd306
from
fastapi
import
Depends
,
FastAPI
,
HTTPException
,
status
from
fastapi
import
Depends
,
FastAPI
,
HTTPException
,
status
,
Request
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
typing
import
List
,
Union
,
Optional
from
typing
import
List
,
Union
,
Optional
...
@@ -20,8 +20,6 @@ from config import DATA_DIR
...
@@ -20,8 +20,6 @@ from config import DATA_DIR
TOOLS_DIR
=
f
"
{
DATA_DIR
}
/tools"
TOOLS_DIR
=
f
"
{
DATA_DIR
}
/tools"
os
.
makedirs
(
TOOLS_DIR
,
exist_ok
=
True
)
os
.
makedirs
(
TOOLS_DIR
,
exist_ok
=
True
)
TOOLS
=
{}
router
=
APIRouter
()
router
=
APIRouter
()
...
@@ -73,7 +71,9 @@ async def get_toolkits(user=Depends(get_admin_user)):
...
@@ -73,7 +71,9 @@ async def get_toolkits(user=Depends(get_admin_user)):
@
router
.
post
(
"/create"
,
response_model
=
Optional
[
ToolResponse
])
@
router
.
post
(
"/create"
,
response_model
=
Optional
[
ToolResponse
])
async
def
create_new_toolkit
(
form_data
:
ToolForm
,
user
=
Depends
(
get_admin_user
)):
async
def
create_new_toolkit
(
request
:
Request
,
form_data
:
ToolForm
,
user
=
Depends
(
get_admin_user
)
):
if
not
form_data
.
id
.
isidentifier
():
if
not
form_data
.
id
.
isidentifier
():
raise
HTTPException
(
raise
HTTPException
(
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
status_code
=
status
.
HTTP_400_BAD_REQUEST
,
...
@@ -90,6 +90,8 @@ async def create_new_toolkit(form_data: ToolForm, user=Depends(get_admin_user)):
...
@@ -90,6 +90,8 @@ async def create_new_toolkit(form_data: ToolForm, user=Depends(get_admin_user)):
tool_file
.
write
(
form_data
.
content
)
tool_file
.
write
(
form_data
.
content
)
toolkit_module
=
load_toolkit_module_from_path
(
form_data
.
id
,
toolkit_path
)
toolkit_module
=
load_toolkit_module_from_path
(
form_data
.
id
,
toolkit_path
)
TOOLS
=
request
.
app
.
state
.
TOOLS
TOOLS
[
form_data
.
id
]
=
toolkit_module
TOOLS
[
form_data
.
id
]
=
toolkit_module
specs
=
get_tools_specs
(
TOOLS
[
form_data
.
id
])
specs
=
get_tools_specs
(
TOOLS
[
form_data
.
id
])
...
@@ -139,7 +141,7 @@ async def get_toolkit_by_id(id: str, user=Depends(get_admin_user)):
...
@@ -139,7 +141,7 @@ async def get_toolkit_by_id(id: str, user=Depends(get_admin_user)):
@
router
.
post
(
"/id/{id}/update"
,
response_model
=
Optional
[
ToolModel
])
@
router
.
post
(
"/id/{id}/update"
,
response_model
=
Optional
[
ToolModel
])
async
def
update_toolkit_by_id
(
async
def
update_toolkit_by_id
(
id
:
str
,
form_data
:
ToolForm
,
user
=
Depends
(
get_admin_user
)
request
:
Request
,
id
:
str
,
form_data
:
ToolForm
,
user
=
Depends
(
get_admin_user
)
):
):
toolkit_path
=
os
.
path
.
join
(
TOOLS_DIR
,
f
"
{
id
}
.py"
)
toolkit_path
=
os
.
path
.
join
(
TOOLS_DIR
,
f
"
{
id
}
.py"
)
...
@@ -148,6 +150,8 @@ async def update_toolkit_by_id(
...
@@ -148,6 +150,8 @@ async def update_toolkit_by_id(
tool_file
.
write
(
form_data
.
content
)
tool_file
.
write
(
form_data
.
content
)
toolkit_module
=
load_toolkit_module_from_path
(
id
,
toolkit_path
)
toolkit_module
=
load_toolkit_module_from_path
(
id
,
toolkit_path
)
TOOLS
=
request
.
app
.
state
.
TOOLS
TOOLS
[
id
]
=
toolkit_module
TOOLS
[
id
]
=
toolkit_module
specs
=
get_tools_specs
(
TOOLS
[
id
])
specs
=
get_tools_specs
(
TOOLS
[
id
])
...
@@ -181,6 +185,11 @@ async def update_toolkit_by_id(
...
@@ -181,6 +185,11 @@ async def update_toolkit_by_id(
@
router
.
delete
(
"/id/{id}/delete"
,
response_model
=
bool
)
@
router
.
delete
(
"/id/{id}/delete"
,
response_model
=
bool
)
async
def
delete_toolkit_by_id
(
id
:
str
,
user
=
Depends
(
get_admin_user
)):
async
def
delete_toolkit_by_id
(
request
:
Request
,
id
:
str
,
user
=
Depends
(
get_admin_user
)):
result
=
Tools
.
delete_tool_by_id
(
id
)
result
=
Tools
.
delete_tool_by_id
(
id
)
if
result
:
TOOLS
=
request
.
app
.
state
.
TOOLS
del
TOOLS
[
id
]
return
result
return
result
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