Improve writing spellcheck to return fixed_text.

This commit is contained in:
Cristiano Ferreira
2024-01-17 16:11:29 +00:00
parent ccc606d5de
commit 92c92dfd98
7 changed files with 13 additions and 615 deletions

15
app.py
View File

@@ -194,8 +194,9 @@ def grade_writing_task_1():
if has_words(answer):
message = (
"Grade this Writing Task 1 answer according to ielts grading system and provide an example of a perfect "
"answer and an elaborated comment where you deep dive into what is wrong and right about the answer."
"Provide your answer on the following json format: {'perfect_answer': 'example perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, "
"answer (min 150 words) and an elaborated comment where you deep dive into what is wrong and right"
" about the answer. Provide your answer on the following json format: {'perfect_answer': 'example "
"perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, "
"'task_response': {'Task Achievement': 0.0, 'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, "
"'Grammatical Range and Accuracy': 0.0}}\n The question was '" + question + "' "
"and the answer was '" + answer + "'")
@@ -203,7 +204,7 @@ def grade_writing_task_1():
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
GEN_QUESTION_TEMPERATURE)
response['misspelled_pairs'] = get_misspelled_pairs(answer)
response['fixed_text'] = get_fixed_text(answer)
return response
else:
return {
@@ -247,9 +248,9 @@ def grade_writing_task_2():
if has_words(answer):
message = (
"Grade this Writing Task 2 answer according to ielts grading system and provide an example of a perfect "
"answer and an elaborated comment where you deep dive into what is wrong and right about the answer."
"Provide your answer on the following json format: {'perfect_answer': 'example perfect answer', "
"'comment': 'comment about answer quality', 'overall': 7.0, "
"answer (min 250 words) and an elaborated comment where you deep dive into what is wrong and right "
"about the answer. Provide your answer on the following json format: {'perfect_answer': 'example "
"perfect answer', 'comment': 'comment about answer quality', 'overall': 7.0, "
"'task_response': {'Task Achievement': 0.0, 'Coherence and Cohesion': 0.0, 'Lexical Resource': 0.0, "
"'Grammatical Range and Accuracy': 0.0}}\n The question was '" + question + "' "
"and the answer was '" + answer + "'")
@@ -257,7 +258,7 @@ def grade_writing_task_2():
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count,
["comment"],
GEN_QUESTION_TEMPERATURE)
response['misspelled_pairs'] = get_misspelled_pairs(answer)
response['fixed_text'] = get_fixed_text(answer)
return response
else:
return {

View File

@@ -249,15 +249,12 @@ def extract_existing_sections_from_body(my_dict, keys_to_extract):
my_dict['sections']))
def get_misspelled_pairs(text):
message = ('From the given text, extract the misspelled words and put them in the json with the correct word that '
'should be on the text instead. Sample JSON: '
'{"misspelled_words":[{"misspelled": "piza", "correction": "pizza"}] \n The text: "' + text + '"')
def get_fixed_text(text):
message = ('Fix the errors in the given text and put it in a JSON. Sample JSON: {"fixed_text": "fixed test with no '
'misspelling errors"}] \n The text: "' + text + '"')
token_count = count_tokens(message)["n_tokens"]
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["misspelled_words"], 0.2)
# Filter out items with the same value for misspelled and correction
filtered_data = [item for item in response["misspelled_words"] if item['misspelled'] != item['correction']]
return filtered_data
response = make_openai_instruct_call(GPT_3_5_TURBO_INSTRUCT, message, token_count, ["fixed_text"], 0.2)
return response["fixed_text"]
def get_speaking_corrections(text):
message = ('Given the provided transcription, identify and extract any inaccuracies, including incorrect words and '

View File

@@ -1,133 +0,0 @@
import streamlit as st
import openai
import os
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_summarizer(
max_tokens,
temperature,
top_p,
frequency_penalty,
question_type,
question,
answer
):
res = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
max_tokens=int(max_tokens),
temperature=float(temperature),
top_p=float(top_p),
frequency_penalty=float(frequency_penalty),
messages=[
{
"role": "user",
"content": "You are a IELTS program that generates questions for the exams.",
},
{
"role": "user",
"content": "Provide me with a transcript for ielts exam Listening section 2. After the transcript, "
"please generate a fill in the blanks exercise with 6 statements related to the text content. "
"Finally, provide the answers for the exercise. The response must be a json following this format: "
"{ 'transcript': 'Audio Transcript: Good morning, and welcome to today's lecture on the history of "
"photography. Today, we will explore the evolution of photography from its early beginnings to the "
"digital age. In the early 19th century, the invention of the camera obscura marked the first "
"step towards capturing images. This precursor to the modern camera allowed artists and scientists "
"to project images onto a surface, tracing their outlines. However, it wasn't until the 1820s that "
"the first permanent photograph was produced. Louis Daguerre, a French inventor, introduced the "
"daguerreotype process in 1839. This revolutionary technique involved exposing a chemically treated "
"metal plate to light, resulting in a unique and highly detailed image. The daguerreotype became "
"immensely popular, paving the way for the widespread adoption of photography. In the late 19th "
"century, the development of flexible film made photography more accessible. George Eastman's "
"introduction of roll film and the Kodak Brownie camera in 1900 revolutionized photography, "
"allowing anyone to capture moments without the need for complex equipment.The 20th century "
"witnessed significant advancements in photographic technology. The introduction of 35mm film "
"and the Leica camera in the 1920s made photography more portable and versatile. This led to "
"the emergence of photojournalism as a powerful medium for documenting historical events.With "
"the advent of digital technology in the late 20th century, photography underwent a transformative "
"shift. Digital cameras eliminated the need for film, enabling instant image capture, storage, "
"and manipulation. The accessibility of digital photography has revolutionized the way we take, "
"share, and edit photographs. In conclusion, the history of photography is a fascinating journey "
"marked by constant innovation and technological advancements. From the camera obscura to digital "
"cameras, photography has evolved into a powerful and ubiquitous form of visual communication.",
"exercise": {
"statements": [
"The camera obscura allowed artists and scientists to project images onto a surface, enabling them to trace their __1__.",
"Louis Daguerre introduced the __2__ process in 1839, which involved exposing a chemically treated metal plate to __3__.",
"The __4__ became popular in the 19th century and played a significant role in the widespread adoption of photography.",
"George Eastman's introduction of roll film and the Kodak Brownie camera in 1900 made photography more __5__.",
"The __6__ and the Leica camera introduced in the 1920s revolutionized photography and led to the emergence of photojournalism."
],
"answers": {
"1": "outlines",
"2": "daguerreotype",
"3": "light",
"4": "daguerreotype",
"5": "accessible",
"6": "35mm film"
}
}
}",
},
{
"role": "user",
"content": "Don't give explanations for the grades, just provide the json with the grades.",
},
{
"role": "user",
"content": f"Evaluate this answer according to ielts grading system: {answer}",
},
],
)
return res["choices"][0]["message"]["content"]
# Set the application title
st.title("GPT-3.5 IELTS Examiner")
# qt_col, q_col = st.columns(2)
# Selection box to select the question type
# with qt_col:
question_type = st.selectbox(
"What is the question type?",
(
"Writing Task 2",
),
)
# Provide the input area for question to be answered
# with q_col:
question = st.text_area("Enter the question:", height=100)
# Provide the input area for text to be summarized
answer = st.text_area("Enter the answer:", height=100)
# Initiate two columns for section to be side-by-side
# col1, col2 = st.columns(2)
# Slider to control the model hyperparameter
# with col1:
token = st.slider("Token", min_value=0.0,
max_value=2000.0, value=1000.0, step=1.0)
temp = st.slider("Temperature", min_value=0.0,
max_value=1.0, value=0.7, step=0.01)
top_p = st.slider("Top_p", min_value=0.0, max_value=1.0, value=0.9, step=0.01)
f_pen = st.slider("Frequency Penalty", min_value=-1.0,
max_value=1.0, value=0.5, step=0.01)
# Showing the current parameter used for the model
# with col2:
with st.expander("Current Parameter"):
st.write("Current Token :", token)
st.write("Current Temperature :", temp)
st.write("Current Nucleus Sampling :", top_p)
st.write("Current Frequency Penalty :", f_pen)
# Creating button for execute the text summarization
if st.button("Grade"):
st.write(generate_summarizer(token, temp, top_p,
f_pen, question_type, question, answer))

