Försöker att förbättra loggningen
This commit is contained in:
@@ -10,9 +10,18 @@ from utils import set_local_logger
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__) # Separate logger for this module
|
logger = logging.getLogger(__name__) # Separate logger for this module
|
||||||
set_local_logger(logger) # Set log level for logger
|
set_local_logger(logger) # Set log level for logger
|
||||||
|
logger.debug("Logging level of backend logger has been configured")
|
||||||
|
|
||||||
# Initialize a Flask application
|
# Initialize a Flask application
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.config['STATIC_FOLDER'] = 'static' # Adjust if needed
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/<path:filename>')
|
||||||
|
def serve_static(filename):
|
||||||
|
return send_from_directory(app.config['STATIC_FOLDER'], filename)
|
||||||
|
|
||||||
|
|
||||||
CORS(app, resources={
|
CORS(app, resources={
|
||||||
r"/api/chat": {
|
r"/api/chat": {
|
||||||
"origins": "*",
|
"origins": "*",
|
||||||
@@ -32,10 +41,8 @@ def chat(url_server = "http://localhost:11434/api/generate", model = "phi3:mini"
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
message = data.get('query')
|
message = data.get('query')
|
||||||
|
|
||||||
# print(f"data = {data}\nmessage = {message}")
|
|
||||||
logger.debug("data = %s\nmessage = %s", str(data), str(message))
|
logger.debug("data = %s\nmessage = %s", str(data), str(message))
|
||||||
try:
|
try:
|
||||||
# Alternative LLM: "model": "mannix/llama3-8b-ablitered-v3:latest",
|
|
||||||
url = url_server
|
url = url_server
|
||||||
model_to_use = model
|
model_to_use = model
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ def configure():
|
|||||||
Reads YAML configruation file into dictionary, parse it and fill all referenceed
|
Reads YAML configruation file into dictionary, parse it and fill all referenceed
|
||||||
environment variables with their values.
|
environment variables with their values.
|
||||||
"""
|
"""
|
||||||
##################
|
####################################
|
||||||
# Read YAML config
|
# Read YAML config
|
||||||
##################
|
####################################
|
||||||
# Load configuration file that defines parameters for services
|
# Load configuration file that defines parameters for services
|
||||||
with open('./smartassist/config/smartassist.yaml') as f:
|
with open('./smartassist/config/smartassist.yaml') as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
@@ -41,19 +41,17 @@ def configure():
|
|||||||
# Update the config dictionary with resolved environment variables
|
# Update the config dictionary with resolved environment variables
|
||||||
updated_config = update_dict_with_env_vars(config)
|
updated_config = update_dict_with_env_vars(config)
|
||||||
|
|
||||||
##################
|
####################################
|
||||||
# Extract global logging level
|
# 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
|
if isinstance(updated_config.get('logging'), dict): # Look for 'logging' key in config file
|
||||||
logging_config = updated_config['logging']
|
logging_config = updated_config['logging']
|
||||||
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
|
if isinstance(logging_config.get('level'), str): # Set to value of the yaml file if specified
|
||||||
utils.log_level = logging_config['level']
|
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
|
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
|
return updated_config
|
||||||
|
|
||||||
|
|
||||||
@@ -67,12 +65,12 @@ def start_frontend(config):
|
|||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
try:
|
try:
|
||||||
s.bind((hostname, port))
|
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
|
# Start frontend (web server) as a separate process
|
||||||
subprocess.Popen(["python", "-m", "http.server", str(port)])
|
subprocess.Popen(["python", "-m", "http.server", str(port)])
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.errno == 48:
|
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:
|
else:
|
||||||
raise # Unexpected error, re-raise it so we can see the traceback
|
raise # Unexpected error, re-raise it so we can see the traceback
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user