added bot prediction for assessments

This commit is contained in:
2024-09-14 01:50:41 +00:00
parent 45bc62c745
commit cd8f499f97
14 changed files with 698 additions and 22 deletions
+62
View File
@@ -4,6 +4,7 @@ from werkzeug.utils import secure_filename
from src.services.chatbot import Chatbot
from src.utils.utils import delete_all_files_in_directory
from src.utils.document_loader import load_document
from src.services.chatbot import Chatbot
# Initialize the Blueprint
@@ -59,3 +60,64 @@ def validate_worker_document():
except Exception as e:
return jsonify({"error": "Internal Server Error", "message": str(e)}), 500
@bot.route('/predict_next_n_assessments', methods=['POST'])
def predict_next_n_assessments():
try:
# Retrieve JSON data from the request
data = request.get_json()
company_info = data.get('company_info')
companyid = data.get('companyid')
N = data.get('N')
if not company_info or not companyid or N is None:
return jsonify({"error": "Missing data", "message": "Company info, company ID, or N value not provided."}), 400
# Instantiate the chatbot service
chatbot = Chatbot()
# Call the prediction method
response = chatbot.predict_next_n_assessment(
company_info=company_info,
companyid=companyid,
N=N
)
if not response:
return jsonify({"error": "No predictions available", "message": "Prediction process failed."}), 400
return jsonify({"predictions": response}), 200
except Exception as e:
return jsonify({"error": "Internal Server Error", "message": str(e)}), 500
@bot.route('/use_bot_predict_assessments', methods=['POST'])
def use_bot_predict_assessments():
try:
# Retrieve JSON data from the request
data = request.get_json()
company_info = data.get('company_info')
companyid = data.get('companyid')
query = data.get('query')
if not company_info or not companyid or query is None:
return jsonify({"error": "Missing data", "message": "Company info, company ID, or query value not provided."}), 400
# Instantiate the chatbot service
chatbot = Chatbot()
# Call the prediction method
response = chatbot.predict_based_on_past_assessment(
company_info=company_info,
companyid=companyid,
query=query
)
if not response:
return jsonify({"error": "No predictions available", "message": "Prediction process failed."}), 400
return jsonify({"predictions": response}), 200
except Exception as e:
return jsonify({"error": "Internal Server Error", "message": str(e)}), 500