diff --git a/.gitignore b/.gitignore index e0b92af..7016039 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ src/next-env.d.ts __pycache__ pythonvenv -*.env \ No newline at end of file +*.env +apikey.txt \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f94e3b2 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "groundbreakinglabs", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/src/api/index.py b/src/api/index.py index 6950a90..cc9b1d6 100644 --- a/src/api/index.py +++ b/src/api/index.py @@ -7,10 +7,65 @@ from bson.json_util import dumps as bson_dumps from bson.raw_bson import RawBSONDocument from bson.objectid import ObjectId +import random +import bson +import json + +from prompt import generate load_dotenv() app = Flask(__name__) +PROMPT = { + "Passage": " \nThe Lame Bake-Off\nIt was an exciting day in the small town of Sweetville. The annual Grand Bake-Off was about to begin! This event brought together the best bakers in the town to show off their delicious creations. People came from near and far to watch and taste the mouthwatering treats.\nOne of the participants was Emma, a 10-year-old girl with a passion for baking. She loved experimenting with different flavors and ingredients to create unique desserts. For the Bake-Off, Emma decided to make her famous chocolate chip cookies with a twist\u2013 she added a caramel filling.\nAs the judges took their seats at the front of the room, Emma nervously arranged her cookies on a beautifully decorated plate. She couldn't wait for the judges to taste her creation. The Bake-Off was about to begin!\nEach participant presented their dish one by one, explaining the ingredients and techniques used. There were pies, cakes, cookies, and even a towering chocolate fountain. The room filled with the sweet aroma of freshly baked goods.\nFinally, it was Emma's turn. She confidently described her caramel-filled chocolate chip cookies, showcasing her baking skills to the judges. As they took a bite, their faces lit up with delight. The judges were impressed by the combination of the gooey caramel and the soft, melt-in-your-mouth cookies.\nAfter tasting all the delicious treats, the judges had the difficult task of selecting the winners. The participants anxiously waited for the results. When the winners were announced, the room erupted with applause.\nEmma couldn't believe her ears when her name was called as the first-place winner in the Kids' Category! Her caramel-filled chocolate chip cookies had won the hearts of the judges and the crowd. She proudly accepted her prize, a shiny blue ribbon, and smiled from ear to ear.\nThe Grand Bake-Off was a great success, leaving everyone with smiles on their faces and full bellies. Emma knew that baking was not just about creating delicious food, but also about bringing joy to others through her sweet creations.\n\n", + "Question": [ + { + "question": "1. What was the special twist that Emma added to her chocolate chip cookies?", + "correct_answer": 0, + "answers": [ + "A. Caramel filling", + "B. Oreo crumbs", + "C. Lemon zest", + "D. Peanut butter" + ], + "type": "Inference" + }, + { + "question": "2. Why was the annual Grand Bake-Off exciting?", + "correct_answer": 3, + "answers": [ + "A. People came to watch a baking competition", + "B. The participants were the best bakers in town", + "C. Delicious treats were available to taste", + "D. All of the above" + ], + "type": "Vocab" + }, + { + "question": "3. How did the judges react to Emma's caramel-filled chocolate chip cookies?", + "correct_answer": 2, + "answers": [ + "A. They were unimpressed", + "B. They thought the cookies were too sweet", + "C. They liked the combination of caramel and cookies", + "D. They thought the cookies needed more flavor" + ], + "type": "Details" + }, + { + "question": "4. What prize did Emma receive for winning first place in the Kids' Category?", + "correct_answer": 0, + "answers": [ + "A. A shiny blue ribbon", + "B. A trophy", + "C. A gift card", + "D. A baking book" + ], + "type": "Main Ideas" + } + ] +} + # MongoDB connection setup client = MongoClient(os.getenv('MONGODB_URI'), server_api=ServerApi('1'), document_class=RawBSONDocument) coll = client.ted_ai.students @@ -24,12 +79,15 @@ def __init__(self, email, interests, sessions, fname, lname): self.fname = fname self.lname = lname +def get_student_by_id(id): + return coll.find_one({"_id": ObjectId(id)}) + # API endpoint to add a new student @app.route("/api/student/new", methods=["POST"]) def add_student(): data = request.get_json() # email = data.get("email") - # interests = data.get("interests") + interests = data.get("interests") # sessions = data.get("sessions") # fname = data.get("fname") # lname = data.get("lname") @@ -37,21 +95,83 @@ def add_student(): # # Create a new student object # new_student = Student(email=email, interests=interests, sessions=sessions, fname=fname, lname=lname) - bson_bytes = bsonjs.loads(bson_dumps(data)) + student = { + "email": "potter.harry@hogwarts.edu", + "interests": interests, + "rounds": [], + "fname": "Harry", + "lname": "Potter" + } + # Insert the new student into the MongoDB collection - inserted_id = coll.insert_one(RawBSONDocument(bson_bytes)).inserted_id + inserted_id = coll.insert_one(student).inserted_id - return jsonify({"message": f"Student added successfully with id { inserted_id }!"}), 201 + return jsonify(json.loads(bson_dumps({"id": inserted_id}))), 201 # API endpoint to get student data by email @app.route("/api/student/", methods=["GET"]) def get_student(id): - student_data = coll.find_one({"_id": ObjectId(id)}) + student_data = get_student_by_id(id) if student_data: return jsonify(bsonjs.dumps(student_data.raw)), 200 else: return jsonify({"message": "Student not found"}), 404 +@app.route("/api/generate/", methods=["GET"]) +def generate_prompt(id): + data = bson.decode(get_student_by_id(id).raw) + interests = data["interests"] + # todo: this is random for right now + picked_interest = interests[random.randint(0, len(interests) - 1)] + + # default for now + question_types = ["Inference", "Vocab", "Details", "Main Ideas"] + + try: + prompt = generate(picked_interest, question_types) + # prompt = PROMPT + + data["rounds"].append({ + "text": prompt["Passage"], + "questions": prompt["Question"] + }) + + coll.update_one({"_id": ObjectId(id)}, {"$set": data}) + + return jsonify({ + "text": prompt["Passage"], + "questions": prompt["Question"] + }), 200 + except Exception as e: + console.log(e) + return jsonify({"message": f"Error generating prompt {e}"}), 500 + +@app.route("/api/student/answer", methods=["POST"]) +def answer(): + data = request.get_json() + answers = data.get("answers") + student_id = data.get("student_id") + + student_data = bson.decode(get_student_by_id(student_id).raw) + + # returns whether or not the answers were answered right as an array of boolean values + ret = [] + if student_data: + for index, answer in enumerate(answers): + new_q = student_data["rounds"][-1]["questions"][index] | { + "selected_answer": answer, + } + + rounds_len = len(student_data["rounds"]) - 1 + + coll.update_one({"_id": ObjectId(student_id)}, {"$set": {f"rounds.{ rounds_len }.questions.{ index }": new_q}}) + + ret.append(answer == student_data["rounds"][-1]["questions"][index]["correct_answer"]) + + return jsonify({"answer_validation": ret}), 200 + else: + return jsonify({"message": "Invalid student id"}), 404 + if __name__ == "__main__": app.run(debug=True) diff --git a/src/api/passage.txt b/src/api/passage.txt new file mode 100644 index 0000000..bbdd918 --- /dev/null +++ b/src/api/passage.txt @@ -0,0 +1 @@ +{'Passage': "\n\nLily's First Ballet Recital\n\nLily had always loved to dance. From a young age, she would twirl and spin around the living room, pretending to be a ballerina. She dreamt of one day performing on a big stage in a beautiful costume. Finally, the day had come for Lily's first ballet recital.\n\nAs the music started playing, Lily felt a mix of excitement and nervousness. She lined up with the other ballerinas, all wearing matching pink tutus and ballet slippers. The lights dimmed, and the curtain slowly opened.\n\nLily gracefully moved across the stage, following the choreography she had practiced over and over. Her body moved with elegance and precision, as if she was floating on air. The audience watched in awe as Lily performed her routine flawlessly.\n\nAfter the performance, Lily's heart was racing with joy. Her parents rushed backstage to congratulate her. They were so proud of their little dancer. Lily couldn't stop smiling – her dream of being a ballerina had come true.\n\n", 'Question': [{'question': '1. What word best describes how Lily felt before her ballet recital?', 'correct_answer': 0, 'answers': ['A. Nervous', 'B. Angry', 'C. Bored', 'D. Sad'], 'type': 'Inference'}, {'question': '2. What did Lily dream of doing one day?', 'correct_answer': 3, 'answers': ['A. Playing the piano', 'B. Painting pictures', 'C. Writing a story', 'D. Performing on a stage'], 'type': 'Vocab'}, {'question': "3. What color were the ballerinas' costumes?", 'correct_answer': 2, 'answers': ['A. Blue', 'B. Yellow', 'C. Pink', 'D. Green'], 'type': 'Details'}, {'question': '4. How did Lily perform her ballet routine?', 'correct_answer': 0, 'answers': ['A. Flawlessly', 'B. Messily', 'C. Loudly', 'D. Slowly'], 'type': 'Main Ideas'}]} \ No newline at end of file diff --git a/src/api/passage_generator.py b/src/api/passage_generator.py new file mode 100644 index 0000000..9b2f6ec --- /dev/null +++ b/src/api/passage_generator.py @@ -0,0 +1,254 @@ + +import openai +import json +import time +def data_clean(data, types): + out = [] + for i in range(len(data["Question"])): + question = {} + question["question"] = data["Question"][i][0] + question["correct_answer"] = ord(data["Answers"][i].lower()) - 97 + question["answers"] = data["Question"][i][1:] + question["type"] = types[i] + + out.append(question) + data["Question"] = out + del data["Answers"] + +def generate(passions, categories): + f = open("apikey.txt", "r") + key = f.readline() + f.close() + openai.api_key = key + + + + + messages = [ {"role": "system","content": "You are an expert educator"} ] + + + message = ''' + Write me a passage about one or more people with random names at fourth-grade reading level based loosely on exactly one of my passions. Ask me 4 multiple choice question to demonstrate my reading comprehension, also fourth-grade level. The first question should be about ''' + categories[0] + '''; the second question should be about ''' + categories[1] + '''; the third question should be about ''' + categories[2] + '''; the fourth question should be about ''' + categories[3] + '''. The answers to these questions should not be explicitly stated in the text, but should also not be ambiguous. Also provide the answer. It should be in the following format: Passage: _passage_ Questions: _questions_ Answers: _answers: + + Example 1: + My passions: farms + + Passage: + Lisa and the Pigpen + Peter lived in a small town with his mama, papa, brothers, and sisters. Everyone had chores. Peter’s + job was to look after his youngest sister Lisa. Lisa was three years old and very curious. She liked to + wander out of the house and play outside. + One day Peter and Lisa were playing hide-and-seek in the house, and the game turned into a chase. + Crash! Bang! Peter tripped and landed in the clothes basket on the kitchen floor. + Lisa fell on the floor beside him and laughed. “Do it again,” begged Lisa. + “Oh, no,” said Mama. “You two go outside with your chasing and stay out of my way. Don’t get into + trouble.” + The children ran out the door into the sunshine. At that moment, Mr. Brown was leading his pig down + the road. He was going to Ms. Smith’s house to show her how big the pig had grown. + Lisa laughed and ran to catch up to Mr. Brown and his pig. Peter yelled after her. + “Where are you going?” Lisa asked Mr. Brown. + Mr. Brown turned around and saw the little girl following him. “I am going to show my friend, Ms. + Smith, how big my pig has grown.” + “I’m going, too,” said Lisa. She marched right along with Mr. Brown. + “Okay, I’m going, too,” Peter sighed, and followed behind them. + When they arrived at Ms. Smith’s house, Mr. Brown put his pig in the pigpen at the back of the + house. Lisa followed Mr. Brown and his pig. When she saw the other pigs, she squealed with delight. The + pigs squealed and oinked. + “Don’t go in the pigpen, children,” Mr. Brown said. Then he went in the house. + Lisa wanted to play with the pigs. She started across the pen to pet the pigs. On her way, she slipped + in the mud and fell in a puddle. Lisa was wet from her head to her toes with black, dirty pigpen water. + She splashed with her hands and kicked her feet, spreading mud all over her clothes. “I’m a pig! I’m a + pig!” she squealed. “Come out of there right now, Lisa!” screamed Peter. + At that moment, Mr. Brown and Ms. Smith came outside. They heard the children shouting and the + pigs squealing. + “Someone is in the pigpen with the pigs!” Ms. Smith exclaimed. + They went to the back of the house and found Lisa splashing in the water. + Peter was shouting at Lisa. “Lisa! Look at you! What will Mama say? You get out of there now!” + “I’m a pig!” said Lisa. She wouldn’t come out of the pigpen. + Peter crawled through the fence to get a hold of Lisa. Lisa ran from him. Peter slipped and fell in the + black, dirty pigpen puddle. + “Oh, no! Now we’re both wet and dirty and smell like a pigpen!” Peter said. + Peter took Lisa’s arm and pulled her out of the pigpen. He held her hand and walked her home. + Peter’s face was long and sad. He wondered what Mama would say. When they walked in the house, + Mama looked up from her laundry. Her eyes grew large and her mouth opened wide. Then she laughed. + “You look and smell like two little pigs. Take off your dirty clothes. I have just enough water to wash + the two of you. Your clothes are another matter. I will take care of those later.” + When the children were clean, Mama put Lisa in her bed for a nap. Peter went outside to sit and + think. How was he going to keep Lisa out of trouble? + + Questions: + + 1. In the first paragraph, what word helps the reader know the meaning of chores? + A. wander + B. curious + C. look + D. job + + 2. Why do Mama’s eyes grow large and her mouth open wide? + A. She was angry at the children. + B. She saw Lisa in the clothes basket. + C. She did not know who the children were. + D. She saw the children covered with mud. + + 3. Which word best describes Lisa? + A. naughty + B. honest + C. helpful + D. thoughtful + + 4. Which pair of words are compound words? + A. outside and laughed + B. sunshine and pigpen + C. laundry and pigpen + D. shouting and following + 5. What is the main idea of the passage? + A. Peter has a hard job watching his sister. + B. Ms. Smith likes to raise pigs. + C. Mama has a busy schedule. + D. Many people raise pigs. + + + Answers: + + 1. D + 2. D + 3. A + 4. B + + + Example 2: + My passions: wild animals + + Passage: + Wolves Home Again + Good things have come from bringing wolves back to Yellowstone National Park. One good thing is + the return of two kinds of trees, which grow only near streams. They had nearly disappeared since the + wolves were gone. There was a reason for this. + The wolves scare away elk, which are animals that eat trees growing out of the ground. Now elk avoid + spending time near streams in the park. They have no place to run from wolves there. The trees that + disappeared near streams now grow in the park. + Yellowstone National Park, “America’s first national park,” is in the northwest part of Wyoming. It + spreads into Idaho and Montana. It became a park in 1872. The park is beautiful and has many visitors. + The land was a home for wolves for a long time. + Wolves were common in the park at first. As time went on, the wolves began dying out. By 1926, no + wolves could be found. People who lived near Yellowstone killed them because the wolves would eat the + animals the people had raised to sell. + In 1995, many people joined forces to bring back the wolves. They were people who cared about + animals and the health of the land. At first, this was only a dream since there were no wolves in the park! + Wolves were in Canada, which is north of the United States. People went to Canada to capture wolves. + They brought them back to the park and let them go. They kept close track of the wolves’ actions. When + a wolf died, they would figure out the reason. A lot was done to protect the wolves from harm. + Yet, ranchers also complained that the wolves were eating their animals. In 1997, they tried to get rid + of the wolves by passing a law to remove them from the park. The law was never passed. + Now, there are many wolves in Yellowstone National Park. The land is healthier, and the wolves have + their home back. + + Questions: + + 1. What is the singular form of the word wolves? + A. wolf + B. wolfs + C. wolfes + D. wolve + + 2. What is the author informing the reader of in the passage? + A. wolves living in Canada + B. wolves bringing good things to Yellowstone National Park + C. wolves eating elk and ranch animals + D. wolves being hunted in Yellowstone National Park + + 3. According to the passage, Yellowstone National Park is located in what three states? + A. Wyoming, Idaho, and Montana + B. Wyoming, Colorado, and Utah + C. Wyoming, Nebraska, and Idaho + D. Wyoming, Montana, and Colorado + + 4. Why were wolves killed by people who lived near Yellowstone? + A. They were eating the ranchers’ animals. + B. Park visitors were hurt by them. + C. They became sick and died. + D. A law was passed to hunt them. + + Answers: + 1. A + 2. B + 3. A + 4. A + + + My passion: + ''' + + streamWords = False + + if(not streamWords): + if message: + messages.append( + {"role": "user", "content": message + passions}, + ) + chat = openai.ChatCompletion.create( + model="gpt-3.5-turbo", messages=messages + ) + reply = chat.choices[0].message.content + else: + messages.append( + {"role": "user", "content": message + passions}, + ) + + for chunk in openai.ChatCompletion.create( + model="gpt-3.5-turbo", + + messages=messages, + stream=True, + ): + content = chunk["choices"][0].get("delta", {}).get("content") + if content is not None: + for char in content: + print(char, end='', flush=True) + #print(char, end='', flush=True) + time.sleep(.05) + + + passage = reply[reply.find("Passage") + 8:reply.find("Questions")] + question = reply[reply.find("Questions") + 10:reply.find("Answers")] + answers = reply[reply.find("Answers") + 8:] + #print(question) + questionArr = question.split('\n') + while("" in questionArr): + questionArr.remove("") + + + q1 = questionArr[0:5] + q2 = questionArr[5:10] + q3 = questionArr[10:15] + q4 = questionArr[15:20] + + questionArr = [q1,q2,q3,q4] + + letters = answers.splitlines() + + while("" in letters): + letters.remove("") + + + for i in range(len(letters)): + letters[i] = letters[i][-1:] + + + + + data = {} + data['Passage'] = passage + data["Question"] = questionArr + data["Answers"] = letters + data_clean(data,categories) + with open('passage.txt', 'w') as f: + f.write(str(data)) + return data + #print(data) + + + +generate("dancing", ["Inference", "Vocab", "Details", "Main Ideas"]) +with open('passage.txt', 'r') as f: + print(f.read()) diff --git a/src/api/prompt.py b/src/api/prompt.py new file mode 100644 index 0000000..fb85362 --- /dev/null +++ b/src/api/prompt.py @@ -0,0 +1,245 @@ + +import openai +import json +import time +from dotenv import load_dotenv +import os + +load_dotenv() + +def data_clean(data, types): + out = [] + for i in range(len(data["Question"])): + question = {} + question["question"] = data["Question"][i][0] + question["correct_answer"] = ord(data["Answers"][i].lower()) - 97 + question["answers"] = data["Question"][i][1:] + question["type"] = types[i] + + out.append(question) + data["Question"] = out + del data["Answers"] + +def generate(passions, categories): + openai.api_key = os.getenv('OPENAI_API_KEY') + + messages = [ {"role": "system","content": "You are an expert educator"} ] + + + message = ''' + Write me a passage about one or more people with random names at fourth-grade reading level based loosely on exactly one of my passions. Ask me 4 multiple choice question to demonstrate my reading comprehension, also fourth-grade level. The first question should be about ''' + categories[0] + '''; the second question should be about ''' + categories[1] + '''; the third question should be about ''' + categories[2] + '''; the fourth question should be about ''' + categories[3] + '''. The answers to these questions should not be explicitly stated in the text, but should also not be ambiguous. Also provide the answer. It should be in the following format: Passage: _passage_ Questions: _questions_ Answers: _answers: + + Example 1: + My passions: farms + + Passage: + Lisa and the Pigpen + Peter lived in a small town with his mama, papa, brothers, and sisters. Everyone had chores. Peter’s + job was to look after his youngest sister Lisa. Lisa was three years old and very curious. She liked to + wander out of the house and play outside. + One day Peter and Lisa were playing hide-and-seek in the house, and the game turned into a chase. + Crash! Bang! Peter tripped and landed in the clothes basket on the kitchen floor. + Lisa fell on the floor beside him and laughed. “Do it again,” begged Lisa. + “Oh, no,” said Mama. “You two go outside with your chasing and stay out of my way. Don’t get into + trouble.” + The children ran out the door into the sunshine. At that moment, Mr. Brown was leading his pig down + the road. He was going to Ms. Smith’s house to show her how big the pig had grown. + Lisa laughed and ran to catch up to Mr. Brown and his pig. Peter yelled after her. + “Where are you going?” Lisa asked Mr. Brown. + Mr. Brown turned around and saw the little girl following him. “I am going to show my friend, Ms. + Smith, how big my pig has grown.” + “I’m going, too,” said Lisa. She marched right along with Mr. Brown. + “Okay, I’m going, too,” Peter sighed, and followed behind them. + When they arrived at Ms. Smith’s house, Mr. Brown put his pig in the pigpen at the back of the + house. Lisa followed Mr. Brown and his pig. When she saw the other pigs, she squealed with delight. The + pigs squealed and oinked. + “Don’t go in the pigpen, children,” Mr. Brown said. Then he went in the house. + Lisa wanted to play with the pigs. She started across the pen to pet the pigs. On her way, she slipped + in the mud and fell in a puddle. Lisa was wet from her head to her toes with black, dirty pigpen water. + She splashed with her hands and kicked her feet, spreading mud all over her clothes. “I’m a pig! I’m a + pig!” she squealed. “Come out of there right now, Lisa!” screamed Peter. + At that moment, Mr. Brown and Ms. Smith came outside. They heard the children shouting and the + pigs squealing. + “Someone is in the pigpen with the pigs!” Ms. Smith exclaimed. + They went to the back of the house and found Lisa splashing in the water. + Peter was shouting at Lisa. “Lisa! Look at you! What will Mama say? You get out of there now!” + “I’m a pig!” said Lisa. She wouldn’t come out of the pigpen. + Peter crawled through the fence to get a hold of Lisa. Lisa ran from him. Peter slipped and fell in the + black, dirty pigpen puddle. + “Oh, no! Now we’re both wet and dirty and smell like a pigpen!” Peter said. + Peter took Lisa’s arm and pulled her out of the pigpen. He held her hand and walked her home. + Peter’s face was long and sad. He wondered what Mama would say. When they walked in the house, + Mama looked up from her laundry. Her eyes grew large and her mouth opened wide. Then she laughed. + “You look and smell like two little pigs. Take off your dirty clothes. I have just enough water to wash + the two of you. Your clothes are another matter. I will take care of those later.” + When the children were clean, Mama put Lisa in her bed for a nap. Peter went outside to sit and + think. How was he going to keep Lisa out of trouble? + + Questions: + + 1. In the first paragraph, what word helps the reader know the meaning of chores? + A. wander + B. curious + C. look + D. job + + 2. Why do Mama’s eyes grow large and her mouth open wide? + A. She was angry at the children. + B. She saw Lisa in the clothes basket. + C. She did not know who the children were. + D. She saw the children covered with mud. + + 3. Which word best describes Lisa? + A. naughty + B. honest + C. helpful + D. thoughtful + + 4. Which pair of words are compound words? + A. outside and laughed + B. sunshine and pigpen + C. laundry and pigpen + D. shouting and following + 5. What is the main idea of the passage? + A. Peter has a hard job watching his sister. + B. Ms. Smith likes to raise pigs. + C. Mama has a busy schedule. + D. Many people raise pigs. + + + Answers: + + 1. D + 2. D + 3. A + 4. B + + + Example 2: + My passions: wild animals + + Passage: + Wolves Home Again + Good things have come from bringing wolves back to Yellowstone National Park. One good thing is + the return of two kinds of trees, which grow only near streams. They had nearly disappeared since the + wolves were gone. There was a reason for this. + The wolves scare away elk, which are animals that eat trees growing out of the ground. Now elk avoid + spending time near streams in the park. They have no place to run from wolves there. The trees that + disappeared near streams now grow in the park. + Yellowstone National Park, “America’s first national park,” is in the northwest part of Wyoming. It + spreads into Idaho and Montana. It became a park in 1872. The park is beautiful and has many visitors. + The land was a home for wolves for a long time. + Wolves were common in the park at first. As time went on, the wolves began dying out. By 1926, no + wolves could be found. People who lived near Yellowstone killed them because the wolves would eat the + animals the people had raised to sell. + In 1995, many people joined forces to bring back the wolves. They were people who cared about + animals and the health of the land. At first, this was only a dream since there were no wolves in the park! + Wolves were in Canada, which is north of the United States. People went to Canada to capture wolves. + They brought them back to the park and let them go. They kept close track of the wolves’ actions. When + a wolf died, they would figure out the reason. A lot was done to protect the wolves from harm. + Yet, ranchers also complained that the wolves were eating their animals. In 1997, they tried to get rid + of the wolves by passing a law to remove them from the park. The law was never passed. + Now, there are many wolves in Yellowstone National Park. The land is healthier, and the wolves have + their home back. + + Questions: + + 1. What is the singular form of the word wolves? + A. wolf + B. wolfs + C. wolfes + D. wolve + + 2. What is the author informing the reader of in the passage? + A. wolves living in Canada + B. wolves bringing good things to Yellowstone National Park + C. wolves eating elk and ranch animals + D. wolves being hunted in Yellowstone National Park + + 3. According to the passage, Yellowstone National Park is located in what three states? + A. Wyoming, Idaho, and Montana + B. Wyoming, Colorado, and Utah + C. Wyoming, Nebraska, and Idaho + D. Wyoming, Montana, and Colorado + + 4. Why were wolves killed by people who lived near Yellowstone? + A. They were eating the ranchers’ animals. + B. Park visitors were hurt by them. + C. They became sick and died. + D. A law was passed to hunt them. + + Answers: + 1. A + 2. B + 3. A + 4. A + + + My passion: + ''' + + streamWords = False + + if(not streamWords): + if message: + messages.append( + {"role": "user", "content": message + passions}, + ) + chat = openai.ChatCompletion.create( + model="gpt-3.5-turbo", messages=messages + ) + reply = chat.choices[0].message.content + else: + messages.append( + {"role": "user", "content": message + passions}, + ) + + for chunk in openai.ChatCompletion.create( + model="gpt-3.5-turbo", + + messages=messages, + stream=True, + ): + content = chunk["choices"][0].get("delta", {}).get("content") + if content is not None: + for char in content: + print(char, end='', flush=True) + #print(char, end='', flush=True) + time.sleep(.05) + + + passage = reply[reply.find("Passage") + 8:reply.find("Questions")] + question = reply[reply.find("Questions") + 10:reply.find("Answers")] + answers = reply[reply.find("Answers") + 8:] + #print(question) + questionArr = question.split('\n') + while("" in questionArr): + questionArr.remove("") + + + q1 = questionArr[0:5] + q2 = questionArr[5:10] + q3 = questionArr[10:15] + q4 = questionArr[15:20] + + questionArr = [q1,q2,q3,q4] + + letters = answers.splitlines() + + while("" in letters): + letters.remove("") + + + for i in range(len(letters)): + letters[i] = letters[i][-1:] + + + + + data = {} + data['Passage'] = passage + data["Question"] = questionArr + data["Answers"] = letters + data_clean(data,categories) + return data + #print(data) \ No newline at end of file diff --git a/src/app/page.tsx b/src/app/page.tsx index 07767f9..5dabf27 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,37 +1,128 @@ -import Head from 'next/head'; -import ToggleButton from '@components/ToggleButton'; +"use client"; +import { useState } from "react"; +import Head from "next/head"; +import InterestButton from "@components/InterestButton"; +import Link from "next/link"; +import Button from "@components/Button"; +import Logo from "@components/Logo"; export default function Home() { + const [interests, setInterests] = useState([]); + + const handleSubmit = async (e: any) => { + e.preventDefault(); + const response = await fetch("/api/student/new", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ interests: interests }), + }); + const data = await response.json(); + console.log(data); + }; + + const handleInterestClick = (interest: string) => { + if (interests.includes(interest)) { + setInterests(interests.filter((i) => i !== interest)); + } else { + setInterests([...interests, interest]); + } + }; + return ( -
+
- Settle - + ReadU + -
-

Welcome, Dilan

-

What are your interests?

- -
- - - - - - - - - - - - - - - +
+ +
+

+ Welcome, Dilan! +

+

+ What are your interests? +

+
+
+
+
+ handleInterestClick("Sports")} + /> + handleInterestClick("Video Games")} + /> + handleInterestClick("Art")} + /> + handleInterestClick("Theater")} + /> + handleInterestClick("Music")} + /> + handleInterestClick("Technology")} + /> + handleInterestClick("Fashion")} + /> + handleInterestClick("Food and Drink")} + /> + handleInterestClick("Travel")} + /> + handleInterestClick("Science")} + /> + handleInterestClick("Movies")} + /> + handleInterestClick("Fitness")} + /> + handleInterestClick("Environment")} + /> + handleInterestClick("History")} + /> + handleInterestClick("Politics")} + /> +
+
- -
); diff --git a/src/app/practice/page.tsx b/src/app/practice/page.tsx new file mode 100644 index 0000000..51ea913 --- /dev/null +++ b/src/app/practice/page.tsx @@ -0,0 +1,80 @@ +import Head from "next/head"; +import ReadingPrompt from "@components/Passage/ReadingPrompt"; +import PassageSetOfQuestions from "@components/Passage/PassageSetOfQuestions"; +import Button from "@components/Button"; +import Logo from "@components/Logo"; + +const question = "Why was Julia confident about winning the Bake-Off?"; +const answers = [ + "She practiced every day.", + "She was a renowned chef.", + "She had a secret family recipe.", + "She had won before.", +]; + +const questions = [ + { + question: "Why was Julia confident about winning the Bake-Off?", + answers: [ + "She practiced every day.", + "She was a renowned chef.", + "She had a secret family recipe.", + "She had won before.", + ], + }, + { + question: "Which word in the passage is a synonym for 'scent'?", + answers: ["Echoed", "Texture", "Booth", "Aroma"], + }, + { + question: "Where did the Great Bake-Off take place?", + answers: [ + "At Julia's home", + "In the town of Ovenville's square", + "In a big hall", + "At the judges' houses", + ], + }, + { + question: "What is the main idea of the passage?", + answers: [ + "Julia's grandmother was a great baker.", + "The town of Ovenville loved to eat cookies.", + "Julia wins the Great Bake-Off using her grandmother's secret recipe.", + "The judges were from different parts of the country.", + ], + }, +]; + +export default function Home() { + return ( +
+ + Reading Practice + + +
+
+ +
+

Reading Practice

+

+ Read this passage and answer some questions. +

+ + +
+ +
+ +
+
+ ); +} diff --git a/src/app/review/page.tsx b/src/app/review/page.tsx new file mode 100644 index 0000000..7bee672 --- /dev/null +++ b/src/app/review/page.tsx @@ -0,0 +1,134 @@ +import Logo from "@components/Logo"; +import OverviewSection from "@components/OverviewSection"; + +const Overview: React.FC = () => { + const questions = [ + { + question: "Why was Julia confident about winning the Bake-Off?", + answers: [ + "She practiced every day.", + "She was a renowned chef.", + "She had a secret family recipe.", + "She had won before.", + ], + }, + { + question: "Which word in the passage is a synonym for 'scent'?", + answers: ["Echoed", "Texture", "Booth", "Aroma"], + }, + { + question: "Where did the Great Bake-Off take place?", + answers: [ + "At Julia's home", + "In the town of Ovenville's square", + "In a big hall", + "At the judges' houses", + ], + }, + { + question: "What is the main idea of the passage?", + answers: [ + "Julia's grandmother was a great baker.", + "The town of Ovenville loved to eat cookies.", + "Julia wins the Great Bake-Off using her grandmother's secret recipe.", + "The judges were from different parts of the country.", + ], + }, + ]; + + return ( +
+
+
+ +
+ +

Overview

+

Let's review your practice session!

+ + {/* Main Idea section */} +
+ + +
+ + {/* Inference section */} +
+ + +
+ + {/* Inference section */} +
+ + +
+ + {/* Inference section */} +
+ + +
+
+
+ ); +}; + +interface QuestionProps { + title: string; + options: string[]; + correctOption?: number; + selectedOption?: number; +} + +const Question: React.FC = ({ + title, + options, + correctOption, + selectedOption, +}) => { + return ( +
+

{title}

+
+ {options.map((option, index) => ( + + ))} +
+
+ ); +}; + +export default Overview; diff --git a/src/components/Button.tsx b/src/components/Button.tsx new file mode 100644 index 0000000..70a4f1e --- /dev/null +++ b/src/components/Button.tsx @@ -0,0 +1,22 @@ +import Link from "next/link"; + +type CustomButtonProps = { + label: string; + onClick?: (e?: any) => void; + link?: string; + className?: string; +}; + +const CustomButton: React.FC = ({ label, onClick, link, className }) => { + return ( + + ); +}; + +export default CustomButton; + diff --git a/src/components/ToggleButton.tsx b/src/components/InterestButton.tsx similarity index 64% rename from src/components/ToggleButton.tsx rename to src/components/InterestButton.tsx index fa5d991..487dc35 100644 --- a/src/components/ToggleButton.tsx +++ b/src/components/InterestButton.tsx @@ -3,14 +3,18 @@ import { FC, useState } from 'react'; interface ToggleButtonProps { label: string; + callback: () => void; } -const ToggleButton: FC = ({ label }) => { +const InterestButton: FC = ({ label, callback }) => { const [isActive, setIsActive] = useState(false); return (