Compare commits
7 Commits
60ad3d109b
...
7c9d20896e
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c9d20896e | |||
| ce5532e9a6 | |||
| feb7e61fd8 | |||
| 9a9b1388ce | |||
| 61974859bd | |||
| bf165d8181 | |||
| fbcac82bbf |
@@ -4,7 +4,7 @@ frontend:
|
|||||||
|
|
||||||
# Backend Configuration
|
# Backend Configuration
|
||||||
backend:
|
backend:
|
||||||
url: "http://localhost:5005"
|
url: "http://localhost:5004"
|
||||||
api: "/api/chat"
|
api: "/api/chat"
|
||||||
|
|
||||||
# Ollama Server Configuration
|
# Ollama Server Configuration
|
||||||
@@ -15,11 +15,13 @@ ollama:
|
|||||||
# model: "llama3:70b" # Select a model supported by the Ollama server
|
# model: "llama3:70b" # Select a model supported by the Ollama server
|
||||||
# model: "llama3:latest" # Select a model supported by the Ollama server
|
# model: "llama3:latest" # Select a model supported by the Ollama server
|
||||||
# model: "mannix/llama3-8b-ablitered-v3:latest" # Select a model supported by the Ollama server
|
# model: "mannix/llama3-8b-ablitered-v3:latest" # Select a model supported by the Ollama server
|
||||||
model: "mistral-nemo:latest" # Select a model supported by the Ollama server
|
# model: "mistral-nemo:latest" # Select a model supported by the Ollama server
|
||||||
|
model: "gemma2:27b"
|
||||||
|
|
||||||
# Logging – comment out the whole section for default level which is INFO
|
# Logging – comment out the whole section for default level which is INFO
|
||||||
logging:
|
logging:
|
||||||
level: DEBUG # Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
level: DEBUG # Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
||||||
|
# level: INFO # Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
||||||
|
|
||||||
# Additional Configuration Options (Optional – ignored for now)
|
# Additional Configuration Options (Optional – ignored for now)
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,20 @@ from flask_cors import CORS, cross_origin # CORS stands for Cross-Origin Resourc
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from utils import set_local_logger
|
# 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")
|
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.config['STATIC_FOLDER'] = 'static' # Adjust if needed
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
api_endpoint = os.environ['BE_API_ENDPOINT'] # Retrieve the environment variable
|
||||||
|
return render_template('index.html', api_endpoint=api_endpoint)
|
||||||
|
|
||||||
@app.route('/<path:filename>')
|
@app.route('/<path:filename>')
|
||||||
def serve_static(filename):
|
def serve_static(filename):
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
const chatbox = document.getElementById('chatbox');
|
const chatbox = document.getElementById('chatbox');
|
||||||
const userInput = document.getElementById('userInput');
|
const userInput = document.getElementById('userInput');
|
||||||
|
|
||||||
|
// Get API endpoint for chat from environment variable
|
||||||
|
const apiEndpoint = process.env.BE_API_ENDPOINT || 'http://localhost:5005/api/chat'; // Default if not found
|
||||||
|
console.log("The API Endpoint is:", apiEndpoint);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Define a function to send the user's message to the AI
|
// Define a function to send the user's message to the AI
|
||||||
function sendMessage() {
|
function sendMessage() {
|
||||||
// Get the user's input message and trim any whitespace
|
// Get the user's input message and trim any whitespace
|
||||||
@@ -11,7 +17,8 @@ function sendMessage() {
|
|||||||
// Check if the message is not empty
|
// Check if the message is not empty
|
||||||
if (query !== '') {
|
if (query !== '') {
|
||||||
// Send a POST request to the /api/chat endpoint with the message
|
// Send a POST request to the /api/chat endpoint with the message
|
||||||
fetch('http://localhost:5005/api/chat', {
|
// fetch('http://localhost:5005/api/chat', {
|
||||||
|
fetch(apiEndpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ query }),
|
body: JSON.stringify({ query }),
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import socket
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
import logging
|
import logging
|
||||||
import utils
|
import utils
|
||||||
from utils import set_local_logger
|
from utils import configure_logging
|
||||||
from backend import run_flask
|
from backend import run_flask
|
||||||
|
|
||||||
logger = logging.getLogger(__name__) # Logger for this module
|
configure_logging() # Configure root logger. The level will be adjusted later based on config file
|
||||||
|
logger = logging.getLogger(__name__) # Logger for this module, inherit properties of the root logger
|
||||||
|
|
||||||
def configure():
|
def configure():
|
||||||
"""
|
"""
|
||||||
@@ -45,13 +46,32 @@ def configure():
|
|||||||
# Extract global logging level
|
# Extract global logging level
|
||||||
####################################
|
####################################
|
||||||
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.info("found key 'logging' 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
|
||||||
|
# logging.info("found key 'level' in config file")
|
||||||
utils.log_level = logging_config['level']
|
utils.log_level = logging_config['level']
|
||||||
logger.info("Logging level set to: {}".format(utils.log_level))
|
numeric_log_level = getattr(logging, utils.log_level, None)
|
||||||
|
|
||||||
|
rlogger = logging.getLogger() # Get the root logger
|
||||||
|
rlogger.setLevel(numeric_log_level)
|
||||||
|
# set_local_logger(logger) # Set log level for logger based on log_level
|
||||||
|
logger.info("Global variable utils.log_level set to: {}".format(utils.log_level))
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# Extract and export API endpoint as
|
||||||
|
# envrionment variable
|
||||||
|
####################################
|
||||||
|
backend_api_ep = 'http://localhost:5005/api/chat' # Default API endpoint
|
||||||
|
if isinstance(updated_config.get('backend'), dict): # Look for 'backend' key in config file
|
||||||
|
if isinstance(updated_config['backend'].get('url'), str): # Look for 'url' key in config file
|
||||||
|
url = updated_config['backend'].get('url')
|
||||||
|
if isinstance(updated_config['backend'].get('api'), str): # Look for 'api' key in config file
|
||||||
|
api = updated_config['backend'].get('api')
|
||||||
|
backend_api_ep = url+api # Extract API endpoint if defined
|
||||||
|
logger.debug("BE_API_ENDPOINT is set to '{}'".format(backend_api_ep))
|
||||||
|
os.environ['BE_API_ENDPOINT'] = backend_api_ep
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Frontend</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
const apiEndpoint = '<%= api_endpoint %>'; // Templating syntax (Jinja2)
|
||||||
|
console.log("API Endpoint:", apiEndpoint);
|
||||||
|
|
||||||
|
// Use apiEndpoint in your frontend code...
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
+27
-12
@@ -3,20 +3,35 @@
|
|||||||
# is that it is easier to avoid circular imports when they are defined in a central location.
|
# is that it is easier to avoid circular imports when they are defined in a central location.
|
||||||
import logging
|
import logging
|
||||||
global log_level # Remember, in Python globals are only global in the module it is defined in
|
global log_level # Remember, in Python globals are only global in the module it is defined in
|
||||||
log_level = 'INFO' # Default logging level
|
log_level = 'INFO' # Default logging level if not specified in config file
|
||||||
|
|
||||||
|
def configure_logging(level=log_level):
|
||||||
def set_local_logger(log_instance):
|
|
||||||
"""
|
"""
|
||||||
Configure logging based on the global variable log_level
|
Set up logging for the project. This is the root logger instance.
|
||||||
Logging is controlled by integer values, where DEBUG < INFO < WARNING < ERROR < CRITICAL.
|
All child loggers inherit from this logger.
|
||||||
To turn off logging completely, set numeric_log_level to at least CRITICAL + 1.
|
|
||||||
"""
|
"""
|
||||||
global log_level
|
numeric_level = getattr(logging, level.upper()) # Convert string to numeric level
|
||||||
numeric_log_level = getattr(logging, log_level, None)
|
|
||||||
if not isinstance(numeric_log_level, int):
|
|
||||||
raise ValueError('Invalid log level: %s' % log_level)
|
|
||||||
|
|
||||||
logging.basicConfig(level=numeric_log_level) # Set the root logger level to the configured level
|
logger = logging.getLogger() # Get the root logger
|
||||||
log_instance.info('Log level set to {}'.format(log_level)) # Example usage of the logger
|
logger.setLevel(numeric_level)
|
||||||
|
|
||||||
|
handler = logging.StreamHandler() # Or other handler (FileHandler for logs to file)
|
||||||
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
# To be removed?
|
||||||
|
# def set_local_logger(log_instance):
|
||||||
|
# """
|
||||||
|
# Configure logging based on the global variable log_level
|
||||||
|
# Logging is controlled by integer values, where DEBUG < INFO < WARNING < ERROR < CRITICAL.
|
||||||
|
# To turn off logging completely, set numeric_log_level to at least CRITICAL + 1.
|
||||||
|
# """
|
||||||
|
# global log_level
|
||||||
|
# numeric_log_level = getattr(logging, log_level, None)
|
||||||
|
# if not isinstance(numeric_log_level, int):
|
||||||
|
# raise ValueError('Invalid log level: %s' % log_level)
|
||||||
|
|
||||||
|
# log_instance.basicConfig(level=numeric_log_level) # Set the root logger level to the configured level
|
||||||
|
# log_instance.info('Current log level set to {}'.format(log_instance.getLogger().getEffectiveLevel())) # Example usage of the logger
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user