Endpoint generate reading kinda working.
This commit is contained in:
@@ -13,6 +13,8 @@ from helper.token_counter import count_tokens
|
||||
load_dotenv()
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
# https://chat.openai.com/share/195c4549-f67c-4353-be44-65c4d5ad5b05
|
||||
|
||||
question = "The average standard of people's health is likely to be lower in the future than it is now. To what extent do " \
|
||||
"you agree or disagree with this statement?"
|
||||
answer = "I completely disagree with the written statement. I believe that most of the people in the world have more information " \
|
||||
@@ -32,14 +34,38 @@ answer = "I completely disagree with the written statement. I believe that most
|
||||
# map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0)
|
||||
# response = make_openai_call("gpt-4", messages, token_count, GRADING_FIELDS, GRADING_TEMPERATURE)
|
||||
|
||||
grade_wt2_message = "You are a IELTS examiner. " \
|
||||
"The question you have to grade is of type Writing Task 2 and is the following:" + question + \
|
||||
"Assess this answer according to the IELTS grading system. It is mandatory for you to provide your response" \
|
||||
" with the overall grade and breakdown grades, with just the following json format: {'comment': 'Comment about " \
|
||||
"answer quality will go here', 'overall': 7.0, 'task_response': {'Task Achievement': 8.0, " \
|
||||
"'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': 6.0}} " \
|
||||
"Evaluate this answer according to ielts grading system: " + answer
|
||||
gen_wt1_question = "Craft a prompt for an IELTS Writing Task 1 General Training exercise that instructs the student to " \
|
||||
"compose a letter. The prompt should present a specific scenario or situation, requiring the student " \
|
||||
"to provide information, advice, or instructions within the letter."
|
||||
|
||||
gen_wt2_question = "Craft a comprehensive question for IELTS Writing Task 2 General Training that directs the candidate " \
|
||||
"to delve into an in-depth analysis of contrasting perspectives on a specific topic. The candidate " \
|
||||
"should be asked to discuss the strengths and weaknesses of both viewpoints, provide evidence or " \
|
||||
"examples, and present a well-rounded argument before concluding with their personal opinion on the " \
|
||||
"subject."
|
||||
gen_sp1_question = "Craft a thought-provoking question for IELTS Speaking Part 1 that encourages candidates to delve deeply " \
|
||||
"into personal experiences, preferences, or insights on diverse topics. Instruct the candidate to offer " \
|
||||
"not only detailed descriptions but also provide nuanced explanations, examples, or anecdotes to enrich " \
|
||||
"their response." \
|
||||
"Provide your response in this json format: {'topic': 'topic','question': 'question'}"
|
||||
gen_sp2_question = "Create a question for IELTS Speaking Part 2 that encourages candidates to narrate a personal experience " \
|
||||
"or story related to a randomly selected topic. Include 3 prompts that guide the candidate to describe " \
|
||||
"specific aspects of the experience, such as details about the situation, their actions, and the " \
|
||||
"reasons it left a lasting impression." \
|
||||
"Provide your response in this json format: {'topic': 'topic','question': 'question', " \
|
||||
"'prompts': ['prompt_1', 'prompt_2', 'prompt_3']}"
|
||||
gen_sp3_question = "Formulate a set of 3 questions for IELTS Speaking Part 3 that encourage candidates to engage in a " \
|
||||
"meaningful discussion on a particular topic. Provide inquiries, ensuring " \
|
||||
"they explore various aspects, perspectives, and implications related to the topic." \
|
||||
"Provide your response in this json format: {'topic': 'topic','questions': ['question_1', " \
|
||||
"'question_2', 'question_3']}"
|
||||
grade_wt2_message = "You are a IELTS examiner. " \
|
||||
"The question you have to grade is of type Writing Task 2 and is the following:" + question + \
|
||||
"Assess this answer according to the IELTS grading system. It is mandatory for you to provide your response" \
|
||||
" with the overall grade and breakdown grades, with just the following json format: {'comment': 'Comment about " \
|
||||
"answer quality will go here', 'overall': 7.0, 'task_response': {'Task Achievement': 8.0, " \
|
||||
"'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': 6.0}} " \
|
||||
"Evaluate this answer according to ielts grading system: " + answer
|
||||
|
||||
topics = [
|
||||
"Art and Creativity",
|
||||
@@ -145,30 +171,87 @@ topics = [
|
||||
]
|
||||
|
||||
gen_listening2_message = "You are an IELTS program designed to assist with language learning. Your task is to provide a detailed " \
|
||||
"transcript of a monologue on the subject of " + random.choice(topics) + ". Ensure that the transcript is comprehensive " \
|
||||
"and covers the topic " \
|
||||
"thoroughly.After the transcript, you should generate a fill in the blanks " \
|
||||
"exercise with six statements related to the content of the monologue. The blank spaces in the exercise should " \
|
||||
"be identified by {{number}}. Finally, provide the answers for the exercise." \
|
||||
"Response Format (JSON): { 'transcript': 'Transcript of the monologue on a specific subject with a minimum of 500 words.', 'exercise': {" \
|
||||
"'statements': { '1': 'Statement 1 with a blank space to fill.', '2': 'Statement 2 with a blank space to fill.'," \
|
||||
"'3': 'Statement 3 with a blank space to fill.', '4': 'Statement 4 with a blank space to fill.', " \
|
||||
"'5': 'Statement 5 with a blank space to fill.', '6': 'Statement 6 with a blank space to fill.' }, " \
|
||||
"'answers': { '1': 'Answer to fill the blank space in statement 1.', " \
|
||||
"'2': 'Answer to fill the blank space in statement 2.', '3': 'Answer to fill the blank space in statement 3.'," \
|
||||
"'4': 'Answer to fill the blank space in statement 4.', '5': 'Answer to fill the blank space in statement 5.'," \
|
||||
"'6': 'Answer to fill the blank space in statement 6.' } } }"
|
||||
"transcript of a monologue on the subject of " + random.choice(
|
||||
topics) + ". Ensure that the transcript is comprehensive " \
|
||||
"and covers the topic " \
|
||||
"thoroughly.After the transcript, you should generate a fill in the blanks " \
|
||||
"exercise with six statements related to the content of the monologue. The blank spaces in the exercise should " \
|
||||
"be identified by {{number}}. Finally, provide the answers for the exercise." \
|
||||
"Response Format (JSON): { 'transcript': 'Transcript of the monologue on a specific subject with a minimum of 500 words.', 'exercise': {" \
|
||||
"'statements': { '1': 'Statement 1 with a blank space to fill.', '2': 'Statement 2 with a blank space to fill.'," \
|
||||
"'3': 'Statement 3 with a blank space to fill.', '4': 'Statement 4 with a blank space to fill.', " \
|
||||
"'5': 'Statement 5 with a blank space to fill.', '6': 'Statement 6 with a blank space to fill.' }, " \
|
||||
"'answers': { '1': 'Answer to fill the blank space in statement 1.', " \
|
||||
"'2': 'Answer to fill the blank space in statement 2.', '3': 'Answer to fill the blank space in statement 3.'," \
|
||||
"'4': 'Answer to fill the blank space in statement 4.', '5': 'Answer to fill the blank space in statement 5.'," \
|
||||
"'6': 'Answer to fill the blank space in statement 6.' } } }"
|
||||
gen_reading_passage_1 = "Generate an extensive text for IELTS Reading Passage 1, of at least 1500 words, on the topic " \
|
||||
"of " + random.choice(topics) + ". The passage should offer a substantial amount of " \
|
||||
"information, analysis, or narrative " \
|
||||
"relevant to the chosen subject matter. This text passage aims to serve as the primary reading " \
|
||||
"section of an IELTS test, providing an in-depth and comprehensive exploration of the topic." \
|
||||
"Provide your response in this json format: {'title': 'title of the text', 'text': 'generated text'}"
|
||||
gen_reading_passage_2 = "Generate an extensive text for IELTS Reading Passage 2, of at least 1500 words, on the topic " \
|
||||
"of " + random.choice(topics) + ". The passage should offer a substantial amount of " \
|
||||
"information, analysis, or narrative " \
|
||||
"relevant to the chosen subject matter. This text passage aims to serve as the primary reading " \
|
||||
"section of an IELTS test, providing an in-depth and comprehensive exploration of the topic." \
|
||||
"Provide your response in this json format: {'title': 'title of the text', 'text': 'generated text'}"
|
||||
gen_reading_passage_3 = "Generate an extensive text for IELTS Reading Passage 2, of at least 1500 words, on the topic " \
|
||||
"of " + random.choice(topics) + ". The passage should offer a substantial amount of " \
|
||||
"information, analysis, or narrative " \
|
||||
"relevant to the chosen subject matter. This text passage aims to serve as the primary reading " \
|
||||
"section of an IELTS test, providing an in-depth and comprehensive exploration of the topic." \
|
||||
"Provide your response in this json format: {'title': 'title of the text', 'text': 'generated text'}"
|
||||
|
||||
token_count = count_tokens(gen_listening2_message)["n_tokens"]
|
||||
sample_text = "In recent years, there has been a significant shift towards renewable energy sources as societies " \
|
||||
"strive to reduce their dependence on fossil fuels and combat the effects of climate change. Renewable " \
|
||||
"energy, derived from sources such as sunlight, wind, and water, offers a promising alternative to " \
|
||||
"traditional energy generation methods.\\nSolar power, harnessed from the sun's rays, has gained immense " \
|
||||
"popularity. Photovoltaic cells, commonly known as solar panels, capture sunlight and convert it into " \
|
||||
"electricity. This technology has become more efficient and affordable, contributing to a growing number " \
|
||||
"of solar installations on rooftops and solar farms. Solar energy not only reduces greenhouse gas " \
|
||||
"emissions but also grants individuals and businesses the ability to generate their own power.\\nSimilarly, " \
|
||||
"wind energy has emerged as a reliable and clean source of electricity. Wind turbines, often found in " \
|
||||
"wind farms, harness the kinetic energy of moving air to turn blades and generate electricity. These " \
|
||||
"structures are strategically placed in areas with consistent wind patterns, contributing to the overall " \
|
||||
"energy grid. Wind power has the advantage of scalability, with both small and large installations being " \
|
||||
"feasible options.\\nHydropower, generated from flowing water in rivers and dams, is another vital renewable " \
|
||||
"energy source. The force of water is used to turn turbines, which then produce electricity. While hydropower " \
|
||||
"has a long history, advancements in technology have led to more efficient and environmentally friendly " \
|
||||
"designs. However, the construction of dams for hydropower can have significant ecological and social " \
|
||||
"impacts, requiring careful consideration.\\nGeothermal energy, originating from the Earth's heat, is " \
|
||||
"also gaining attention. This energy source is harnessed through underground steam and hot water reservoirs, " \
|
||||
"which are tapped for electricity generation and heating. Geothermal power plants have a relatively small " \
|
||||
"environmental footprint and provide a consistent source of energy, making them a viable option in regions " \
|
||||
"with suitable geological conditions.\\nIn conclusion, the transition to renewable energy sources marks a " \
|
||||
"pivotal step towards sustainable and environmentally conscious energy generation. Solar, wind, hydropower, " \
|
||||
"and geothermal energy offer diverse options that can collectively contribute to reducing carbon emissions " \
|
||||
"and combating climate change. As technology continues to evolve and economies adapt, the potential for " \
|
||||
"widespread adoption of renewable energy remains promising."
|
||||
gen_multiple_choice_for_text = "Generate 10 multiple choice questions for this text: '" + sample_text + "'\n" \
|
||||
"Parse those questions to this format: 'questions': [{'id': '9', 'options': [{'id': 'A', 'text': " \
|
||||
"'Economic benefits'}, {'id': 'B', 'text': 'Government regulations'}, {'id': 'C', 'text': " \
|
||||
"'Concerns about climate change'}, {'id': 'D', 'text': 'Technological advancement'}], " \
|
||||
"'prompt': 'What is the main reason for the shift towards renewable energy sources?', " \
|
||||
"'solution': 'C', 'variant': 'text'}]"
|
||||
|
||||
mc_questions = "questions: 1. What is the main reason for the shift towards renewable energy sources? - A. Economic benefits - B. Government regulations - C. Concerns about climate change - D. Technological advancement 2. Which of the following is NOT a renewable energy source mentioned in the text? - A. Solar power - B. Coal - C. Wind energy - D. Hydropower 3. What is the term used to describe the conversion of sunlight into electricity? - A. Solar power - B. Photovoltaic cells - C. Wind turbines - D. Hydropower 4. Which of the following is a benefit of solar energy? - A. Reduced greenhouse gas emissions - B. Increased dependence on fossil fuels - C. Higher energy costs - D. Limited availability 5. How do wind turbines generate electricity? - A. By harnessing the sun's rays - B. By using the force of water - C. By capturing wind - D. By tapping into underground reservoirs 6. What is the advantage of wind power over other renewable energy sources? - A. It is more affordable - B. It is more scalable - C. It has a smaller environmental footprint - D. It is easier to construct 7. Which renewable energy source has a long history but has recently seen advancements in technology? - A. Solar energy - B. Hydropower - C. Wind energy - D. Geothermal energy 8. What is the main drawback of constructing dams for hydropower? - A. Limited availability of suitable locations - B. High cost of construction - C. Negative impacts on the environment - D. Technological limitations 9. What is the source of geothermal energy? - A. The sun's rays - B. Moving air - C. Flowing water - D. The Earth's heat 10. How does geothermal energy differ from other renewable energy sources mentioned in the text? - A. It has a smaller environmental footprint - B. It is more expensive to harness - C. It is not affected by geographical conditions - D. It provides a consistent source of energy."
|
||||
parse_mc_questions = "Parse this '" + mc_questions + "' into this json format: 'questions': [{'id': '9', 'options': [{'id': 'A', 'text': " \
|
||||
"'Economic benefits'}, {'id': 'B', 'text': 'Government regulations'}, {'id': 'C', 'text': " \
|
||||
"'Concerns about climate change'}, {'id': 'D', 'text': 'Technological advancement'}], " \
|
||||
"'prompt': 'What is the main reason for the shift towards renewable energy sources?', " \
|
||||
"'solution': 'C', 'variant': 'text'}]"
|
||||
|
||||
token_count = count_tokens(parse_mc_questions)["n_tokens"]
|
||||
|
||||
response = openai.Completion.create(
|
||||
model="gpt-3.5-turbo-instruct",
|
||||
prompt=gen_listening2_message,
|
||||
max_tokens=int(4097 - token_count - 300),
|
||||
temperature=0.7
|
||||
)["choices"][0]["text"]
|
||||
model="gpt-3.5-turbo-instruct",
|
||||
prompt=parse_mc_questions,
|
||||
max_tokens=int(4097 - token_count - 300),
|
||||
temperature=0.7
|
||||
)
|
||||
|
||||
# processed = process_response(response, "comment")
|
||||
processed = process_response(response, "transcript")
|
||||
processed = process_response(response["choices"][0]["text"], "transcript")
|
||||
print(processed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user