mirror of
https://github.com/open-webui/open-webui
synced 2025-02-22 05:08:14 +00:00
fix: tools & function not installing requirements
This commit is contained in:
parent
14eda1bf5b
commit
02d5bca44d
@ -65,6 +65,7 @@ def replace_imports(content):
|
|||||||
|
|
||||||
|
|
||||||
def load_toolkit_module_by_id(toolkit_id, content=None):
|
def load_toolkit_module_by_id(toolkit_id, content=None):
|
||||||
|
|
||||||
if content is None:
|
if content is None:
|
||||||
tool = Tools.get_tool_by_id(toolkit_id)
|
tool = Tools.get_tool_by_id(toolkit_id)
|
||||||
if not tool:
|
if not tool:
|
||||||
@ -74,6 +75,10 @@ def load_toolkit_module_by_id(toolkit_id, content=None):
|
|||||||
|
|
||||||
content = replace_imports(content)
|
content = replace_imports(content)
|
||||||
Tools.update_tool_by_id(toolkit_id, {"content": content})
|
Tools.update_tool_by_id(toolkit_id, {"content": content})
|
||||||
|
else:
|
||||||
|
frontmatter = extract_frontmatter(content)
|
||||||
|
# Install required packages found within the frontmatter
|
||||||
|
install_frontmatter_requirements(frontmatter.get("requirements", ""))
|
||||||
|
|
||||||
module_name = f"tool_{toolkit_id}"
|
module_name = f"tool_{toolkit_id}"
|
||||||
module = types.ModuleType(module_name)
|
module = types.ModuleType(module_name)
|
||||||
@ -82,16 +87,9 @@ def load_toolkit_module_by_id(toolkit_id, content=None):
|
|||||||
try:
|
try:
|
||||||
# Executing the modified content in the created module's namespace
|
# Executing the modified content in the created module's namespace
|
||||||
exec(content, module.__dict__)
|
exec(content, module.__dict__)
|
||||||
|
frontmatter = extract_frontmatter(content)
|
||||||
# Extract frontmatter, assuming content can be treated directly as a string
|
|
||||||
frontmatter = extract_frontmatter(
|
|
||||||
content
|
|
||||||
) # Ensure this method is adaptable to handle content strings
|
|
||||||
|
|
||||||
# Install required packages found within the frontmatter
|
|
||||||
install_frontmatter_requirements(frontmatter.get("requirements", ""))
|
|
||||||
|
|
||||||
print(f"Loaded module: {module.__name__}")
|
print(f"Loaded module: {module.__name__}")
|
||||||
|
|
||||||
# Create and return the object if the class 'Tools' is found in the module
|
# Create and return the object if the class 'Tools' is found in the module
|
||||||
if hasattr(module, "Tools"):
|
if hasattr(module, "Tools"):
|
||||||
return module.Tools(), frontmatter
|
return module.Tools(), frontmatter
|
||||||
@ -112,6 +110,9 @@ def load_function_module_by_id(function_id, content=None):
|
|||||||
|
|
||||||
content = replace_imports(content)
|
content = replace_imports(content)
|
||||||
Functions.update_function_by_id(function_id, {"content": content})
|
Functions.update_function_by_id(function_id, {"content": content})
|
||||||
|
else:
|
||||||
|
frontmatter = extract_frontmatter(content)
|
||||||
|
install_frontmatter_requirements(frontmatter.get("requirements", ""))
|
||||||
|
|
||||||
module_name = f"function_{function_id}"
|
module_name = f"function_{function_id}"
|
||||||
module = types.ModuleType(module_name)
|
module = types.ModuleType(module_name)
|
||||||
@ -120,15 +121,7 @@ def load_function_module_by_id(function_id, content=None):
|
|||||||
try:
|
try:
|
||||||
# Execute the modified content in the created module's namespace
|
# Execute the modified content in the created module's namespace
|
||||||
exec(content, module.__dict__)
|
exec(content, module.__dict__)
|
||||||
|
frontmatter = extract_frontmatter(content)
|
||||||
# Extract the frontmatter from the content, simulate file-like behaviour
|
|
||||||
frontmatter = extract_frontmatter(
|
|
||||||
content
|
|
||||||
) # This function needs to handle string inputs
|
|
||||||
|
|
||||||
# Install necessary requirements specified in frontmatter
|
|
||||||
install_frontmatter_requirements(frontmatter.get("requirements", ""))
|
|
||||||
|
|
||||||
print(f"Loaded module: {module.__name__}")
|
print(f"Loaded module: {module.__name__}")
|
||||||
|
|
||||||
# Create appropriate object based on available class type in the module
|
# Create appropriate object based on available class type in the module
|
||||||
|
Loading…
Reference in New Issue
Block a user