Spaces:
Build error
Build error
Upload utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from groq import Groq
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Initialize Groq client
|
| 5 |
+
client = Groq(api_key=os.environ["GROQ_API_KEY"])
|
| 6 |
+
|
| 7 |
+
def generate_tutor_output(subject, difficulty, student_input, model):
|
| 8 |
+
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"}
|
| 9 |
+
current_model = model_dict[model]
|
| 10 |
+
|
| 11 |
+
prompt = f"""
|
| 12 |
+
You are an expert tutor in {subject} at the {difficulty} level.
|
| 13 |
+
The student has provided the following input: "{student_input}"
|
| 14 |
+
|
| 15 |
+
Please generate:
|
| 16 |
+
1. A brief, engaging lesson on the topic (2-3 paragraphs)
|
| 17 |
+
2. A thought-provoking question to check understanding
|
| 18 |
+
3. Constructive feedback on the student's input
|
| 19 |
+
|
| 20 |
+
Format your response as a JSON object with keys: "lesson", "question", "feedback"
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
completion = client.chat.completions.create(
|
| 24 |
+
messages=[
|
| 25 |
+
{
|
| 26 |
+
"role": "system",
|
| 27 |
+
"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.",
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"role": "user",
|
| 31 |
+
"content": prompt,
|
| 32 |
+
}
|
| 33 |
+
],
|
| 34 |
+
model=current_model,
|
| 35 |
+
max_tokens=1000,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
return completion.choices[0].message.content
|