76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
from flask import Flask, request, jsonify
|
|
from flask_cors import CORS
|
|
from db import Base, engine
|
|
from models import User
|
|
from services.intent_service import IntentService
|
|
from services.mode_service import ModeService
|
|
from services.preference_service import PreferenceService
|
|
from services.suggestion_service import SuggestionService
|
|
from services.document_service import DocumentService
|
|
from services.search_service import SearchService
|
|
from services.monitoring_service import MonitoringService
|
|
from services.export_service import ExportService
|
|
from services.audit_service import AuditService
|
|
from services.security_service import SecurityService
|
|
|
|
app = Flask(__name__)
|
|
CORS(app)
|
|
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
intent_service = IntentService()
|
|
mode_service = ModeService()
|
|
preference_service = PreferenceService()
|
|
suggestion_service = SuggestionService()
|
|
document_service = DocumentService()
|
|
search_service = SearchService()
|
|
monitoring_service = MonitoringService()
|
|
export_service = ExportService()
|
|
audit_service = AuditService()
|
|
security_service = SecurityService()
|
|
|
|
USER_ID = 1
|
|
|
|
@app.route("/api/conversation", methods=["POST"])
|
|
def conversation():
|
|
data = request.json
|
|
message = data.get("message", "")
|
|
|
|
mode = mode_service.get_current_mode(USER_ID)
|
|
if not mode:
|
|
reply = (
|
|
"{user.name}, como você quer trabalhar hoje?\n\n"
|
|
"- Modo Advogado\n- Modo Corporativo\n- Apenas Conversar\n\n"
|
|
"Me diga qual modo você prefere agora."
|
|
)
|
|
return jsonify({"reply": reply, "suggestions": [], "quick_actions": []})
|
|
|
|
intent = intent_service.detect_intent(message)
|
|
prefs = preference_service.get_preferences(USER_ID)
|
|
|
|
if intent == "set_mode":
|
|
mode_service.set_mode(USER_ID, intent_service.extract_mode(message))
|
|
reply = f"Perfeito, vou atuar no modo {mode_service.get_current_mode(USER_ID)}. O que vamos fazer agora?"
|
|
return jsonify({"reply": reply, "suggestions": [], "quick_actions": []})
|
|
|
|
if intent == "document":
|
|
response = document_service.handle(message, mode, prefs)
|
|
elif intent == "search":
|
|
response = search_service.handle(message, mode, prefs)
|
|
elif intent == "monitoring":
|
|
response = monitoring_service.handle(message, mode, prefs)
|
|
else:
|
|
response = document_service.chat_like(message, mode, prefs)
|
|
|
|
suggestions = suggestion_service.generate_suggestions(response, intent, mode, prefs)
|
|
quick_actions = suggestion_service.generate_quick_actions(response, intent, mode, prefs)
|
|
|
|
return jsonify({
|
|
"reply": response["text"],
|
|
"suggestions": suggestions,
|
|
"quick_actions": quick_actions
|
|
})
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True)
|