Spaces:
Sleeping
Sleeping
| import os | |
| import openai | |
| client = openai.OpenAI( | |
| base_url="https://api.groq.com/openai/v1", | |
| api_key=os.getenv("GROQ_API_KEY") | |
| ) | |
| def generate_question_random(): | |
| ques_prompt = ( | |
| "Generate only one unique, factually accurate quiz question on any theme from a wide variety of topics. " | |
| "Generate question on a different theme each time involve literature, sports, science, mathematics, technology and other themes" | |
| "Question generated in each chat has to be a new question. Don't generate even a similar question to previous one. Make the question as innovative as possible so that it doesn't get repeated." | |
| "Ensure that:\n" | |
| "1. The question is unique.\n" | |
| "2. Options: A, B, C, D.\n" | |
| "3. Correct answer should be marked.\n" | |
| "4. Difficulty: Easy, Medium, Hard.\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]\n" | |
| "Difficulty level: [Easy/Medium/Hard]" | |
| ) | |
| response = client.chat.completions.create( | |
| model="llama-3.3-70b-versatile", | |
| 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 | |