updated
This commit is contained in:
+106
-22
@@ -9,9 +9,70 @@ from src.models.sop_response_schemas import *
|
||||
from src.models.bot_response_schema import *
|
||||
from scripts.assessment_data import generate_summary_stats_v2
|
||||
from dotenv import load_dotenv
|
||||
from scripts.statistics_data import (generate_summary_stats,create_json_body,fetch_data)
|
||||
load_dotenv()
|
||||
|
||||
import random
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
import pandas as pd
|
||||
|
||||
# Define possible areas
|
||||
areas = [
|
||||
"Agile Methodologies", "API Development", "Code Review", "Collaboration with Cross-Functional Teams",
|
||||
"Continuous Integration/Continuous Deployment (CI/CD)", "Debugging Techniques", "Documentation",
|
||||
"Performance Optimization", "System Design", "Unit Testing", "Version Control"
|
||||
]
|
||||
|
||||
# Generate random dates
|
||||
def random_date():
|
||||
start_date = datetime(2024, 1, 1)
|
||||
return (start_date + timedelta(days=random.randint(1, 300))).strftime('%Y-%m-%dT00:00:00.000Z')
|
||||
|
||||
# Generate dummy assessments
|
||||
def generate_dummy_data(num_assessments=50, max_users_per_assessment=5):
|
||||
data = []
|
||||
for i in range(1, num_assessments + 1):
|
||||
assessment_id = str(i)
|
||||
assessment_name = f"Assessment {i}"
|
||||
start_date = random_date()
|
||||
red_flags = random.randint(0, 5)
|
||||
open_items = random.randint(0, 50)
|
||||
completed_items = random.randint(0, 50)
|
||||
total_assigned_items = open_items + completed_items
|
||||
|
||||
# Generate random users for each assessment
|
||||
user_details = []
|
||||
num_users = random.randint(1, max_users_per_assessment)
|
||||
for _ in range(num_users):
|
||||
user_name = f"User_{random.randint(1, 100)}"
|
||||
user_total_items = random.randint(1, 50)
|
||||
user_completed_items = random.randint(0, user_total_items)
|
||||
area_list = random.sample(areas, random.randint(1, 5))
|
||||
|
||||
user_details.append({
|
||||
"name": user_name,
|
||||
"total_assigned_items": user_total_items,
|
||||
"completed_items": user_completed_items,
|
||||
"area_list": area_list
|
||||
})
|
||||
|
||||
data.append({
|
||||
"assessment_id": assessment_id,
|
||||
"red_flags": red_flags,
|
||||
"open_items": open_items,
|
||||
"completed_items": completed_items,
|
||||
"total_assigned_items": total_assigned_items,
|
||||
"assessment_name": assessment_name,
|
||||
"start_date": start_date,
|
||||
"user_details": user_details
|
||||
})
|
||||
|
||||
return {"error": False, "data": data}
|
||||
|
||||
# Generate dummy data
|
||||
dummy_data = generate_dummy_data(num_assessments=100, max_users_per_assessment=5)
|
||||
#print(dummy_data)
|
||||
#SopGeneratorDocument
|
||||
class Chatbot:
|
||||
def __init__(self):
|
||||
@@ -123,10 +184,14 @@ class Chatbot:
|
||||
"""
|
||||
try:
|
||||
# Define the path to the company's assessment data (stored as a CSV)
|
||||
data_path = os.path.join('data', 'raw', 'erp_company_assessment', f'{companyid}_raw_data.csv')
|
||||
|
||||
# Generate summary statistics from the company's assessment data
|
||||
summary_stats = generate_summary_stats_v2(file_path=data_path)
|
||||
json_body_area = create_json_body("problematic-areas", companyid)
|
||||
json_body_assessment = create_json_body("user-stats-by-assessment", companyid)
|
||||
# Fetching data
|
||||
problematic_areas_data = fetch_data(json_body_area)
|
||||
assessment_data = fetch_data(json_body_assessment)
|
||||
|
||||
summary_stats = generate_summary_stats(assessment_data, problematic_areas_data)
|
||||
print(summary_stats)
|
||||
|
||||
|
||||
# Generate the prompt using the company info and the summary statistics
|
||||
@@ -164,7 +229,7 @@ class Chatbot:
|
||||
return None
|
||||
|
||||
|
||||
def predict_next_n_assessment(self, company_info, companyid, N) -> AssessmentPredictionsResponse:
|
||||
def predict_next_n_assessment(self,companyid, N) -> AssessmentPredictionsResponse:
|
||||
"""
|
||||
This method generates predictions based on past assessment data of a company. It queries the backend for the
|
||||
company's assessment data, generates a prompt, and then uses the GPT-4 model to return predictions based on the query.
|
||||
@@ -176,51 +241,62 @@ class Chatbot:
|
||||
:return: Result containing the prediction result or None if an error occurs.
|
||||
"""
|
||||
try:
|
||||
|
||||
json_body_area = create_json_body("problematic-areas", companyid)
|
||||
json_body_assessment = create_json_body("user-stats-by-assessment", companyid)
|
||||
# Fetching data
|
||||
problematic_areas_data = fetch_data(json_body_area)
|
||||
assessment_data = fetch_data(json_body_assessment)
|
||||
|
||||
summary_stats = generate_summary_stats(assessment_data, problematic_areas_data)
|
||||
print(summary_stats)
|
||||
# Define the path to the company's assessment data (stored as a CSV)
|
||||
data_path = os.path.join('data', 'raw', 'erp_company_assessment', f'{companyid}_raw_data.csv')
|
||||
#data_path = os.path.join('data', 'raw', 'erp_company_assessment', f'{companyid}_raw_data.csv')
|
||||
|
||||
# Generate summary statistics from the company's assessment data
|
||||
summary_stats = generate_summary_stats_v2(file_path=data_path)
|
||||
#summary_stats = generate_summary_stats_v2(file_path=data_path)
|
||||
|
||||
# Generate the prompt using the company info and the summary statistics
|
||||
prompt = predict_next_n_assessments_prompt()
|
||||
prompt = predict_next_n_assessments_prompt_v2()
|
||||
|
||||
|
||||
# Interact with GPT-4 model to get a response
|
||||
MODEL = "gpt-4o"
|
||||
response = self.client.beta.chat.completions.parse(
|
||||
model=self.model,
|
||||
model=MODEL,
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": f"{prompt}"
|
||||
},
|
||||
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"company info: {company_info}--> N-value is {N} ",
|
||||
"content": f"Summary stattistics of company past assessment: {summary_stats}",
|
||||
},
|
||||
{
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"Summary stats: {summary_stats}",
|
||||
"content": f"Number of next assessments to predict: {N}",
|
||||
}
|
||||
],
|
||||
response_format=AssessmentPredictionsResponse,
|
||||
#response_format=AssessmentPredictionsResponse,
|
||||
max_tokens=1024,
|
||||
temperature=0.1
|
||||
)
|
||||
|
||||
# Extract the response from the GPT-4 model
|
||||
extracted_text = json.loads(response.choices[0].message.content)
|
||||
preds = json.loads(response.choices[0].message.content)
|
||||
|
||||
# Initialize dictionary to store assessments with dynamic names
|
||||
predictions = {}
|
||||
#predictions = {}
|
||||
|
||||
# Loop through the predicted assessments and rename them dynamically
|
||||
for i in range(N):
|
||||
assessment_key = f"assessment_{i + 1}"
|
||||
predictions[assessment_key] = extracted_text["predictions"][i]['AssessmentN']
|
||||
#for i in range(N):
|
||||
#assessment_key = f"assessment_{i + 1}"
|
||||
#predictions[assessment_key] = extracted_text["predictions"][i]['AssessmentN']
|
||||
|
||||
# Return the dynamically named assessments
|
||||
return predictions
|
||||
return preds
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
@@ -279,10 +355,18 @@ class Chatbot:
|
||||
"""
|
||||
try:
|
||||
# Define the path to the company's assessment data (stored as a CSV)
|
||||
data_path = os.path.join('data', 'raw', 'erp_company_assessment', f'{companyid}_raw_data.csv')
|
||||
#data_path = os.path.join('data', 'raw', 'erp_company_assessment', f'{companyid}_raw_data.csv')
|
||||
|
||||
# Generate summary statistics from the company's assessment data
|
||||
summary_stats = generate_summary_stats_v2(file_path=data_path)
|
||||
#summary_stats = generate_summary_stats_v2(file_path=data_path)
|
||||
json_body_area = create_json_body("problematic-areas", companyid)
|
||||
json_body_assessment = create_json_body("user-stats-by-assessment", companyid)
|
||||
# Fetching data
|
||||
problematic_areas_data = fetch_data(json_body_area)
|
||||
assessment_data = fetch_data(json_body_assessment)
|
||||
|
||||
summary_stats = generate_summary_stats(assessment_data, problematic_areas_data)
|
||||
|
||||
|
||||
# Generate the prompt using the company info and the summary statistics
|
||||
prompt = predict_goal_achievement_probability_prompt()
|
||||
@@ -301,7 +385,7 @@ class Chatbot:
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"Summary stats: {summary_stats}",
|
||||
"content": f"Summary stats of past assement: {summary_stats}",
|
||||
}
|
||||
],
|
||||
response_format=AchievementPrediction,
|
||||
|
||||
Reference in New Issue
Block a user