(20241212) Reorganizing code to perform core actions in one place.
This commit is contained in:
+40
-54
@@ -70,13 +70,20 @@ from utils_v2.api.async_quart import (
|
||||
# GMail-related utils:
|
||||
from utils_v2.goog.gmail.gmail_client import AsyncGMailClient
|
||||
|
||||
# Behaviour Models:
|
||||
from models.behaviour.mail.oauth_v3 import MailOAuthModel
|
||||
from models.behaviour.mail.sync_v3 import MailSyncModel
|
||||
from models.behaviour.mail.retrieve import MailRetrieveModel
|
||||
from models.behaviour.sms.auth_v2 import SMSAuthModel
|
||||
from models.behaviour.sms.send import SMSSendModel
|
||||
from models.behaviour.ai.llm.open_ai import LLMOpenAI
|
||||
# Core Controller Models:
|
||||
from controllers.core.message import MessageController
|
||||
from controllers.core.auth_token import AuthTokenController
|
||||
from controllers.core.ai.llm import LLMController
|
||||
|
||||
# API Controller Models:
|
||||
from controllers.api.mail import MailController
|
||||
|
||||
# # Old Behaviour Models:
|
||||
# from controllers.mail.oauth_v3 import MailOAuthModel
|
||||
# from controllers.mail.sync_v3 import MailSyncModel
|
||||
# from controllers.mail.retrieve import MailRetrieveModel
|
||||
# from controllers.sms.auth_v2 import SMSAuthModel
|
||||
# from controllers.sms.send import SMSSendModel
|
||||
|
||||
# To make REST API calls:
|
||||
import httpx
|
||||
@@ -87,13 +94,13 @@ from icecream import IceCreamDebugger
|
||||
# All the blueprints:
|
||||
from api.blueprints.mail.oauth_request import mail_oauth_bp
|
||||
from api.blueprints.mail.oauth_callback import mail_callback_bp
|
||||
from api.blueprints.mail.sync import mail_sync_bp
|
||||
from api.blueprints.mail.list import mail_list_bp
|
||||
from api.blueprints.mail.retrieve import mail_retrieve_bp
|
||||
from api.blueprints.sms.auth import sms_auth_bp
|
||||
from api.blueprints.sms.send import sms_send_bp
|
||||
from api.blueprints.chat.auth import chat_auth_bp
|
||||
from api.blueprints.chat.webhook import chat_webhook_bp
|
||||
# from api.blueprints.mail.sync_v2 import mail_sync_bp
|
||||
# from api.blueprints.mail.list import mail_list_bp
|
||||
# from api.blueprints.mail.retrieve import mail_retrieve_bp
|
||||
# from api.blueprints.sms.auth import sms_auth_bp
|
||||
# from api.blueprints.sms.send import sms_send_bp
|
||||
# from api.blueprints.chat.auth import chat_auth_bp
|
||||
# from api.blueprints.chat.webhook import chat_webhook_bp
|
||||
from api.blueprints.tech.chat_alerts import tech_chat_alert_bp
|
||||
from api.blueprints.test.callback import test_callback_bp
|
||||
from api.blueprints.ai.llm.invoke import llm_invoke_bp
|
||||
@@ -126,13 +133,13 @@ app = Quart(__name__, template_folder = r"../views")
|
||||
app = cors(app)
|
||||
app.register_blueprint(mail_oauth_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_callback_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_sync_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_list_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_retrieve_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(sms_auth_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
app.register_blueprint(sms_send_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
app.register_blueprint(chat_webhook_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
# app.register_blueprint(mail_sync_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
# app.register_blueprint(mail_list_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
# app.register_blueprint(mail_retrieve_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
# app.register_blueprint(sms_auth_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
# app.register_blueprint(sms_send_bp, url_prefix = f"/{MODULE_BASE}/sms")
|
||||
# app.register_blueprint(chat_auth_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
# app.register_blueprint(chat_webhook_bp, url_prefix = f"/{MODULE_BASE}/chat")
|
||||
app.register_blueprint(tech_chat_alert_bp, url_prefix = f"/{MODULE_BASE}/tech/alert")
|
||||
app.register_blueprint(test_callback_bp, url_prefix = f"/{MODULE_BASE}/test")
|
||||
app.register_blueprint(llm_invoke_bp, url_prefix = f"/{MODULE_BASE}/ai")
|
||||
@@ -318,53 +325,32 @@ async def app_startup(**kwargs):
|
||||
|
||||
current_app.printer("MongoDB ready.")
|
||||
|
||||
# ┳ ┓ ┳┳┓ ┓ ┓
|
||||
# ┃┏┓╋┏┓┏┓┏┓┏┓┃ ┃┃┃┏┓┏┫┏┓┃┏
|
||||
# ┻┛┗┗┗ ┛ ┛┗┗┻┗ ┛ ┗┗┛┗┻┗ ┗┛
|
||||
# ┏┓ ┳┳┓ ┓ ┓
|
||||
# ┃ ┏┓┏┓┏┓ ┃┃┃┏┓┏┫┏┓┃┏
|
||||
# ┗┛┗┛┛ ┗ ┛ ┗┗┛┗┻┗ ┗┛
|
||||
|
||||
current_app.mail_oauth_model = MailOAuthModel(
|
||||
current_app.core_message_controller = MessageController(
|
||||
cache = current_app.module_cache,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
http_client = current_app.http_client,
|
||||
debug = enable_debugging,
|
||||
debug_prefix = "Mail-OAuth | ",
|
||||
debug_prefix = "Message (CM) | ",
|
||||
debug_only_errors = True
|
||||
)
|
||||
current_app.mail_sync_model = MailSyncModel(
|
||||
current_app.core_auth_token_controller = AuthTokenController(
|
||||
cache = current_app.module_cache,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
http_client = current_app.http_client,
|
||||
debug = enable_debugging,
|
||||
debug_prefix = "Mail-Sync | ",
|
||||
debug_only_errors = True
|
||||
)
|
||||
current_app.mail_retrieve_model = MailRetrieveModel(
|
||||
cache = current_app.module_cache,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
http_client = current_app.http_client,
|
||||
debug = enable_debugging,
|
||||
debug_prefix = "Mail-Retr | ",
|
||||
debug_prefix = "Message (CM) | ",
|
||||
debug_only_errors = True
|
||||
)
|
||||
|
||||
current_app.sms_auth_model = SMSAuthModel(
|
||||
cache = current_app.module_cache,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
http_client = current_app.http_client,
|
||||
debug = enable_debugging,
|
||||
debug_prefix = "SMS-Auth | ",
|
||||
debug_only_errors = True
|
||||
)
|
||||
current_app.sms_send_model = SMSSendModel(
|
||||
cache = current_app.module_cache,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
http_client = current_app.http_client,
|
||||
debug = enable_debugging,
|
||||
debug_prefix = "SMS-Send | ",
|
||||
debug_only_errors = True
|
||||
)
|
||||
# ┏┓┏┓┳ ┏┓ ┓┓
|
||||
# ┣┫┃┃┃ ┃ ┏┓┏┓╋┏┓┏┓┃┃┏┓┏┓┏
|
||||
# ┛┗┣┛┻ ┗┛┗┛┛┗┗┛ ┗┛┗┗┗ ┛ ┛
|
||||
|
||||
current_app.printer("Internal models ready.")
|
||||
current_app.mail_controller = MailController()
|
||||
|
||||
# ┏┓ ┓ ┏┓┓•
|
||||
# ┃ ┏┓┏┓┏┓┏┓┏╋┏┓┏┓┏ ┏┓┏┓┏┫ ┃ ┃┓┏┓┏┓╋┏
|
||||
@@ -389,7 +375,7 @@ async def app_startup(**kwargs):
|
||||
# ┛
|
||||
|
||||
# For LLMs:
|
||||
current_app.llm = LLMOpenAI(
|
||||
current_app.llm = LLMController(
|
||||
llm_creds = {
|
||||
"model": script_cred["openAi"]["model"],
|
||||
"openai_api_key": script_cred["openAi"]["openai_api_key"]
|
||||
|
||||
Reference in New Issue
Block a user