Fun Fact: Built this entire project from scratch in under 24 hoursβbecause who needs sleep when thereβs code to write? π€π₯
A Software Engineering Intern Assignment that creates an interactive chat application UI functioning as a teaching assistant for Data Structures and Algorithms (DSA) problems. This application leverages GPT to provide guided assistance without revealing direct solutions.
Untitled.video.-.Made.with.Clipchamp.1.mp4
This application allows users to:
- Submit LeetCode problem URLs
- Ask specific questions about DSA problems
- Receive guided hints and intuition-building responses
- Develop problem-solving skills through interactive dialogue
The GPT-powered teaching assistant is designed to help users understand problems better rather than providing ready-made solutions. It functions as a mentor that guides users toward developing their own solutions.
- Features
- Setup Instructions
- Architecture
- Usage Guidelines
- GPT Integration & Prompt Design
- Project Structure
- Interactive Chat Interface: Clean, responsive UI for seamless interaction
- Guided Learning: Provides hints and guidance without direct solutions
- Conversation Management: Save, bookmark, and retrieve conversations
- Dark Mode: Toggle between light and dark themes for comfortable viewing
- Custom Prompting System: Structured prompt engineering for effective learning
- Markdown Support: Properly formatted code snippets and explanations
- Node.js (v14.0.0 or higher)
- NPM (v6.0.0 or higher)
- Gemini API key
-
Clone the Repository
git clone https://github.com/medss19/GPT-Teaching-Assistant.git cd GPT-Teaching-Assistant/frontend
-
Install Dependencies
npm install
-
Set Up Environment Variables Create a
.env
file in thefrontend
directory:VITE_GEMINI_API_KEY=your-api-key-here
-
Run Development Server
npm run dev
-
Build for Production
npm run build npm run preview # To preview the build
The application follows a modular React architecture built with Vite for optimal performance and developer experience.
App (Root)
βββ Chat (Main Container)
β βββ ChatHeader (Title & Controls)
β βββ ChatMessages (Conversation Display)
β β βββ MessageItem (Individual Messages)
β βββ ChatInput (User Input)
βββ Sidebar (Navigation)
βββ ConversationList (Chat History)
βββ BookmarkedList (Saved Conversations)
- App.jsx: Application entry point and routing
- Chat.jsx: Main container orchestrating the chat interface
- useChat.js: Custom hook managing chat state and logic
- api.js: API communication with the Gemini model
- systemPrompts.js: Structured prompts for GPT interaction
- teachingPatterns.js: Educational patterns for guiding users
The application uses React's Context API and custom hooks to manage:
- Conversation history
- Current chat state
- Bookmarked conversations
- User preferences
- Click the "New Conversation" button in the sidebar
- Enter a LeetCode problem URL in the input field:
https://leetcode.com/problems/two-sum/
- Type your specific doubt or question:
I understand we need to find two numbers that add up to the target, but I'm not sure how to avoid the O(nΒ²) approach
- Press Enter or click the Send button
- Switch Conversations: Click on any conversation in the sidebar
- Bookmark: Click the bookmark icon (limited to 2 bookmarks)
- Delete: Click the delete icon to remove a conversation
- Dark Mode: Toggle using the button in the chat header
The application integrates with the Gemini API to leverage GPT capabilities for teaching assistance.
For a comprehensive explanation of our prompt engineering approach, please see our DSA Teaching Assistant Prompt Guide.
Prompts are carefully designed to:
- Analyze Problems: Extract key information from LeetCode URLs
- Guide Rather Than Solve: Help users discover solutions independently
- Build Intuition: Develop problem-solving patterns and techniques
- Provide Analogies: Explain complex concepts with relatable examples
- Encourage Reflection: Ask questions that deepen understanding
const basePrompt = `
You are a Data Structures and Algorithms (DSA) teaching assistant.
Your goal is to help the student understand the problem and develop their own solution.
NEVER provide the complete solution. Instead:
1. Help them understand the problem statement
2. Guide them to identify key patterns or algorithms
3. Provide small hints that build intuition
4. Ask leading questions to develop their problem-solving skills
`;
The application communicates with the Gemini API using:
const callGeminiAPI = async (prompt) => {
try {
const response = await fetch(GEMINI_API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
contents: [{ parts: [{ text: prompt }] }],
generationConfig: {
temperature: 0.7,
maxOutputTokens: 2048,
},
}),
});
// Process and return response
} catch (error) {
console.error('Error calling Gemini API:', error);
return { error: true, message: 'Failed to get response' };
}
};
frontend/
βββ public/ # Static assets
βββ src/
β βββ components/
β β βββ chat/ # Chat UI components
β β β βββ Chat.jsx # Main chat container
β β β βββ ChatHeader.jsx # Title and controls
β β β βββ ChatInput.jsx # User input handling
β β β βββ ChatMessages.jsx # Message display
β β β βββ MessageItem.jsx # Individual message rendering
β β β βββ WelcomeMessage.jsx # Initial instructions
β β βββ sidebar/ # Navigation components
β β β βββ Sidebar.jsx # Main sidebar container
β β β βββ ConversationList.jsx # Chat history
β β β βββ BookmarkedList.jsx # Saved conversations
β β βββ utils/ # Helper functions
β β βββ api.js # API communication
β β βββ formatters.jsx # Text formatting utilities
β β βββ systemPrompts.js # GPT prompt templates
β β βββ teachingPatterns.js # Educational patterns
β βββ hooks/
β β βββ useChat.js # Custom chat logic hook
β βββ assets/ # Images and icons
β βββ App.jsx # Main application component
β βββ main.jsx # Entry point
βββ .env # Environment variables
βββ package.json # Dependencies
βββ vite.config.js # Build configuration
- Voice Input/Output: Add speech recognition and text-to-speech for accessibility
- Code Execution: Allow users to run code snippets directly in the chat
- Progress Tracking: Monitor user improvement over time
- Problem Recommendations: Suggest relevant problems based on user interaction
- Multiple GPT Models: Allow switching between different teaching styles
-
URL Request Repetition: The chatbot may occasionally ask for a URL again even after you've already provided one.
-
Context Confusion: Sometimes the chatbot may reference previous conversations and produce answers related to prior questions when responding to a new query.
-
Formula Formatting Limitations: Complex mathematical notations (such as formulas with superscripts or special symbols) may display incorrectly or with formatting issues.
-
Limited Teaching Patterns: The current teaching interaction patterns are limited in scope and could be expanded in future updates.
-
Occasional Glitches: In rare instances, the conversation may experience a glitch that produces unrelated or unsolicited responses. If this occurs, restarting the application is recommended.
Example
I have worked diligently to create a user-friendly and functional chatbot experience, with continuous improvements planned for future releases.