Spaces:
Running
Running
""" | |
Prompt Template Module - Stores functions for generating LLM prompts | |
""" | |
from typing import Tuple | |
import few_shots_examples | |
def generate_decomposition_prompt(question: str, grade: str, subject: str, learning_needs: str) -> Tuple[str, str]: | |
""" | |
Generate prompts for concept decomposition based on user background | |
Args: | |
question: User's question | |
grade: Educational grade level | |
subject: Subject area | |
learning_needs: Specific learning needs/goals | |
Returns: | |
Tuple of (system_prompt, user_prompt) | |
""" | |
system_prompt = """You are an expert educational AI tutor. Your task is to break down complex questions into fundamental concepts that are appropriate for the student's grade level and background knowledge. | |
Please analyze the question and create a knowledge graph that shows: | |
1. The main concept being asked about | |
2. Essential sub-concepts needed to understand the main concept | |
3. The relationships between these concepts (prerequisite or related) | |
Consider the student's grade level and subject background when determining: | |
- Which concepts to include | |
- How detailed the explanations should be | |
- The appropriate terminology to use | |
- The complexity level of relationships | |
Your response must be in the following JSON format: | |
{ | |
"main_concept": "Core concept name", | |
"Explanation": "Brief, grade-appropriate explanation of the main concept", | |
"sub_concepts": [ | |
{ | |
"id": "unique_id", | |
"name": "Concept name", | |
"description": "Brief, grade-appropriate description", | |
"difficulty": "basic|intermediate|advanced" | |
} | |
], | |
"relationships": [ | |
{ | |
"source": "concept_id", | |
"target": "concept_id", | |
"type": "prerequisite|related", | |
"explanation": "Why this relationship exists" | |
} | |
] | |
}""" | |
user_prompt = f""" | |
Break down the concepts needed to understand this question, considering: | |
1. The student's current grade level and subject knowledge | |
2. Any specific learning needs mentioned | |
3. The logical progression of concepts needed | |
4. Appropriate difficulty levels for each concept | |
Please ensure all explanations and terminology are appropriate for a {grade} level student. | |
Here is an example: | |
Input: "What is Algebra" | |
OUTPUT: {str(few_shots_examples.CONCEPT_DECOMPOSITION_EXAMPLES_1)} | |
Input: "What is the relationship between the mean and variance of a normal distribution." | |
OUTPUT: {str(few_shots_examples.CONCEPT_DECOMPOSITION_EXAMPLES_2)}, | |
Please analyze this question for a {grade} level student studying {subject}. | |
Question: {question} | |
Student Background: | |
- Grade Level: {grade} | |
- Subject: {subject} | |
- Learning Needs: {learning_needs if learning_needs else 'Not specified'} | |
""" | |
return system_prompt, user_prompt | |
def generate_explanation_prompt(concept_name, concept_description, question, grade, subject, learning_needs): | |
""" | |
Generate prompt for concept explanation | |
Args: | |
concept_name: Concept name | |
concept_description: Concept description | |
question: Original question | |
grade: Grade level | |
subject: Subject | |
learning_needs: Learning needs | |
Returns: | |
Tuple of system prompt and user prompt | |
""" | |
system_prompt = """You are an AI assistant in the educational field, specializing in explaining academic concepts and providing constructive learning resources. | |
Your task is to deeply explain the specified concept, providing examples, resources, and practice questions. | |
Your answer must be in valid JSON format, including the following fields: | |
{ | |
"explanation": "Detailed concept explanation", | |
"examples": [ | |
{ | |
"problem": "Example problem", | |
"solution": "Step-by-step solution", | |
"difficulty": "Difficulty level (Easy/Medium/Hard)" | |
}, | |
... | |
], | |
"resources": [ | |
{ | |
"type": "Resource type (Video/Article/Interactive/Book)", | |
"title": "Resource title", | |
"description": "Resource description", | |
"link": "Link (optional)" | |
}, | |
... | |
], | |
"practice_questions": [ | |
{ | |
"question": "Practice question", | |
"answer": "Answer", | |
"difficulty": "Difficulty level (Easy/Medium/Hard)" | |
}, | |
... | |
] | |
} | |
The explanation should be clear, comprehensive, and appropriate for a {grade} level {subject} student's language and difficulty level. | |
Examples should include 1-3 items, ranging from simple to complex, with step-by-step solutions. | |
Resources should be diverse, including videos, articles, interactive tools, etc. | |
Practice questions should include 2-4 items of varying difficulty to help students solidify the concept.""" | |
user_prompt = f"""Please explain the following concept in detail, considering the student's grade, subject background, and learning needs: | |
Concept: {concept_name} | |
Description: {concept_description} | |
Original Question: {question} | |
Grade: {grade} | |
Subject: {subject} | |
Learning Needs: {learning_needs if learning_needs else "Not specified"} | |
Please provide a detailed explanation, relevant examples, learning resources, and practice questions, and return JSON in the specified format.""" | |
return system_prompt, user_prompt | |
# Prompt template for decomposing concepts | |
CONCEPT_DECOMPOSITION_PROMPT = """ | |
Based on the user's question and profile information, please break down the question into multiple essential basic concepts, and output the relationships between these concepts in JSON format. | |
User Profile: | |
- Grade: {grade} | |
- Subject: {subject} | |
- Needs: {needs} | |
User Question: {question} | |
Please follow the format below for your response: | |
```json | |
{ | |
"main_concept": "Main concept name", | |
"sub_concepts": [ | |
{ | |
"id": "concept_1", | |
"name": "Concept 1 name", | |
"description": "Brief description of concept 1" | |
}, | |
{ | |
"id": "concept_2", | |
"name": "Concept 2 name", | |
"description": "Brief description of concept 2" | |
} | |
// More concepts... | |
], | |
"relationships": [ | |
{ | |
"source": "concept_1", | |
"target": "concept_2", | |
"type": "prerequisite" // Can be "prerequisite" or "related" | |
} | |
// More relationships... | |
] | |
} | |
``` | |
Please ensure the generated JSON is correctly formatted, each concept has a unique ID, and the relationships clearly express the dependencies between concepts. | |
""" | |
# Prompt template for generating concept explanations and learning resources | |
CONCEPT_EXPLANATION_PROMPT = """ | |
Please generate detailed explanations, examples, and learning resource suggestions for the following concept based on the user's profile information. | |
User Profile: | |
- Grade: {grade} | |
- Subject: {subject} | |
- Needs: {needs} | |
Selected Concept: {concept_name} | |
Concept Description: {concept_description} | |
Please provide your answer in the following format: | |
```json | |
{ | |
"explanation": "Detailed explanation of the concept, appropriate for the user's grade level...", | |
"examples": [ | |
{ | |
"problem": "Example 1...", | |
"solution": "Solution process and answer...", | |
"difficulty": "Easy/Medium/Hard" | |
}, | |
// More examples... | |
], | |
"resources": [ | |
{ | |
"type": "Video/Book/Website", | |
"title": "Resource title", | |
"description": "Resource description", | |
"link": "Link (optional)" | |
}, | |
// More resources... | |
], | |
"practice_questions": [ | |
{ | |
"question": "Practice question 1...", | |
"answer": "Answer...", | |
"difficulty": "Easy/Medium/Hard" | |
}, | |
// More practice questions... | |
] | |
} | |
``` | |
Please ensure the content is appropriate for the user's grade level, the explanations are easy to understand, and provide valuable learning resources and examples. | |
""" | |