- Corrections to tenant, catalog, and tenant_make
- Clean-up of tenant elements - ensure the chat_client get's it's initial call rifht.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
from flask import Flask, jsonify
|
||||
|
||||
from flask import Flask, jsonify, request
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
import logging.config
|
||||
|
||||
@@ -74,6 +75,13 @@ def create_app(config_file=None):
|
||||
|
||||
app.logger.info(f"EveAI Chat Client Started Successfully (PID: {os.getpid()})")
|
||||
app.logger.info("-------------------------------------------------------------------------------------------------")
|
||||
|
||||
# @app.before_request
|
||||
# def app_before_request():
|
||||
# app.logger.debug(f'App before request: {request.path} ===== Method: {request.method} =====')
|
||||
# app.logger.debug(f'Full URL: {request.url}')
|
||||
# app.logger.debug(f'Endpoint: {request.endpoint}')
|
||||
|
||||
return app
|
||||
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
<!-- Custom theme colors from tenant settings -->
|
||||
<style>
|
||||
:root {
|
||||
--primary-color: {{ customization.primary_color|default('#007bff') }};
|
||||
--secondary-color: {{ customization.secondary_color|default('#6c757d') }};
|
||||
--background-color: {{ customization.background_color|default('#ffffff') }};
|
||||
--text-color: {{ customization.text_color|default('#212529') }};
|
||||
--sidebar-color: {{ customization.sidebar_color|default('#f8f9fa') }};
|
||||
--primary-color: {{ customisation.primary_color|default('#007bff') }};
|
||||
--secondary-color: {{ customisation.secondary_color|default('#6c757d') }};
|
||||
--background-color: {{ customisation.background_color|default('#ffffff') }};
|
||||
--text-color: {{ customisation.text_color|default('#212529') }};
|
||||
--sidebar-color: {{ customisation.sidebar_color|default('#f8f9fa') }};
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -3,13 +3,32 @@ from flask import Blueprint, render_template, request, session, current_app, jso
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from common.extensions import db
|
||||
from common.models.user import Tenant, SpecialistMagicLinkTenant
|
||||
from common.models.user import Tenant, SpecialistMagicLinkTenant, TenantMake
|
||||
from common.models.interaction import SpecialistMagicLink, Specialist, ChatSession, Interaction
|
||||
from common.services.interaction.specialist_services import SpecialistServices
|
||||
from common.utils.database import Database
|
||||
from common.utils.chat_utils import get_default_chat_customisation
|
||||
|
||||
chat_bp = Blueprint('chat', __name__)
|
||||
chat_bp = Blueprint('chat_bp', __name__, url_prefix='/chat')
|
||||
|
||||
@chat_bp.before_request
|
||||
def log_before_request():
|
||||
current_app.logger.debug(f'Before request: {request.path} =====================================')
|
||||
|
||||
|
||||
@chat_bp.after_request
|
||||
def log_after_request(response):
|
||||
return response
|
||||
|
||||
|
||||
# @chat_bp.before_request
|
||||
# def before_request():
|
||||
# try:
|
||||
# mw_before_request()
|
||||
# except Exception as e:
|
||||
# current_app.logger.error(f'Error switching schema in Document Blueprint: {e}')
|
||||
# raise
|
||||
|
||||
|
||||
@chat_bp.route('/')
|
||||
def index():
|
||||
@@ -31,14 +50,12 @@ def chat(magic_link_code):
|
||||
current_app.logger.error(f"Invalid magic link code: {magic_link_code}")
|
||||
return render_template('error.html', message="Invalid magic link code.")
|
||||
|
||||
tenant_id = magic_link_tenant.tenant_id
|
||||
|
||||
# Get tenant information
|
||||
tenant_id = magic_link_tenant.tenant_id
|
||||
tenant = Tenant.query.get(tenant_id)
|
||||
if not tenant:
|
||||
current_app.logger.error(f"Tenant not found for ID: {tenant_id}")
|
||||
return render_template('error.html', message="Tenant not found.")
|
||||
|
||||
# Switch to tenant schema
|
||||
Database(tenant_id).switch_schema()
|
||||
|
||||
@@ -48,6 +65,12 @@ def chat(magic_link_code):
|
||||
current_app.logger.error(f"Specialist magic link not found in tenant schema: {tenant_id}")
|
||||
return render_template('error.html', message="Specialist configuration not found.")
|
||||
|
||||
# Get relevant TenantMake
|
||||
tenant_make = TenantMake.query.get(specialist_ml.tenant_make_id)
|
||||
if not tenant_make:
|
||||
current_app.logger.error(f"Tenant make not found: {specialist_ml.tenant_make_id}")
|
||||
return render_template('error.html', message="Tenant make not found.")
|
||||
|
||||
# Get specialist details
|
||||
specialist = Specialist.query.get(specialist_ml.specialist_id)
|
||||
if not specialist:
|
||||
@@ -55,13 +78,13 @@ def chat(magic_link_code):
|
||||
return render_template('error.html', message="Specialist not found.")
|
||||
|
||||
# Store necessary information in session
|
||||
session['tenant_id'] = tenant_id
|
||||
session['specialist_id'] = specialist_ml.specialist_id
|
||||
session['specialist_args'] = specialist_ml.specialist_args or {}
|
||||
session['magic_link_code'] = magic_link_code
|
||||
session['tenant'] = tenant.to_dict()
|
||||
session['specialist'] = specialist.to_dict()
|
||||
session['magic_link'] = specialist_ml.to_dict()
|
||||
session['tenant_make'] = tenant_make.to_dict()
|
||||
|
||||
# Get customisation options with defaults
|
||||
customisation = get_default_chat_customisation(tenant.chat_customisation_options)
|
||||
customisation = get_default_chat_customisation(tenant_make.chat_customisation_options)
|
||||
|
||||
# Start a new chat session
|
||||
session['chat_session_id'] = SpecialistServices.start_session()
|
||||
|
||||
Reference in New Issue
Block a user