mirror of
https://github.com/open-webui/pipelines
synced 2025-05-11 08:01:08 +00:00
Merge pull request #192 from zabirauf/u/zabirauf/pip-reqs
Adding ability to install requirements from frontmatter through the /pipelines/add API
This commit is contained in:
commit
45e3a215b4
38
main.py
38
main.py
@ -26,6 +26,7 @@ import time
|
||||
import json
|
||||
import uuid
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
from config import API_KEY, PIPELINES_DIR
|
||||
@ -105,12 +106,45 @@ def get_all_pipelines():
|
||||
|
||||
return pipelines
|
||||
|
||||
def parse_frontmatter(content):
|
||||
frontmatter = {}
|
||||
for line in content.split('\n'):
|
||||
if ':' in line:
|
||||
key, value = line.split(':', 1)
|
||||
frontmatter[key.strip().lower()] = value.strip()
|
||||
return frontmatter
|
||||
|
||||
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.")
|
||||
|
||||
async def load_module_from_path(module_name, module_path):
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
|
||||
try:
|
||||
# Read the module content
|
||||
with open(module_path, 'r') as file:
|
||||
content = file.read()
|
||||
|
||||
# Parse frontmatter
|
||||
frontmatter = {}
|
||||
if content.startswith('"""'):
|
||||
end = content.find('"""', 3)
|
||||
if end != -1:
|
||||
frontmatter_content = content[3:end]
|
||||
frontmatter = parse_frontmatter(frontmatter_content)
|
||||
|
||||
# Install requirements if specified
|
||||
if 'requirements' in frontmatter:
|
||||
install_frontmatter_requirements(frontmatter['requirements'])
|
||||
|
||||
# Load the module
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
print(f"Loaded module: {module.__name__}")
|
||||
if hasattr(module, "Pipeline"):
|
||||
|
Loading…
Reference in New Issue
Block a user