import openai import csv import json key = open("key", "r") # Set the API key openai.api_key = key.readline() key.close() # Set the model to use model_engine = "text-davinci-003" topics = ["Consumer Healthcare", "Fitness", "Wellness"] content_count = [] industry = [] for t in topics: print("How many quizes do you want to generate about topic:"+t) count = int(input()) content_count.append(count) with open("quiz.csv", "a") as file: reader = csv.writer(file) t = 0 for topic in topics: c = 0 for count in range(content_count[c]): print("Feed in content to write about for"+topic) content = input() print( "Write a brief summary of your content. Or press enter to let the ai generate it for you") summary = input() if(summary == ""): summaryprompt = "Write a brief summary of the followign content: "+content summaryresult = openai.Completion.create( engine=model_engine, prompt=summaryprompt, max_tokens=1024, n=1, stop=None, temperature=0.5) # Print the generated text summary = summaryresult.text print("Summary:"+summary) print("How many questions do you want to write?") question_count = input() print("Answer count?") answer_count = input() # Set the prompt to use as input prompt = "Given the following text, write exactly "+str(question_count)+"multiple choice quiz questions each with "+str(answer_count) + " possible answers and write down whether each answer is wrong or right and why. in the 'questions' column questions column should be enclosed in square brackets separated by a comma. answers column should have the answers enclosed in square brackets separated by comma, right_answer should be an array of correct answer indexes for each of the questions. In the descriptions column write descriptions of each answer choice separated by comma enclosed in square brackets for the column descriptions for each answer separate by comma and enclose in square brackets. For right answer index, write down why the answer is correct, for all other indexes write down why the answer is wrong. In descriptions, enclose in square brackets descriptions of the wrong answers and description of the right answers separated by commas. Do not enclose any values in quotes. \n" + \ " Your response should be in CSV format in the order of 'questions','answers','right_answer','descriptions': reply only in this csv format." + \ """[Question 1,Question 2,Question 3,Question 4],[["a","b","c","d"],["a","b","c","d"]],[3,3],[[incorrect because,incorrect because,correct because, incorrect beacuse],[incorrect because,incorrect because,correct because, incorrect beacuse]]""" + content # Generate text using the GPT-3 model response = openai.Completion.create( engine=model_engine, prompt=prompt, max_tokens=1024, n=1, stop=None, temperature=0.5) # Print the generated text print(response["choices"][0].text) reader.writerow([response["choices"][0].text]) c += 1