multiple area tags

This commit is contained in:
teslim
2025-07-08 15:20:10 +01:00
parent 31d85a83e7
commit d654707751
7 changed files with 45 additions and 29 deletions
-2
View File
@@ -47,8 +47,6 @@ def validate_worker_document():
# Validate the worker's response using the provided document
validation_result = chatbot.validate_worker(question, docs)
print(validation_result)
if not validation_result:
return jsonify({"error": "Validation failed", "message": "Validation process failed."}), 400
+4
View File
@@ -80,6 +80,10 @@ def generate_questions_from_sop_v3():
"assessment_type": input_data['assessment_type'],
"duration": input_data['duration']
}
# Add area_tags if provided in the payload (optional)
if 'area_tags' in input_data:
generator_input['area_tags'] = input_data['area_tags']
# Generate questions using the QuestionGenerator
generator = QuestionsGeneratorV2()
+4 -15
View File
@@ -1,17 +1,3 @@
'''from pydantic import BaseModel
from typing import List, Dict
class Question(BaseModel):
assigned_to: str
role: str
questions: str
area_tag:str
class AssementQuestion(BaseModel):
number: int
questions: List[Question]'''
from pydantic import BaseModel
from typing import List, Dict
from typing import Optional
@@ -33,5 +19,8 @@ class Questions(BaseModel):
class AssessmentQuestions(BaseModel):
questions: Questions
class AllQuestionsItems(BaseModel):
items: List[Question]
class AllQuestions(BaseModel):
questions : List[Question]
questions: AllQuestionsItems
+19 -2
View File
@@ -236,8 +236,25 @@ def get_questions_prompt_v5():
NOTE: !!! MAKE SURE YOU CORRECTLY ATTACH "assigned_to" AS THE ID OF THE MEMBER OF THE ROLE AS STATED IN THE SOP. CHECK MEMBERS UNDER THE ROLE IN THE PROVIDED SOP AND USE THE CORRECT ID OF THE MEMBER, DO NOT USE MEMBER iD THAT IS NOT PROVIDED AS "assigned_to" pls FOLLOW THIS STRICTLY!!!
NOTE: CHECK THE "role_id" UNDER THE PROVIDED SOP AND USE THE CORRECT ID OF THE ROLE, DO NOT USE OR FORMULATE "role_id" THAT IS NOT PROVIDED AS "role" pls FOLLOW THIS STRICTLY!!!
NOTE: IF area tags is not provided for specicfic role SOPS, kindly formulate an area name based on the sop and make the area_tag null but forumlate rea name, only do this if area tags info is not provided for specific role sops
NOTE: Use exactly the area names provided if available unless area tags is missing and you need to forumalate one
NOTE: IF area tags is not provided for specific role SOPS, kindly formulate an area name based on the sop and make the area_tag null but formulate area name, only do this if area tags info is not provided for specific role sops
NOTE: Use exactly the area names provided if available unless area tags is missing and you need to formulate one
CRITICAL AREA DIVERSIFICATION REQUIREMENT:
When area_tags are not provided or the area_tags array is empty, you MUST generate questions across AT LEAST 2-3 DIFFERENT area_names. Do NOT generate all questions under a single area_name. Analyze the SOPs and create diverse area_names such as:
- "Communication & Coordination"
- "Process Compliance"
- "Quality Assurance"
- "Timeline Management"
- "Technical Execution"
- "Safety Protocols"
- "Documentation & Reporting"
- "Resource Management"
- "Performance Monitoring"
- "Risk Assessment"
- "Training & Development"
- "Customer Relations"
MANDATORY: Distribute your questions across these different area_names to ensure comprehensive coverage of the organizational processes. Each area_name should have multiple questions assigned to it. Do not concentrate all questions in one area - this defeats the purpose of comprehensive assessment.
"""
return prompt
+1 -1
View File
@@ -77,7 +77,7 @@ dummy_data = generate_dummy_data(num_assessments=100, max_users_per_assessment=5
#SopGeneratorDocument
class Chatbot:
def __init__(self):
self.api_key = os.getenv("OPENAI_API_KEY") or "sk-svcacct-v2m4jSLxCTLR-WizUhZnkOHEuftWNVy2k7vIGWDGJogaBr5VogTTVT3BlbkFJjCxOowETlz7muR8eAS7ExO1NA7kvcrZ4HVhS66jxK8PpvNce1kAAA"
self.api_key = os.getenv("OPENAI_API_KEY")
self.client = OpenAI(api_key=self.api_key)
self.model = "gpt-4o-mini"
+16 -8
View File
@@ -16,7 +16,6 @@ load_dotenv()
class QuestionsGenerator:
def __init__(self):
self.api_key = os.getenv("OPENAI_API_KEY")
self.client = OpenAI(api_key=self.api_key)
self.model = "gpt-4o-mini"
def generate_questions(self, input_data: Dict) -> AssessmentQuestions:
@@ -204,6 +203,7 @@ class QuestionsGeneratorV2:
sops = input_data['sops']
assessment_type = input_data['assessment_type']
total_duration = input_data['duration']
area_tags = input_data.get('area_tags', []) # Get area_tags if provided, default to empty list
# Chunk the SOPs into smaller pieces
@@ -211,16 +211,24 @@ class QuestionsGeneratorV2:
docs_text = [sops[i:i + chunk_size] for i in range(0, len(sops), chunk_size)]
docs = [{"type": "text", "text": text} for text in docs_text]
# Prepare messages for the API call
messages = [
{"role": "system", "content": get_questions_prompt_v5()},
{"role": "user", "content": f"The SOPs are provided below."},
{"role": "user", "content": json.dumps(docs)},
{"role": "user", "content": f"Assessment Type: {assessment_type}"},
{"role": "user", "content": f"Duration: {total_duration}"}
]
# Add area_tags information if provided
if area_tags:
messages.append({"role": "user", "content": f"Available Area Tags: {json.dumps(area_tags)}"})
else:
messages.append({"role": "user", "content": "Area Tags: Not provided (empty array) - Please generate questions across multiple diverse area_names as instructed."})
response = self.client.beta.chat.completions.parse(
model=self.model,
messages=[
{"role": "system", "content": get_questions_prompt_v5()},
{"role": "user", "content": f"The SOPs are provided below."},
{"role": "user", "content": json.dumps(docs)},
{"role": "user", "content": f"Assessment Type: {assessment_type}"},
{"role": "user", "content": f"Duration: {total_duration}"}
],
messages=messages,
temperature=0.1,
response_format=AllQuestions, # Ensure you specify the correct format
max_tokens=6000
+1 -1
View File
@@ -4,7 +4,7 @@ from flask import Flask, session, redirect, url_for, request, g, jsonify
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv("API_KEY") or "erp_3bb0e4be8508494bb23621fc10e76a7d"
API_KEY = os.getenv("API_KEY")
def auth_check(func):
@wraps(func)