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