View File

@@ -1,105 +0,0 @@
import openai
import os
from dotenv import load_dotenv
import whisper
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
def correct_answer(
max_tokens,
temperature,
top_p,
frequency_penalty,
question_type,
question,
answer_path
):
model = whisper.load_model("base")
# result = model.transcribe("audio-samples/mynameisjeff.wav", fp16=False, language='English', verbose=True)
if os.path.exists(answer_path):
result = model.transcribe(answer_path, fp16=False, language='English', verbose=True)
answer = result["text"]
print(answer)
res = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
max_tokens=int(max_tokens),
temperature=float(temperature),
top_p=float(top_p),
frequency_penalty=float(frequency_penalty),
messages=
[
{
"role": "user",
"content": "You are a IELTS examiner.",
},
{
"role": "user",
"content": f"The question you have to grade is of type {question_type} and is the following: {question}",
},
{
"role": "user",
"content": "Please provide a JSON object response with the overall grade and breakdown grades, "
"formatted as follows: {'overall': 7.0, 'task_response': {'Fluency and Coherence': 8.0, "
"'Lexical Resource': 6.5, 'Grammatical Range and Accuracy': 7.5, 'Pronunciation': "
"6.0}}",
},
{
"role": "user",
"content": "If the answer is unrelated to the question give it the minimum grade.",
},
{
"role": "user",
"content": f"Evaluate this answer according to ielts grading system: {answer}",
},
],
)
return res["choices"][0]["message"]["content"]
else:
print("File not found:", answer_path)
import streamlit as st
# Set the application title
st.title("GPT-3.5 IELTS Examiner")
# Selection box to select the question type
question_type = st.selectbox(
"What is the question type?",
(
"Speaking Part 1",
"Speaking Part 2",
"Speaking Part 3"
),
)
# Provide the input area for question to be answered
# PT-1: How do you usually spend your weekends? Why?
# PT-2: Describe someone you know who does something well. You should say who this person is, how do you know this person, what they do well and explain why you think this person is so good at doing this.
question = st.text_area("Enter the question:", height=100)
# Provide the input area for text to be summarized
# audio-samples/mynameisjeff.wav
answer_path = st.text_area("Enter the answer path:", height=100)
# Initiate two columns for section to be side-by-side
# col1, col2 = st.columns(2)
# Slider to control the model hyperparameter
# with col1:
token = st.slider("Token", min_value=0.0, max_value=2000.0, value=1000.0, step=1.0)
temp = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.01)
top_p = st.slider("Top_p", min_value=0.0, max_value=1.0, value=0.9, step=0.01)
f_pen = st.slider("Frequency Penalty", min_value=-1.0, max_value=1.0, value=0.5, step=0.01)
# Showing the current parameter used for the model
# with col2:
with st.expander("Current Parameter"):
st.write("Current Token :", token)
st.write("Current Temperature :", temp)
st.write("Current Nucleus Sampling :", top_p)
st.write("Current Frequency Penalty :", f_pen)
# Creating button for execute the text summarization
if st.button("Grade"):
st.write(correct_answer(token, temp, top_p, f_pen, question_type, question, answer_path))

View File

@@ -1,102 +0,0 @@
import openai
import os
from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_summarizer(
max_tokens,
temperature,
top_p,
frequency_penalty,
question_type,
question,
answer
):
res = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
max_tokens=int(max_tokens),
temperature=float(temperature),
top_p=float(top_p),
frequency_penalty=float(frequency_penalty),
messages=
[
{
"role": "user",
"content": "You are a IELTS examiner.",
},
{
"role": "user",
"content": f"The question you have to grade is of type {question_type} and is the following: {question}",
},
{
"role": "user",
"content": "Please provide a JSON object response with the overall grade and breakdown grades, "
"formatted as follows: {'overall': 7.0, 'task_response': {'Task Achievement': 8.0, "
"'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': "
"6.0}}",
},
{
"role": "user",
"content": "Don't give explanations for the grades, just provide the json with the grades.",
},
{
"role": "user",
"content": f"Evaluate this answer according to ielts grading system: {answer}",
},
],
)
return res["choices"][0]["message"]["content"]
import streamlit as st
# Set the application title
st.title("GPT-3.5 IELTS Examiner")
# qt_col, q_col = st.columns(2)
# Selection box to select the question type
# with qt_col:
question_type = st.selectbox(
"What is the question type?",
(
"Listening",
"Reading",
"Writing Task 1",
"Writing Task 2",
"Speaking Part 1",
"Speaking Part 2"
),
)
# Provide the input area for question to be answered
# with q_col:
question = st.text_area("Enter the question:", height=100)
# Provide the input area for text to be summarized
answer = st.text_area("Enter the answer:", height=100)
# Initiate two columns for section to be side-by-side
# col1, col2 = st.columns(2)
# Slider to control the model hyperparameter
# with col1:
token = st.slider("Token", min_value=0.0, max_value=2000.0, value=1000.0, step=1.0)
temp = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.01)
top_p = st.slider("Top_p", min_value=0.0, max_value=1.0, value=0.9, step=0.01)
f_pen = st.slider("Frequency Penalty", min_value=-1.0, max_value=1.0, value=0.5, step=0.01)
# Showing the current parameter used for the model
# with col2:
with st.expander("Current Parameter"):
st.write("Current Token :", token)
st.write("Current Temperature :", temp)
st.write("Current Nucleus Sampling :", top_p)
st.write("Current Frequency Penalty :", f_pen)
# Creating button for execute the text summarization
if st.button("Grade"):
st.write(generate_summarizer(token, temp, top_p, f_pen, question_type, question, answer))

View File

@@ -1,3 +0,0 @@
from helper.heygen_api import create_video
create_video("How has the concept of a 'healthy lifestyle' evolved in recent years, and what role does society play in promoting it?")

View File

@@ -1,257 +0,0 @@
import random
from functools import reduce
import openai
import os
from dotenv import load_dotenv
from app import GRADING_FIELDS, GRADING_TEMPERATURE
from helper.api_messages import get_grading_messages, QuestionType
from helper.openai_interface import make_openai_call, process_response
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 " \
"about their health and also about how they can improve their healthy conditions. Nowadays, information about " \
"how harmful is to smoke for our bodies can be seen in many packets of cigars. This is a clear example how " \
"things can change from our recent past. There is a clear trend in the diminishing of smokers and if this " \
"continues it will have a positive impact in our health. On the other hand, the alimentation habbits are " \
"changing all over the world and this can affect peoples health. However every one can choose what to eat " \
"every day. Mostly everybody, from developed societies, know the importance of having a healthy diet. Advances " \
"such as the information showed in the menus of fast food restaurants will help people to have a clever choice " \
"before they choose what to eat. Another important issue that I would like to mention is how medicine is changing. " \
"There are new discovers and treatments almost every week and that is an inequivoque sintom of how things are " \
"changing in order to improve the worlds health."
# messages = get_grading_messages(QuestionType.WRITING_TASK_2, question, answer)
# token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'],
# 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)
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",
"History of Ancient Civilizations",
"Environmental Conservation",
"Space Exploration",
"Artificial Intelligence",
"Climate Change",
"World Religions",
"The Human Brain",
"Renewable Energy",
"Cultural Diversity",
"Modern Technology Trends",
"Women's Rights",
"Sustainable Agriculture",
"Globalization",
"Natural Disasters",
"Cybersecurity",
"Philosophy of Ethics",
"Robotics",
"Health and Wellness",
"Literature and Classics",
"World Geography",
"Music and Its Influence",
"Human Rights",
"Social Media Impact",
"Food Sustainability",
"Economics and Markets",
"Human Evolution",
"Political Systems",
"Mental Health Awareness",
"Quantum Physics",
"Biodiversity",
"Education Reform",
"Animal Rights",
"The Industrial Revolution",
"Future of Work",
"Film and Cinema",
"Genetic Engineering",
"Ancient Mythology",
"Climate Policy",
"Space Travel",
"Renewable Energy Sources",
"Cultural Heritage Preservation",
"Modern Art Movements",
"Immigration Issues",
"Sustainable Transportation",
"The History of Medicine",
"Artificial Neural Networks",
"Climate Adaptation",
"Philosophy of Existence",
"Augmented Reality",
"Yoga and Meditation",
"Literary Genres",
"World Oceans",
"Gender Equality",
"Social Networking",
"Sustainable Fashion",
"International Trade",
"Prehistoric Era",
"Democracy and Governance",
"Postcolonial Literature",
"Geopolitics",
"Psychology and Behavior",
"Nanotechnology",
"Endangered Species",
"Education Technology",
"Renaissance Art",
"Renewable Energy Policy",
"Cultural Festivals",
"Modern Architecture",
"Climate Resilience",
"Artificial Life",
"Fitness and Nutrition",
"Classic Literature Adaptations",
"World History Wars",
"Ethical Dilemmas",
"Internet of Things (IoT)",
"Meditation Practices",
"Literary Symbolism",
"Marine Conservation",
"Social Justice Movements",
"Sustainable Tourism",
"International Finance",
"Ancient Philosophy",
"Cold War Era",
"Behavioral Economics",
"Space Colonization",
"Clean Energy Initiatives",
"Cultural Exchange",
"Modern Sculpture",
"Climate Mitigation",
"Artificial Intelligence Ethics",
"Mindfulness",
"Literary Criticism",
"Wildlife Conservation",
"Political Activism",
"Renewable Energy Innovations",
"History of Mathematics",
"Human-Computer Interaction",
"Global Health",
"Cultural Appropriation"
]
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.' } } }"
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'}"
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=parse_mc_questions,
max_tokens=int(4097 - token_count - 300),
temperature=0.7
)
# processed = process_response(response, "comment")
processed = process_response(response["choices"][0]["text"], "transcript")
print(processed)