diff --git a/smartassist/src/backend.py b/smartassist/src/backend.py index e29d957..40d598f 100644 --- a/smartassist/src/backend.py +++ b/smartassist/src/backend.py @@ -10,9 +10,18 @@ from utils import set_local_logger logger = logging.getLogger(__name__) # Separate logger for this module set_local_logger(logger) # Set log level for logger +logger.debug("Logging level of backend logger has been configured") # Initialize a Flask application app = Flask(__name__) +app.config['STATIC_FOLDER'] = 'static' # Adjust if needed + + +@app.route('/') +def serve_static(filename): + return send_from_directory(app.config['STATIC_FOLDER'], filename) + + CORS(app, resources={ r"/api/chat": { "origins": "*", @@ -32,10 +41,8 @@ def chat(url_server = "http://localhost:11434/api/generate", model = "phi3:mini" data = request.get_json() message = data.get('query') - # print(f"data = {data}\nmessage = {message}") logger.debug("data = %s\nmessage = %s", str(data), str(message)) try: - # Alternative LLM: "model": "mannix/llama3-8b-ablitered-v3:latest", url = url_server model_to_use = model data = { diff --git a/smartassist/src/startservices.py b/smartassist/src/startservices.py index 884c7fa..37b6719 100644 --- a/smartassist/src/startservices.py +++ b/smartassist/src/startservices.py @@ -17,9 +17,9 @@ def configure(): Reads YAML configruation file into dictionary, parse it and fill all referenceed environment variables with their values. """ - ################## + #################################### # Read YAML config - ################## + #################################### # Load configuration file that defines parameters for services with open('./smartassist/config/smartassist.yaml') as f: config = yaml.safe_load(f) @@ -41,19 +41,17 @@ def configure(): # Update the config dictionary with resolved environment variables updated_config = update_dict_with_env_vars(config) - ################## + #################################### # Extract global logging level - ################## - # The log_level variable will be used by the logger module to set the log level - # global log_level # Must be defined within function if referencing the global variable log_level defined outside this function + #################################### if isinstance(updated_config.get('logging'), dict): # Look for 'logging' key in config file logging_config = updated_config['logging'] if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified utils.log_level = logging_config['level'] + logger.info("Logging level set to: {}".format(utils.log_level)) - set_local_logger(logger) # Set log level for logger based on log_level - + logger.debug("Logging level of startservices' logger has been configured") return updated_config @@ -67,12 +65,12 @@ def start_frontend(config): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: try: s.bind((hostname, port)) - logger.info("No server is running on %s -— starting one.", parsed_url.netloc) + logger.debug("No server is running on %s -— starting one.", parsed_url.netloc) # Start frontend (web server) as a separate process subprocess.Popen(["python", "-m", "http.server", str(port)]) except socket.error as e: if e.errno == 48: - logger.error("A server is already running on %s -— will use this.", parsed_url.netloc) + logger.debug("A server is already running on %s -— will use this.", parsed_url.netloc) else: raise # Unexpected error, re-raise it so we can see the traceback except Exception as e: