all setup reinitialized
This commit is contained in:
@@ -24,9 +24,6 @@ def allowed_file(filename):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@qs_b.route('/generate_questions_from_sop', methods=['POST'])
|
||||
@auth_check
|
||||
def generate_questions_from_sop_v2():
|
||||
@@ -58,7 +55,43 @@ def generate_questions_from_sop_v2():
|
||||
# Convert the Pydantic model to a dictionary and return as JSON
|
||||
return jsonify({"questions": questions_response.dict()}), 200
|
||||
|
||||
except ValidationError as ve:
|
||||
return jsonify({"error": "Validation Error", "message": str(ve)}), 400
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": "Internal Server Error", "message": str(e)}), 500
|
||||
return jsonify({"error": "Internal Server Error", "message": str(e)}), 500
|
||||
|
||||
|
||||
@qs_b.route('/generate_questions_from_sop-latest', methods=['POST'])
|
||||
@auth_check
|
||||
def generate_questions_from_sop_v3():
|
||||
if not request.is_json:
|
||||
return jsonify({"error": "Invalid input", "message": "Input data must be in JSON format."}), 400
|
||||
|
||||
input_data = request.get_json()
|
||||
|
||||
required_fields = ['sops', 'assessment_type', 'duration']
|
||||
for field in required_fields:
|
||||
if field not in input_data:
|
||||
return jsonify({"error": "Missing data", "message": f"'{field}' is required."}), 400
|
||||
|
||||
try:
|
||||
# Prepare the data for the generator
|
||||
generator_input = {
|
||||
"sops": input_data['sops'],
|
||||
"assessment_type": input_data['assessment_type'],
|
||||
"duration": input_data['duration']
|
||||
}
|
||||
|
||||
# Generate questions using the QuestionGenerator
|
||||
generator = QuestionsGeneratorV2()
|
||||
questions_response = generator.generate_questions_for_all(generator_input)
|
||||
|
||||
if not questions_response:
|
||||
return jsonify({"error": "Question generation failed", "message": "Could not generate questions from the provided data."}), 500
|
||||
|
||||
# Convert the Pydantic model to a dictionary and return as JSON
|
||||
return jsonify({"questions": questions_response}), 200
|
||||
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": "Internal Server Error", "message": str(e)}), 500
|
||||
|
||||
|
||||
@@ -14,10 +14,11 @@ class AssementQuestion(BaseModel):
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Dict
|
||||
|
||||
from typing import Optional
|
||||
|
||||
class Question(BaseModel):
|
||||
area_tag: int
|
||||
area_tag: Optional[int]
|
||||
area_name: str
|
||||
assigned_to: int
|
||||
questions: str
|
||||
role: int
|
||||
@@ -30,4 +31,7 @@ class Questions(BaseModel):
|
||||
questions: List[FrequencyQuestions]
|
||||
|
||||
class AssessmentQuestions(BaseModel):
|
||||
questions: Questions
|
||||
questions: Questions
|
||||
|
||||
class AllQuestions(BaseModel):
|
||||
questions : List[Question]
|
||||
@@ -118,6 +118,8 @@ def get_questions_prompt_v2():
|
||||
def get_questions_prompt_v3():
|
||||
prompt = """
|
||||
You are tasked with generating assessment questions for workers based on their SOPs. These questions should vary by assessment type (daily, weekly, biweekly), frequency number (e.g., day 2, week 3), and total duration (e.g., 6 weeks).
|
||||
|
||||
INPUT: SOPS
|
||||
|
||||
Guidelines:
|
||||
1. Generate yes/no questions relevant to each worker's SOP based on their role.
|
||||
@@ -149,4 +151,94 @@ def get_questions_prompt_v3():
|
||||
}
|
||||
}
|
||||
"""
|
||||
return prompt
|
||||
return prompt
|
||||
|
||||
|
||||
def get_questions_prompt_v5():
|
||||
prompt = """
|
||||
Comprehensive Assessment Question Generation Methodology
|
||||
|
||||
Objective:
|
||||
Generate a robust, long-term assessment framework for organizational performance evaluation, focusing on systematic and consistent monitoring of operational procedures.
|
||||
|
||||
Strategic Design Principles:
|
||||
1. Question Generation Framework:
|
||||
- Create a holistic set of assessment questions
|
||||
- Designed for sustained use across multiple assessment periods
|
||||
- Provides comprehensive organizational insight
|
||||
- Enables continuous performance tracking and improvement
|
||||
|
||||
2. Structural Requirements:
|
||||
a. Question Attributes:
|
||||
- Binary (Yes/No) response format
|
||||
- Directly mapped to specific organizational roles
|
||||
- Aligned with Standard Operating Procedures (SOPs)
|
||||
- Covers multiple performance dimensions
|
||||
|
||||
b. Taxonomical Tagging:
|
||||
- area_tag: Precise topic/domain identifier
|
||||
- role: Specific organizational role classification
|
||||
- assigned_to: Exact responsible team member identifier
|
||||
|
||||
3. Question Design Criteria:
|
||||
a. Content Depth:
|
||||
- Reveal operational effectiveness
|
||||
- Uncover potential process improvements
|
||||
- Highlight compliance and procedural adherence
|
||||
- Capture nuanced performance indicators
|
||||
|
||||
b. Evaluation Dimensions:
|
||||
- Operational efficiency
|
||||
- Quality control
|
||||
- Safety protocols
|
||||
- Procedural compliance
|
||||
- Resource utilization
|
||||
- Knowledge application
|
||||
- Risk management
|
||||
|
||||
4. Contextual Considerations:
|
||||
- Reflect current organizational structure
|
||||
- Adaptable to evolving operational landscapes
|
||||
- Maintain consistency in assessment approach
|
||||
- Support data-driven decision-making
|
||||
Tagging Requirements:
|
||||
- area_tag: Unique identifier for topic area
|
||||
- role: Corresponding role ID from SOP
|
||||
- assigned_to: Exact ID of specific team member responsible
|
||||
Output Specification:
|
||||
{
|
||||
"questions": {
|
||||
"items": [
|
||||
{
|
||||
"area_tag": int, # Domain/Topic Identifier
|
||||
"area_name":str # Name of the area
|
||||
"assigned_to": str, # Responsible Member ID
|
||||
"questions": str, # Assessment Query
|
||||
"role": int # Organizational Role Identifier
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Implementation Guidelines:
|
||||
- Develop questions that transcend mere compliance
|
||||
- Encourage reflective and proactive organizational learning
|
||||
- Ensure questions are clear, unambiguous, and actionable
|
||||
- Prioritize questions that drive continuous improvement
|
||||
|
||||
Critical Mandate:
|
||||
Craft questions that are:
|
||||
- Precise and targeted
|
||||
- Aligned with organizational SOPs
|
||||
- Capable of revealing substantive operational insights
|
||||
- Supportive of strategic organizational objectives
|
||||
NOTE: Generate at least 25 questions and can be more depending on the structure of the sop
|
||||
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
|
||||
|
||||
"""
|
||||
return prompt
|
||||
|
||||
@@ -197,3 +197,39 @@ class QuestionsGeneratorV2:
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def generate_questions_for_all(self,input_data, all_questions: List[Dict]=[]):
|
||||
try:
|
||||
sops = input_data['sops']
|
||||
assessment_type = input_data['assessment_type']
|
||||
total_duration = input_data['duration']
|
||||
|
||||
|
||||
# Chunk the SOPs into smaller pieces
|
||||
chunk_size = 1000
|
||||
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]
|
||||
|
||||
|
||||
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}"}
|
||||
],
|
||||
temperature=0.1,
|
||||
response_format=AllQuestions, # Ensure you specify the correct format
|
||||
max_tokens=6000
|
||||
)
|
||||
|
||||
questions_json = json.loads(response.choices[0].message.content)
|
||||
|
||||
# Add the questions to the shared list (using lock to avoid race conditions
|
||||
return questions_json
|
||||
except Exception as e:
|
||||
print(f"An error occurred while generating questions: {e}")
|
||||
return None
|
||||
Reference in New Issue
Block a user