Spaces:
Sleeping
Sleeping
File size: 1,626 Bytes
1da8db2 |
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 |
from groq import Groq
import os
# Initialize Groq client
client = Groq(api_key=os.environ["GROQ_API_KEY"])
def generate_tutor_output(subject, difficulty, student_input, model):
model_dict = {"LLAMA3 8B": "llama3-groq-8b-8192-tool-use-preview", "LLAMA3 70B": "llama3-groq-70b-8192-tool-use-preview","Mixtral 8x7B": "mixtral-8x7b-32768"}
current_model = model_dict[model]
prompt = f"""
You are an expert tutor in {subject} at the {difficulty} level.
The student has provided the following input: "{student_input}"
Please generate:
1. A brief, engaging lesson on the topic (2-3 paragraphs)
2. A thought-provoking question to check understanding
3. Constructive feedback on the student's input
Format your response as a JSON object with keys: "lesson", "question", "feedback"
"""
completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "You are the world's best AI tutor, renowned for your ability to explain complex concepts in an engaging, clear, and memorable way and giving math examples. Your expertise in {subject} is unparalleled, and you're adept at tailoring your teaching to {difficulty} level students. Your goal is to not just impart knowledge, but to inspire a love for learning and critical thinking.",
},
{
"role": "user",
"content": prompt,
}
],
model=current_model,
max_tokens=1000,
)
return completion.choices[0].message.content |