diff --git a/blueprints/function_calling_blueprint.py b/blueprints/function_calling_blueprint.py index aeae2411..f9ad77d6 100644 --- a/blueprints/function_calling_blueprint.py +++ b/blueprints/function_calling_blueprint.py @@ -5,7 +5,7 @@ import requests import json -from utils.main import ( +from utils.pipelines.main import ( get_last_user_message, add_or_update_system_message, get_tools_specs, diff --git a/examples/filters/libretranslate_filter_pipeline.py b/examples/filters/libretranslate_filter_pipeline.py index 0c14ac8f..37a3547b 100644 --- a/examples/filters/libretranslate_filter_pipeline.py +++ b/examples/filters/libretranslate_filter_pipeline.py @@ -4,7 +4,7 @@ import requests import os -from utils.main import get_last_user_message, get_last_assistant_message +from utils.pipelines.main import get_last_user_message, get_last_assistant_message class Pipeline: diff --git a/main.py b/main.py index 6cec49c1..acccffe7 100644 --- a/main.py +++ b/main.py @@ -8,9 +8,9 @@ from typing import List, Union, Generator, Iterator -from utils.auth import bearer_security, get_current_user -from utils.main import get_last_user_message, stream_message_template -from utils.misc import convert_to_raw_url +from utils.pipelines.auth import bearer_security, get_current_user +from utils.pipelines.main import get_last_user_message, stream_message_template +from utils.pipelines.misc import convert_to_raw_url from contextlib import asynccontextmanager from concurrent.futures import ThreadPoolExecutor @@ -108,11 +108,19 @@ def get_all_pipelines(): 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) - spec.loader.exec_module(module) - print(f"Loaded module: {module.__name__}") - if hasattr(module, "Pipeline"): - return module.Pipeline() + try: + spec.loader.exec_module(module) + print(f"Loaded module: {module.__name__}") + if hasattr(module, "Pipeline"): + return module.Pipeline() + else: + raise Exception("No Pipeline class found") + + except Exception as e: + print(f"Error loading module: {module_name}") + print(e) + os.remove(module_path) return None diff --git a/utils/auth.py b/utils/pipelines/auth.py similarity index 100% rename from utils/auth.py rename to utils/pipelines/auth.py diff --git a/utils/main.py b/utils/pipelines/main.py similarity index 100% rename from utils/main.py rename to utils/pipelines/main.py diff --git a/utils/misc.py b/utils/pipelines/misc.py similarity index 100% rename from utils/misc.py rename to utils/pipelines/misc.py