175 lines
7.3 KiB
Python
175 lines
7.3 KiB
Python
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")
|
||
|
||
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 people’s 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 world’s 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)
|
||
|
||
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.' } } }"
|
||
|
||
token_count = count_tokens(gen_listening2_message)["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"]
|
||
|
||
# processed = process_response(response, "comment")
|
||
processed = process_response(response, "transcript")
|
||
print(processed)
|
||
|