Spaces:
Sleeping
Sleeping
File size: 6,470 Bytes
93fe96e |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# π» Code Practice Feature
## Overview
The Code Practice feature is a new tab in the LLM Curriculum Assistant that allows students to practice programming skills with AI-generated problems and personalized feedback.
## Features
### π― Problem Types
1. **Create Practice Problems**
- Students write code from scratch based on problem descriptions
- Covers various programming concepts (loops, functions, variables, etc.)
2. **Debug - Identify Error Type**
- Students analyze buggy code to identify what type of error it contains
- Helps develop debugging skills and error recognition
3. **Debug - Explain Error Reason**
- Students explain why errors occur in given code
- Builds understanding of error causes and programming logic
4. **Debug - Fix the Error**
- Students fix buggy code and provide corrected solutions
- Practical debugging experience with real code issues
5. **Optimize Code Performance**
- Students improve existing code for better performance
- Focus on efficiency, loops, algorithms, and best practices
### π¨ User Interface
The Code Practice tab features:
- **Topic Input**: Students specify what they want to practice (e.g., "for loops", "functions", "recursion")
- **Problem Type Dropdown**: Choose from 5 different practice modes
- **Generate Problem Button**: Creates a new practice problem using LLM
- **Problem Description**: Clear instructions and requirements with formatted example outputs
- **Code Editor**: VS Code-style editor for writing solutions
- **Student Code Input**: Dedicated editor for student solutions
- **Analyze Button**: Execute code and get AI feedback
- **Terminal Output**: Shows actual code execution results and errors
- **Analysis Output**: Detailed feedback with suggestions and explanations
### π€ AI-Powered Features
- **Curriculum-Based Problem Generation**: LLM creates problems based on actual curriculum content and difficulty level
- **Intelligent Code Analysis**: Provides detailed feedback that references curriculum concepts and standards
- **Personalized Feedback**: Encouraging but honest assessment aligned with curriculum learning objectives
- **Educational Explanations**: Helps students understand concepts based on what they've learned in class
## How to Use
1. **Navigate to Code Practice Tab**
- Click on the "π» Code Practice" tab in the main interface
2. **Set Up Your Practice Session**
- Enter a topic you want to practice (e.g., "for loops", "recursion", "arrays")
- Select a problem type from the dropdown menu
- Click "π² Generate Problem" to get a new practice problem
3. **Work on the Problem**
- Read the problem description carefully
- Use the code editor to write your solution
- The editor supports Python syntax highlighting
4. **Get Feedback**
- Click "π Analyze My Code" to receive AI feedback
- Review the detailed analysis and suggestions
- Use the feedback to improve your solution
5. **Practice More**
- Generate new problems to continue practicing
- Try different problem types to develop various skills
## Technical Implementation
### CodePracticeAssistant Class
The new `CodePracticeAssistant` class handles:
- **Curriculum Integration**: Uses the curriculum assistant's vector database to find relevant content
- **LLM Integration**: Uses Claude 3.5 Haiku for problem generation and code analysis
- **Problem Generation**: Creates problems based on actual curriculum content and difficulty level
- **Code Analysis**: Provides comprehensive feedback that references curriculum concepts
- **Error Handling**: Graceful handling of API errors and edge cases
### Key Methods
- `generate_practice_problem(topic, problem_type)`: Creates new practice problems based on curriculum content
- `analyze_student_code(topic, problem_type, problem_description, student_code)`: Analyzes student solutions with curriculum context
- `execute_code(student_code)`: Safely executes student code and returns terminal output
- `_find_curriculum_content(topic)`: Finds relevant curriculum content for the given topic
### UI Components
- **Gradio Tabs**: Organized interface with separate tabs for chat and practice
- **Code Editors**: Syntax-highlighted code input areas
- **Markdown Outputs**: Formatted problem descriptions and analysis
- **Interactive Buttons**: Generate and analyze functionality
## Benefits for Students
1. **Personalized Learning**: Practice specific topics at your own pace
2. **Immediate Feedback**: Get instant analysis of your code
3. **Multiple Skill Development**: Practice writing, debugging, and optimizing code
4. **Safe Learning Environment**: Make mistakes and learn from AI feedback
5. **Progressive Difficulty**: Problems adapt to your skill level
## Integration with Existing Features
The Code Practice feature seamlessly integrates with the existing curriculum assistant:
- **Shared LLM Infrastructure**: Uses the same Claude API for consistency
- **Unified Interface**: Both features accessible from the same application
- **Consistent Experience**: Similar UI patterns and interaction models
- **Complementary Learning**: Chat for questions, Practice for hands-on coding
## Future Enhancements
Potential improvements could include:
- **Difficulty Levels**: Beginner, Intermediate, Advanced options
- **Progress Tracking**: Save completed problems and track improvement
- **Hints System**: Get progressive hints when stuck
- **Code Execution**: Run code and see actual output
- **Collaborative Features**: Share problems with classmates
- **Custom Problem Creation**: Teachers can create custom problems
## Requirements
- Python 3.7+
- Anthropic API key (ANTHROPIC_KEY environment variable)
- All existing dependencies from requirements.txt
## Usage Example
```python
# Initialize the practice assistant
practice_assistant = CodePracticeAssistant()
# Generate a practice problem
problem, starter_code = practice_assistant.generate_practice_problem(
topic="for loops",
problem_type="Create Practice Problems"
)
# Analyze student code
analysis = practice_assistant.analyze_student_code(
topic="for loops",
problem_type="Create Practice Problems",
problem_description=problem,
student_code="def sum_list(nums):\n return sum(nums)"
)
```
The Code Practice feature transforms the curriculum assistant into a comprehensive learning platform that combines theoretical knowledge with practical coding experience. |