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
367fa039
Commit
367fa039
authored
Aug 08, 2024
by
Jan-Timo Hesse
Browse files
added install_frontmatter_requirements
parent
71d88fe3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
backend/apps/webui/utils.py
backend/apps/webui/utils.py
+13
-0
No files found.
backend/apps/webui/utils.py
View file @
367fa039
from
importlib
import
util
import
os
import
re
import
sys
import
subprocess
from
config
import
TOOLS_DIR
,
FUNCTIONS_DIR
...
...
@@ -52,6 +54,7 @@ def load_toolkit_module_by_id(toolkit_id):
frontmatter
=
extract_frontmatter
(
toolkit_path
)
try
:
install_frontmatter_requirements
(
frontmatter
.
get
(
"requirements"
,
""
))
spec
.
loader
.
exec_module
(
module
)
print
(
f
"Loaded module:
{
module
.
__name__
}
"
)
if
hasattr
(
module
,
"Tools"
):
...
...
@@ -73,6 +76,7 @@ def load_function_module_by_id(function_id):
frontmatter
=
extract_frontmatter
(
function_path
)
try
:
install_frontmatter_requirements
(
frontmatter
.
get
(
"requirements"
,
""
))
spec
.
loader
.
exec_module
(
module
)
print
(
f
"Loaded module:
{
module
.
__name__
}
"
)
if
hasattr
(
module
,
"Pipe"
):
...
...
@@ -88,3 +92,12 @@ def load_function_module_by_id(function_id):
# Move the file to the error folder
os
.
rename
(
function_path
,
f
"
{
function_path
}
.error"
)
raise
e
def
install_frontmatter_requirements
(
requirements
):
if
requirements
:
req_list
=
[
req
.
strip
()
for
req
in
requirements
.
split
(
','
)]
for
req
in
req_list
:
print
(
f
"Installing requirement:
{
req
}
"
)
subprocess
.
check_call
([
sys
.
executable
,
"-m"
,
"pip"
,
"install"
,
req
])
else
:
print
(
"No requirements found in frontmatter."
)
\ No newline at end of file
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