Skip to content

Commit

Permalink
refac
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbck committed Jun 2, 2024
1 parent 5478b92 commit dd98a71
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion blueprints/function_calling_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/filters/libretranslate_filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 15 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit dd98a71

Please sign in to comment.