From 2c5cd6f6cf2a11253f68d781d38d51a8885e52e0 Mon Sep 17 00:00:00 2001 From: unclecode Date: Thu, 14 Mar 2024 12:24:20 +0800 Subject: [PATCH] Address #4: Brief description of the fix https://github.com/unclecode/funckycall/issues/4 - Creates the log folder if doesn't exist - Fixed the issue for routing a normal chat message Further testing is required before closing the issue. --- app/libs/chains.py | 2 +- app/main.py | 2 -- app/providers.py | 3 +++ app/utils.py | 8 ++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/libs/chains.py b/app/libs/chains.py index ac01a83..14ec4e0 100644 --- a/app/libs/chains.py +++ b/app/libs/chains.py @@ -288,7 +288,7 @@ class DefaultCompletionHandler(Handler): async def handle(self, context: Context): if context.is_normal_chat: # Assuming context.client is set and has a method for creating chat completions - completion = await context.client.chat.completions.create( + completion = context.client.route( messages=context.messages, **context.client.clean_params(context.params), ) diff --git a/app/main.py b/app/main.py index 98e100f..0de8dc3 100644 --- a/app/main.py +++ b/app/main.py @@ -5,8 +5,6 @@ from starlette.requests import Request from routes import proxy from routes import examples - - from utils import create_logger import os from dotenv import load_dotenv diff --git a/app/providers.py b/app/providers.py index 47f21ee..17229c2 100644 --- a/app/providers.py +++ b/app/providers.py @@ -13,6 +13,9 @@ def __init__(self, api_key: str, base_url = None): def route(self, model: str, messages: list, **kwargs): pass + async def route_async(self, model: str, messages: list, **kwargs): + pass + def clean_params(self, params): pass diff --git a/app/utils.py b/app/utils.py index 66c5d3c..dc84a46 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,10 +1,14 @@ import logging +import os # To be developed -def create_logger(lof_path:str = ".logs/access.log"): +def create_logger(log_path:str = ".logs/access.log"): + log_dir = os.path.dirname(log_path) + if not os.path.exists(log_dir): + os.makedirs(log_dir) logger = logging.getLogger("app") logger.setLevel(logging.DEBUG) - file_handler = logging.FileHandler(lof_path) + file_handler = logging.FileHandler(log_path) file_handler.setLevel(logging.DEBUG) formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") file_handler.setFormatter(formatter)