Spaces:
Sleeping
Sleeping
File size: 3,102 Bytes
45aa75b 1ef4b34 45aa75b bbc58d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import os
from openai import OpenAI
# client = OpenAI(
# base_url="https://api.groq.com/openai/v1",
# api_key=os.getenv("GROQ_API_KEY")
# )
client = OpenAI(api_key = os.getenv("OPENAI_API_KEY"))
def beat_the_ai(theme, score):
ques_prompt = (
f"Generate a unique, factually accurate quiz question on the theme of {theme} \n"
f"The user's current score is {score} out of 100. Use this score to adaptively determine the difficulty of the question — higher scores should correspond to higher difficulty levels.\n"
"Ensure that:\n"
"1. The question is factually accurate, unique, and not similar to previous questions. Make the question as innovative as possible so that it doesn't get repeated.\n"
"2. Options: A, B, C, D.\n"
"3. The correct answer is accurate and clearly marked.\n"
"4. Difficulty: Easy, Medium, Hard. The difficulty level is dynamically adjusted based on the user’s performance in the challenge:\n"
"-If the user score(out of 100) is high: Increase the difficulty of subsequent questions.\n"
"-If the user score(out of 100) is low: Lower the difficulty to provide a chance to regain confidence, but maintain a challenge level that requires learning and growth.\n"
f"4. Assign a difficulty level (Easy, Medium, or Hard) to the question.\n"
f" Evaluate the difficulty using the following weighted criteria (total score out of 10):\n"
f" - Concept Complexity (30%):\n"
f" * 1 = Basic, 2 = Intermediate, 3 = Advanced\n"
f" - Application Level (25%):\n"
f" * 1 = Pure recall, 2 = Application-based, 3 = Higher-order thinking\n"
f" - Ambiguity (15%):\n"
f" * 1 = Clear and straightforward, 2 = Moderate trickiness, 3 = Ambiguous or misleading\n"
f" - Time Requirement (15%):\n"
f" * 1 = <15 seconds, 2 = 15–45 seconds, 3 = >45 seconds to solve\n"
f" - Prerequisite Knowledge (15%):\n"
f" * 1 = None or very basic, 2 = Requires some prior understanding, 3 = Requires strong foundational knowledge\n"
f" Calculate the total weighted score and assign difficulty as follows:\n"
f" * 1.0 - 3.5 = Easy\n"
f" * 3.6 - 6.5 = Medium\n"
f" * 6.6 - 10.0 = Hard\n\n"
"Provide response in this format:\n"
"Theme: [Theme]\n"
"Question: [Your question here]\n"
"A) [Option A]\n"
"B) [Option B]\n"
"C) [Option C]\n"
"D) [Option D]\n"
"Correct answer: [Correct option letter]. Just return the option A, B, C or D and nothing else.\n"
"Difficulty level: [Easy/Medium/Hard]"
"Do not provide the parameter details just consider them for yourself."
)
response = client.chat.completions.create(
model="gpt-4-1106-preview",
messages=[
{"role": "system", "content": "You are a helpful assistant who generates quizzes."},
{"role": "user", "content": ques_prompt}
],
temperature=0.5,
max_tokens=1024
)
return response.choices[0].message.content.strip()
# print(beat_the_ai("Science", 75)) |