added goal achievment preditions
This commit is contained in:
@@ -183,3 +183,94 @@ class Chatbot:
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def recommend_assessment_frequencies(self,sops) -> AssessmentSuggestion:
|
||||
"""
|
||||
|
||||
Process the SOPs data and return assessment frequencies.
|
||||
|
||||
|
||||
"""
|
||||
try:
|
||||
|
||||
chunk_size = 1000 # Define your chunk size
|
||||
# Convert the 'sops' dictionary values into a single text string for chunking
|
||||
sops_text = '\n'.join([str(item) for sublist in sops.values() for item in sublist])
|
||||
|
||||
# Break the text into chunks of the defined size
|
||||
docs_text = [sops_text[i:i + chunk_size] for i in range(0, len(sops_text), chunk_size)]
|
||||
|
||||
# Create a list of documents
|
||||
docs = [{"type": "text", "text": text} for text in docs_text]
|
||||
# Generate the prompt using the company info and the summary statistics
|
||||
|
||||
prompt = recommend_assessment_frequency_prompt() # Update your prompt to handle managers and workers
|
||||
|
||||
response = self.client.beta.chat.completions.parse(
|
||||
model=self.model,
|
||||
messages=[
|
||||
{"role": "system", "content": prompt},
|
||||
{"role": "user", "content": docs}
|
||||
],
|
||||
response_format=AssessmentSuggestion, # Use the updated response schema
|
||||
max_tokens=4096,
|
||||
temperature=0.1
|
||||
)
|
||||
|
||||
return json.loads(response.choices[0].message.content)
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def predict_goal_achievement_probability(self, company_info, companyid) -> AchievementPrediction:
|
||||
"""
|
||||
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.
|
||||
|
||||
:param company_info: General information about the company (name, size, departments, etc.).
|
||||
:param companyid: Unique identifier of the company to fetch its specific data.
|
||||
:return: Result containing the prediction result or None if an error occurs.
|
||||
"""
|
||||
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)
|
||||
|
||||
# Generate the prompt using the company info and the summary statistics
|
||||
prompt = predict_goal_achievement_probability_prompt()
|
||||
|
||||
# Interact with GPT-4 model to get a response
|
||||
response = self.client.beta.chat.completions.parse(
|
||||
model=self.model,
|
||||
messages=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": prompt
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"company info: {company_info}",
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": f"Summary stats: {summary_stats}",
|
||||
}
|
||||
],
|
||||
response_format=AchievementPrediction,
|
||||
max_tokens=1024,
|
||||
temperature=0.1
|
||||
)
|
||||
|
||||
# Extract the response from the GPT-4 model
|
||||
predictions = json.loads(response.choices[0].message.content)
|
||||
# Return the dynamically named assessments
|
||||
return predictions
|
||||
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user