Spaces:
Sleeping
Sleeping
feat: modify the generative ai prompt to focus more on the specified question
Browse files- inference_api.py +22 -9
inference_api.py
CHANGED
|
@@ -513,6 +513,7 @@ class Interaction(BaseModel):
|
|
| 513 |
skill_id: str = Field(..., description="Skill ID or underscore-separated ID compound like '2_37'")
|
| 514 |
correctness: int = Field(..., description="Is the response correct (1) or incorrect (0)")
|
| 515 |
ms_first_response: int = Field(..., description="Time taken to answer in milliseconds")
|
|
|
|
| 516 |
|
| 517 |
|
| 518 |
class PredictRequest(BaseModel):
|
|
@@ -594,7 +595,11 @@ def predict(req: PredictRequest):
|
|
| 594 |
# Call Gemini GenAI if triggered
|
| 595 |
explanation = None
|
| 596 |
if struggling_skills_triggered:
|
| 597 |
-
explanation = trigger_gemini_explanation(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
else:
|
| 599 |
logger.info("Generative AI was not triggered (no skills met both mastery and history length triggers).")
|
| 600 |
|
|
@@ -630,18 +635,26 @@ def predict(req: PredictRequest):
|
|
| 630 |
return PredictResponse(category_mastery=category_mastery, explanation=explanation)
|
| 631 |
|
| 632 |
|
| 633 |
-
def trigger_gemini_explanation(skills: List[str], preference: str) -> str:
|
| 634 |
-
"""Call Google Gemini Generative AI to generate personalized hint."""
|
| 635 |
logger.info(f"[GenAI Trigger] Contacting Gemini for struggling skills: {skills}")
|
| 636 |
-
logger.info(f"[GenAI Trigger]
|
|
|
|
|
|
|
| 637 |
|
| 638 |
prompt = (
|
| 639 |
f"A student is struggling with the following math concepts: {', '.join(skills)}.\n"
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
)
|
| 646 |
|
| 647 |
logger.info(f"[Gemini Prompt]\n{prompt}")
|
|
|
|
| 513 |
skill_id: str = Field(..., description="Skill ID or underscore-separated ID compound like '2_37'")
|
| 514 |
correctness: int = Field(..., description="Is the response correct (1) or incorrect (0)")
|
| 515 |
ms_first_response: int = Field(..., description="Time taken to answer in milliseconds")
|
| 516 |
+
question: Optional[str] = Field(None, description="The text of the question, if available")
|
| 517 |
|
| 518 |
|
| 519 |
class PredictRequest(BaseModel):
|
|
|
|
| 595 |
# Call Gemini GenAI if triggered
|
| 596 |
explanation = None
|
| 597 |
if struggling_skills_triggered:
|
| 598 |
+
explanation = trigger_gemini_explanation(
|
| 599 |
+
skills=struggling_skills_triggered,
|
| 600 |
+
preference=req.personal_preference,
|
| 601 |
+
question=most_recent.question
|
| 602 |
+
)
|
| 603 |
else:
|
| 604 |
logger.info("Generative AI was not triggered (no skills met both mastery and history length triggers).")
|
| 605 |
|
|
|
|
| 635 |
return PredictResponse(category_mastery=category_mastery, explanation=explanation)
|
| 636 |
|
| 637 |
|
| 638 |
+
def trigger_gemini_explanation(skills: List[str], preference: str, question: Optional[str] = None) -> str:
|
| 639 |
+
"""Call Google Gemini Generative AI to generate personalized hint using their hobby/interest."""
|
| 640 |
logger.info(f"[GenAI Trigger] Contacting Gemini for struggling skills: {skills}")
|
| 641 |
+
logger.info(f"[GenAI Trigger] Student Hobby: \"{preference}\"")
|
| 642 |
+
if question:
|
| 643 |
+
logger.info(f"[GenAI Trigger] Specific Question: \"{question}\"")
|
| 644 |
|
| 645 |
prompt = (
|
| 646 |
f"A student is struggling with the following math concepts: {', '.join(skills)}.\n"
|
| 647 |
+
)
|
| 648 |
+
if question:
|
| 649 |
+
prompt += f"The specific math question they are struggling with is: \"{question}\"\n"
|
| 650 |
+
|
| 651 |
+
prompt += (
|
| 652 |
+
f"The student's hobby / interest is: \"{preference}\"\n\n"
|
| 653 |
+
"Please generate a warm, encouraging math hint in Bahasa Indonesia. "
|
| 654 |
+
"The response MUST focus heavily on solving this specific question step-by-step "
|
| 655 |
+
f"using their hobby (\"{preference}\") as a creative analogy, theme, or context to make it highly engaging and easy to understand. "
|
| 656 |
+
"If the question requires step-by-step mathematical problem solving, show the clear step-by-step calculations. "
|
| 657 |
+
"Keep the overall response extremely concise and strictly under 10 lines total."
|
| 658 |
)
|
| 659 |
|
| 660 |
logger.info(f"[Gemini Prompt]\n{prompt}")
|