quiz fixed

This commit is contained in:
2025-02-12 19:25:12 +00:00
parent d1ed8b9e3f
commit 35a099112b
4 changed files with 261 additions and 10 deletions
+3 -4
View File
@@ -20,7 +20,7 @@ from fastapi.responses import Response
from datetime import datetime
from fastapi import HTTPException
from pydantic import BaseModel
from typing import Optional, Union, Dict, Any
from typing import Optional, Union, Dict, Any,List,Optional, List, Tuple, Any
import os
import requests
import os
@@ -108,10 +108,9 @@ class QuizRequest(BaseModel):
class QuizResponse(BaseModel):
success: bool
message: str
quiz_data: Optional[Dict[str, Any]] = None
quiz_data: Optional[List[Any]] = None
error: Optional[str] = None
async def extract_pdf_text(pdf_url: str) -> Union[str, None]:
"""Extract text from PDF and handle potential errors."""
try:
@@ -435,4 +434,4 @@ async def startup_event():
if __name__ == "__main__":
import uvicorn
uvicorn.run("app:app", host="0.0.0.0", port=5042, reload=True)
uvicorn.run("app:app", host="0.0.0.0", port=5048, reload=True)
+134
View File
@@ -1225,5 +1225,139 @@
"timestamp": "2025-02-11T19:20:04.632908"
}
]
},
"eyfgsydfgyhfgh": {
"messages": [
{
"role": "human",
"content": "Let's get started",
"timestamp": "2025-02-11T20:39:33.360102"
},
{
"role": "ai",
"content": "Can you describe a time when you interacted with someone who had a visible or invisible disability during an emergency response? What was the situation, and how did you approach it?",
"timestamp": "2025-02-11T20:39:33.373817"
},
{
"role": "human",
"content": "i did as expected",
"timestamp": "2025-02-11T20:40:05.467696"
},
{
"role": "ai",
"content": "Can you elaborate on how you approached the situation with the individual who had a disability? What specific actions did you take to ensure their needs were met?",
"timestamp": "2025-02-11T20:40:05.480207"
},
{
"role": "human",
"content": "During the community health fair, I noticed the elderly man struggling to understand the information being presented due to his hearing impairment. Recognizing his discomfort, I immediately adjusted my approach. First, I made sure to face him directly and speak clearly, ensuring he could read my lips. I also used simple hand gestures to reinforce key points.\n\nAdditionally, I wrote down critical details on a notepad to provide a visual aid, making it easier for him to follow along. To further assist, I guided him to a quieter area where he could focus without distractions. Recognizing that accessibility is key, I connected him with a sign language interpreter who was available at the event.\n\nMy goal was to make sure he received the information he needed in a way that was comfortable for him. This experience reinforced the importance of adaptability and effective communication, especially when assisting individuals with disabilities.",
"timestamp": "2025-02-11T20:43:36.243236"
},
{
"role": "ai",
"content": "That's a great example of adaptability and communication. How did you feel about the impact your actions had on the elderly man? What was his response, and did it change how you view your role in emergency responses involving individuals with disabilities?",
"timestamp": "2025-02-11T20:43:36.251651"
},
{
"role": "human",
"content": "NOW GENERATE THE STARTPOP FRAMEWORK",
"timestamp": "2025-02-11T20:44:01.740609"
},
{
"role": "ai",
"content": "{\"theme_title\":\"Disability Questions\",\"question\":\"Can you describe a time when you interacted with someone who had a visible or invisible disability during an emergency response? What was the situation, and how did you approach it?\",\"Situation\":[\"During a community health fair, I noticed an elderly man struggling to understand the information being presented due to his hearing impairment.\",\"He appeared visibly uncomfortable and was missing key points from the presentation, which was causing him frustration.\",\"Recognizing the situation, I took it upon myself to ensure he received the necessary information in a way that suited his needs.\"],\"Task\":[\"My main task was to facilitate effective communication with the elderly man to ensure he could understand the health information being shared.\",\"I aimed to create an inclusive environment that respected his dignity and allowed him to engage with the material being presented.\"],\"Action\":[\"Negative: I could have ignored his struggles, assuming he would figure it out on his own, which would have left him feeling isolated.\",\"Negative: I could have spoken loudly without considering his hearing impairment, leading to misunderstanding and frustration.\",\"Positive: I faced him directly, spoke clearly, and used hand gestures to enhance communication.\",\"Positive: I wrote down critical details to provide visual support and guided him to a quieter area to minimize distractions.\"],\"Results and Transitions\":[\"The elderly man expressed gratitude for the assistance and was able to grasp the key information presented at the health fair.\",\"This experience highlighted the importance of adaptability and effective communication in emergency situations involving individuals with disabilities.\"],\"Personal Lessons\":[\"I learned the significance of recognizing and addressing the unique needs of individuals with disabilities during emergency responses.\",\"This situation reinforced my belief that effective communication is crucial for ensuring that everyone feels respected and included.\"],\"Observations of Others\":[\"I noticed other attendees observing how I interacted with the elderly man, which may have encouraged them to also be more considerate of others' needs.\",\"The sign language interpreter was engaged, and I could see the positive impact of our collaborative efforts.\"],\"Professional Connection\":[\"This experience aligns with ______ Fire's commitment to inclusivity and compassionate care for individuals with disabilities during emergencies.\",\"I appreciate how ______ Fire prioritizes training for firefighters to effectively communicate and assist all community members, including those with disabilities.\"]}",
"timestamp": "2025-02-11T20:44:01.746961"
},
{
"role": "human",
"content": "i do not like the task part pof the theem generated",
"timestamp": "2025-02-11T20:44:36.633029"
},
{
"role": "ai",
"content": "Thank you for your feedback! Can you clarify what specific aspects of the task section you would like to change or improve?",
"timestamp": "2025-02-11T20:44:36.639277"
},
{
"role": "human",
"content": "i write the second line better",
"timestamp": "2025-02-11T20:47:15.741450"
},
{
"role": "ai",
"content": "Please provide the revised second line for the task section, and I will incorporate it into the STARTPOP framework.",
"timestamp": "2025-02-11T20:47:15.747979"
},
{
"role": "human",
"content": "The second line that has to do with inclusive enveiroment ",
"timestamp": "2025-02-11T20:48:26.907776"
},
{
"role": "ai",
"content": "What would you like the second line of the task section to say regarding the inclusive environment? Please provide your revised version so I can update it accordingly.",
"timestamp": "2025-02-11T20:48:26.913888"
},
{
"role": "human",
"content": "just think of better replacxemnt ",
"timestamp": "2025-02-11T20:49:01.003105"
},
{
"role": "ai",
"content": "How about this for the second line of the task section: \"I aimed to ensure that he felt supported and respected throughout the interaction, allowing him to engage fully with the materials presented.\" Does this work for you?",
"timestamp": "2025-02-11T20:49:01.011260"
},
{
"role": "human",
"content": "okay this is fine ",
"timestamp": "2025-02-11T20:49:33.513221"
},
{
"role": "ai",
"content": "Great! Here\u2019s the updated STARTPOP framework with the revised task section:\n\n### STARTPOP Framework:\n- **Situation**: \n - During a community health fair, I noticed an elderly man struggling to understand the information being presented due to his hearing impairment.\n - He appeared visibly uncomfortable and was missing key points from the presentation, which was causing him frustration.\n - Recognizing the situation, I took it upon myself to ensure he received the necessary information in a way that suited his needs.\n\n- **Task**: \n - My main task was to facilitate effective communication with the elderly man to ensure he could understand the health information being shared.\n - I aimed to ensure that he felt supported and respected throughout the interaction, allowing him to engage fully with the materials presented.\n\n- **Action**: \n - Negative: I could have ignored his struggles, assuming he would figure it out on his own, which would have left him feeling isolated.\n - Negative: I could have spoken loudly without considering his hearing impairment, leading to misunderstanding and frustration.\n - Positive: I faced him directly, spoke clearly, and used hand gestures to enhance communication.\n - Positive: I wrote down critical details to provide visual support and guided him to a quieter area to minimize distractions.\n\n- **Results and Transitions**: \n - The elderly man expressed gratitude for the assistance and was able to grasp the key information presented at the health fair.\n - This experience highlighted the importance of adaptability and effective communication in emergency situations involving individuals with disabilities.\n\n- **Personal Lessons**: \n - I learned the significance of recognizing and addressing the unique needs of individuals with disabilities during emergency responses.\n - This situation reinforced my belief that effective communication is crucial for ensuring that everyone feels respected and included.\n\n- **Observations of Others**: \n - I noticed other attendees observing how I interacted with the elderly man, which may have encouraged them to also be more considerate of others' needs.\n - The sign language interpreter was engaged, and I could see the positive impact of our collaborative efforts.\n\n- **Professional Connection**: \n - This experience aligns with ______ Fire's commitment to inclusivity and compassionate care for individuals with disabilities during emergencies.\n - I appreciate how ______ Fire prioritizes training for firefighters to effectively communicate and assist all community members, including those with disabilities.",
"timestamp": "2025-02-11T20:49:33.522621"
},
{
"role": "human",
"content": "NOW GENERATE THE STARTPOP FRAMEWORK",
"timestamp": "2025-02-11T20:50:22.485491"
},
{
"role": "ai",
"content": "{\"theme_title\":\"Disability Questions\",\"question\":\"Can you describe a time when you interacted with someone who had a visible or invisible disability during an emergency response? What was the situation, and how did you approach it?\",\"Situation\":[\"During a community health fair, I noticed an elderly man struggling to understand the information being presented due to his hearing impairment.\",\"He appeared visibly uncomfortable and was missing key points from the presentation, which was causing him frustration.\",\"Recognizing the situation, I took it upon myself to ensure he received the necessary information in a way that suited his needs.\"],\"Task\":[\"My main task was to facilitate effective communication with the elderly man to ensure he could understand the health information being shared.\",\"I aimed to ensure that he felt supported and respected throughout the interaction, allowing him to engage fully with the materials presented.\"],\"Action\":[\"Negative: I could have ignored his struggles, assuming he would figure it out on his own, which would have left him feeling isolated.\",\"Negative: I could have spoken loudly without considering his hearing impairment, leading to misunderstanding and frustration.\",\"Positive: I faced him directly, spoke clearly, and used hand gestures to enhance communication.\",\"Positive: I wrote down critical details to provide visual support and guided him to a quieter area to minimize distractions.\"],\"Results and Transitions\":[\"The elderly man expressed gratitude for the assistance and was able to grasp the key information presented at the health fair.\",\"This experience highlighted the importance of adaptability and effective communication in emergency situations involving individuals with disabilities.\"],\"Personal Lessons\":[\"I learned the significance of recognizing and addressing the unique needs of individuals with disabilities during emergency responses.\",\"This situation reinforced my belief that effective communication is crucial for ensuring that everyone feels respected and included.\"],\"Observations of Others\":[\"I noticed other attendees observing how I interacted with the elderly man, which may have encouraged them to also be more considerate of others' needs.\",\"The sign language interpreter was engaged, and I could see the positive impact of our collaborative efforts.\"],\"Professional Connection\":[\"This experience aligns with ______ Fire's commitment to inclusivity and compassionate care for individuals with disabilities during emergencies.\",\"I appreciate how ______ Fire prioritizes training for firefighters to effectively communicate and assist all community members, including those with disabilities.\"]}",
"timestamp": "2025-02-11T20:50:22.496141"
},
{
"role": "human",
"content": "NOW GENERATE THE STARTPOP FRAMEWORK",
"timestamp": "2025-02-11T21:05:12.026471"
},
{
"role": "ai",
"content": "{\"theme_title\":\"Disability Questions\",\"question\":\"Can you describe a time when you interacted with someone who had a visible or invisible disability during an emergency response? What was the situation, and how did you approach it?\",\"Situation\":[\"During a community health fair, I noticed an elderly man struggling to understand the information being presented due to his hearing impairment.\",\"He appeared visibly uncomfortable and was missing key points from the presentation, which was causing him frustration.\",\"Recognizing the situation, I took it upon myself to ensure he received the necessary information in a way that suited his needs.\"],\"Task\":[\"My main task was to facilitate effective communication with the elderly man to ensure he could understand the health information being shared.\",\"I aimed to ensure that he felt supported and respected throughout the interaction, allowing him to engage fully with the materials presented.\"],\"Action\":[\"Negative: I could have ignored his struggles, assuming he would figure it out on his own, which would have left him feeling isolated.\",\"Negative: I could have spoken loudly without considering his hearing impairment, leading to misunderstanding and frustration.\",\"Positive: I faced him directly, spoke clearly, and used hand gestures to enhance communication.\",\"Positive: I wrote down critical details to provide visual support and guided him to a quieter area to minimize distractions.\"],\"Results and Transitions\":[\"The elderly man expressed gratitude for the assistance and was able to grasp the key information presented at the health fair.\",\"This experience highlighted the importance of adaptability and effective communication in emergency situations involving individuals with disabilities.\"],\"Personal Lessons\":[\"I learned the significance of recognizing and addressing the unique needs of individuals with disabilities during emergency responses.\",\"This situation reinforced my belief that effective communication is crucial for ensuring that everyone feels respected and included.\"],\"Observations of Others\":[\"I noticed other attendees observing how I interacted with the elderly man, which may have encouraged them to also be more considerate of others' needs.\",\"The sign language interpreter was engaged, and I could see the positive impact of our collaborative efforts.\"],\"Professional Connection\":[\"This experience aligns with ______ Fire's commitment to inclusivity and compassionate care for individuals with disabilities during emergencies.\",\"I appreciate how ______ Fire prioritizes training for firefighters to effectively communicate and assist all community members, including those with disabilities.\"]}",
"timestamp": "2025-02-11T21:05:12.032063"
},
{
"role": "human",
"content": "NOW GENERATE THE STARTPOP FRAMEWORK",
"timestamp": "2025-02-11T22:10:44.764456"
},
{
"role": "ai",
"content": "{\"theme_title\":\"Disability Questions\",\"question\":\"Can you describe a time when you interacted with someone who had a visible or invisible disability during an emergency response? What was the situation, and how did you approach it?\",\"Situation\":[\"During a community health fair, I noticed an elderly man struggling to understand the information being presented due to his hearing impairment.\",\"He appeared visibly uncomfortable and was missing key points from the presentation, which was causing him frustration.\",\"Recognizing the situation, I took it upon myself to ensure he received the necessary information in a way that suited his needs.\"],\"Task\":[\"My main task was to facilitate effective communication with the elderly man to ensure he could understand the health information being shared.\",\"I aimed to ensure that he felt supported and respected throughout the interaction, allowing him to engage fully with the materials presented.\"],\"Action\":[\"Negative: I could have ignored his struggles, assuming he would figure it out on his own, which would have left him feeling isolated.\",\"Negative: I could have spoken loudly without considering his hearing impairment, leading to misunderstanding and frustration.\",\"Positive: I faced him directly, spoke clearly, and used hand gestures to enhance communication.\",\"Positive: I wrote down critical details to provide visual support and guided him to a quieter area to minimize distractions.\"],\"Results and Transitions\":[\"The elderly man expressed gratitude for the assistance and was able to grasp the key information presented at the health fair.\",\"This experience highlighted the importance of adaptability and effective communication in emergency situations involving individuals with disabilities.\"],\"Personal Lessons\":[\"I learned the significance of recognizing and addressing the unique needs of individuals with disabilities during emergency responses.\",\"This situation reinforced my belief that effective communication is crucial for ensuring that everyone feels respected and included.\"],\"Observations of Others\":[\"I noticed other attendees observing how I interacted with the elderly man, which may have encouraged them to also be more considerate of others' needs.\",\"The sign language interpreter was engaged, and I could see the positive impact of our collaborative efforts.\"],\"Professional Connection\":[\"This experience aligns with ______ Fire's commitment to inclusivity and compassionate care for individuals with disabilities during emergencies.\",\"I appreciate how ______ Fire prioritizes training for firefighters to effectively communicate and assist all community members, including those with disabilities.\"]}",
"timestamp": "2025-02-11T22:10:44.775403"
},
{
"role": "human",
"content": "NOW GENERATE THE STARTPOP FRAMEWORK",
"timestamp": "2025-02-11T22:11:36.237209"
},
{
"role": "ai",
"content": "{\"theme_title\":\"Disability Questions\",\"question\":\"Can you describe a time when you interacted with someone who had a visible or invisible disability during an emergency response? What was the situation, and how did you approach it?\",\"Situation\":[\"During a community health fair, I noticed an elderly man struggling to understand the information being presented due to his hearing impairment.\",\"He appeared visibly uncomfortable and was missing key points from the presentation, which was causing him frustration.\",\"Recognizing the situation, I took it upon myself to ensure he received the necessary information in a way that suited his needs.\"],\"Task\":[\"My main task was to facilitate effective communication with the elderly man to ensure he could understand the health information being shared.\",\"I aimed to ensure that he felt supported and respected throughout the interaction, allowing him to engage fully with the materials presented.\"],\"Action\":[\"Negative: I could have ignored his struggles, assuming he would figure it out on his own, which would have left him feeling isolated.\",\"Negative: I could have spoken loudly without considering his hearing impairment, leading to misunderstanding and frustration.\",\"Positive: I faced him directly, spoke clearly, and used hand gestures to enhance communication.\",\"Positive: I wrote down critical details to provide visual support and guided him to a quieter area to minimize distractions.\"],\"Results and Transitions\":[\"The elderly man expressed gratitude for the assistance and was able to grasp the key information presented at the health fair.\",\"This experience highlighted the importance of adaptability and effective communication in emergency situations involving individuals with disabilities.\"],\"Personal Lessons\":[\"I learned the significance of recognizing and addressing the unique needs of individuals with disabilities during emergency responses.\",\"This situation reinforced my belief that effective communication is crucial for ensuring that everyone feels respected and included.\"],\"Observations of Others\":[\"I noticed other attendees observing how I interacted with the elderly man, which may have encouraged them to also be more considerate of others' needs.\",\"The sign language interpreter was engaged, and I could see the positive impact of our collaborative efforts.\"],\"Professional Connection\":[\"This experience aligns with ______ Fire's commitment to inclusivity and compassionate care for individuals with disabilities during emergencies.\",\"I appreciate how ______ Fire prioritizes training for firefighters to effectively communicate and assist all community members, including those with disabilities.\"]}",
"timestamp": "2025-02-11T22:11:36.243189"
}
]
}
}
+119 -5
View File
@@ -2,7 +2,8 @@ import os
import requests
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain_core.prompts.prompt import PromptTemplate
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser, JsonOutputParser
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
@@ -22,7 +23,7 @@ load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
llm_temp = ChatOpenAI(model="gpt-4o-mini", temperature=0.7,max_tokens=10000)
def generate_quiz(startpop_pdf, quiz_type=None) -> dict:
def generate_quiz1(startpop_pdf, quiz_type=None) -> dict:
try:
# Define the prompt template for generating the quiz
quiz_prompt = PromptTemplate(
@@ -32,13 +33,13 @@ You are an assistant designed to generate firefighter interview quizzes based on
### Quiz Types:
1. **Single Line Text Inputs**:
- Output format: `{"question": "Your question", "correct_answer": "Your correct answer"}`
- Output format: {{{{"question": "Your question", "correct_answer": "Your correct answer"}}}}
2. **Multiple Choice Questions**:
- Output format: `{"question": "Your question", "options": ["Option 1", "Option 2"], "correct_answer": "Correct Option"}`
- Output format: "{"question": "Your question", "options": ["Option 1", "Option 2"], "correct_answer": "Correct Option"}"
3. **True or False Questions**:
- Output format: `{"question": "Your question", "options": ["True", "False"], "correct_answer": "True or False"}`
- Output format: "{"question": "Your question", "options": ["True", "False"], "correct_answer": "True or False"}"
Each quiz must include a field called `"quiz_type"` with values `1`, `2`, or `3` corresponding to the quiz type.
@@ -122,3 +123,116 @@ QUIZ TYPE: {quiz_type}
return {}
import os
import json
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
# Load API key
api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=api_key) # Initialize OpenAI client
def generate_quiz(startpop_pdf: str, quiz_type: int) -> dict:
try:
# Define the system prompt
system_prompt = """
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are an assistant designed to generate firefighter interview quizzes based on the STARTPOP framework provided in a PDF document. Your task is to analyze the content of the PDF and create a quiz tailored to the specified quiz type.
### Quiz Types:
1. **Single Line Text Inputs**:
- Output format: "[{"question": "Your question", "correct_answer": "Your correct answer"}]"
2. **Multiple Choice Questions**:
- Output format: "[{"question": "Your question", "options": ["Option 1", "Option 2"], "correct_answer": "Correct Option"}]"
3. **True or False Questions**:
- Output format: "[{"question": "Your question", "options": ["True", "False"], "correct_answer": "True or False"}]"
Each quiz must include a field called `"quiz_type"` with values `1`, `2`, or `3` corresponding to the quiz type.
### Project Overview:
### Key Concepts in Firefighting:
Firefighter interviews evaluate candidates based on **7 Main Concepts** and **20 Important Themes**. These are used to assess alignment with firefighting principles, communication skills, problem-solving abilities, and overall competence.
#### 7 Main Concepts:
- High Performance Teams
- Situational Awareness
- Being a Great Problem Solver
- Customer Service
- Building Construction & Mechanical Aptitude
- Emergency Medicine Experience
- Mental & Physical Health
#### 20 Important Themes:
- Customer Service
- Conflict
- Challenge
- Leadership
- Stress
- Successful Team
- Diversity
- Mistake
- Unsuccessful Team
- Disagreement
- Bent a Rule
- Delivered a Difficult Message
- Displayed Integrity
- Took a Shortcut
- Didnt Follow the Rules
- Emergency Response
- Dealt with Disabilities
- Solved a Big Problem
- Continuous Improvement
- Handled Sensitive Information
#### STARTPOP Framework:
The STARTPOP framework enhances the STAR method by adding depth and variety to responses. Its components are:
1. **Situation**: Set up the context (dates, places, circumstances).
2. **Task**: Explain what needed to be done and why.
3. **Actions**: Outline both positive and negative approaches.
4. **Results**: Share outcomes in a time-specific manner.
5. **Transitions**: Ensure professional coherence.
6. **Personal Lessons**: Discuss what you learned.
7. **Other People Observations**: Share insights about others involved.
8. **Professional Connection**: Relate the experience to firefighting.
### Instructions:
- Analyze the provided STARTPOP PDF to extract relevant themes and concepts.
- Generate a quiz with x number of questions and be dynyamic that builds user confidence by focusing on interview-based scenarios.
- Avoid questions directly about the STARTPOP framework itself (e.g., "What is STARTPOP?").
- Use the specified quiz type (`quiz_type`) to determine the output format.
- Generate good number of questions for the complete quiz please, ay least 15 questions
- avoid putting ```json before or after text ,return only the json output....
NOTE !!! : THE PDF REFERENCES THE STARTPOP FRAME WORK FOR THE CURRENT USER THAT HAS BEEN FORMUALTED, BASED ON THIS YOU CREATE QUIZ FOR THE USER TO PREPARE FOR THE INTERVIEW, IT IS NOT AS IF YOU ARE JUST EXTRACTING QUESTIONS FIRECTLY FROM THIS PDF USING IT AS CONTEXT TO CREATE THE RIGHT QUIZ
NOTE !!: ```json before or after text ,return only the json output.... and stritcly follow the outoput format spoecificed above , do not change it
<|eot_id|><|start_header_id|>user<|end_header_id|>
""",
# OpenAI API call
response = client.chat.completions.create(
model="gpt-4o-mini",
temperature=0.7,
messages=[
{"role": "system", "content": f"{system_prompt}"},
{"role": "user", "content": f"STARTPOP FULL PDF: {startpop_pdf}"},
{"role": "user", "content": f"QUIZ TYPE: {quiz_type}"}
]
)
# Extract JSON response
print(response)
return json.loads(response.choices[0].message.content) # Already JSON formatted
except Exception as e:
print(f"Error: {e}")
return {}
+5 -1
View File
@@ -70,7 +70,11 @@ def fetch_conversation_history(conversation_id: str) -> List[Message]:
response = requests.get(url)
response.raise_for_status() # Raise an error for bad responses
data = response.json()["data"] # First JSON parse
data = json.loads(json.loads(data))
print(data)
#
data = json.loads(data)
print(f"Data {data}")
print(f"Type: {type(data)}")
# Parse the API response into Message objects
messages = []
for item in data: