Skip to content

Instantly share code, notes, and snippets.

@jayo78
Created January 7, 2023 18:46
Show Gist options
  • Save jayo78/afe93f6002f7351bc848ea5c201c0edb to your computer and use it in GitHub Desktop.
Save jayo78/afe93f6002f7351bc848ea5c201c0edb to your computer and use it in GitHub Desktop.
import openai
openai.api_key = "YOUR_API_KEY_HERE"
gpt3_prompt = """
Grade the following essay and output a thorough analysis with examples and justifications. Output in the following JSON format:
{ "grade": ${grade}, "analysis": ${tone} }
PROMPT: <PROMPT>
ESSAY: <ESSAY>
"""
def grade_essay(prompt, response):
model_engine = "text-davinci-003"
prompt = gpt3_prompt.replace("<PROMPT>", prompt).replace("<ESSAY>", response)
completions = openai.Completion.create(engine=model_engine, prompt=prompt, max_tokens=1024, n=1,stop=None,temperature=0.5)
message = completions.choices[0].text
return message
prompt = "Write an essay on the impact of technology on society."
response = "Technology has had a significant impact on society in recent years. It has transformed the way we communicate, access information, and do business. One of the main benefits of technology is the ability to connect people from all around the world through social media and other platforms. It has also made it easier for people to access education and job opportunities online. However, technology has also had negative impacts on society. It has contributed to a decrease in face-to-face communication and an increase in cyberbullying. In addition, the reliance on technology has led to a decrease in critical thinking skills and an increase in misinformation. Overall, while technology has brought many benefits to society, it is important to use it responsibly and consider the potential downsides."
print(grade_essay(prompt, response))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment