UNPKG

education-module-ai

Version:
346 lines (281 loc) 9.42 kB
# Education Module for Agent Framework This module provides educational content management, learning sessions, and user profile tracking for the Agent Framework. ## Features - **Educational Content Management**: Create, retrieve, and search educational content across various subjects and levels - **Learning Sessions**: Interactive learning sessions with AI-powered responses and content recommendations - **User Profiles**: Track user progress, learning styles, strengths, and weaknesses - **Analytics**: Track usage patterns and learning progress - **Notifications**: Send notifications for learning activities and achievements - **Reusable UI Components**: Ready-to-use React components for quizzes, Q&A, and learning paths ## Installation ```bash npm install @agent-framework/education-module ``` ## Usage ### Backend Integration ```typescript import { initializeEducationAPI } from '@agent-framework/education-module'; // Initialize the education API const app = await initializeEducationAPI(); // The API is now running with the following endpoints: // - /api/educational-contents // - /api/learning-sessions // - /api/user-profiles ``` ### Frontend Integration #### Using Data Resources ```typescript import { EducationalContentResource, LearningSessionResource, UserProfileResource } from '@agent-framework/education-module'; // Fetch educational content const fetchContent = async (subject) => { const response = await fetch(`/api/educational-contents/subject/${subject}`); const { data } = await response.json(); return data; }; // Start a learning session const startSession = async (userId, subject, level) => { const response = await fetch('/api/learning-sessions/start', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId, subject, level }), }); const { data } = await response.json(); return data; }; // Send a message in a learning session const sendMessage = async (sessionId, content) => { const response = await fetch(`/api/learning-sessions/${sessionId}/message`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content }), }); const { data } = await response.json(); return data; }; ``` #### Using React Components ```tsx import React from 'react'; import { QuizComponent, AnswerQuestionComponent, LearningPathComponent } from '@agent-framework/education-module'; // In your React application const EducationPage: React.FC = () => { return ( <div className="education-container"> <h1>Education Portal</h1> {/* Quiz Component */} <QuizComponent title="Computer Science Quiz" description="Test your knowledge in computer science" onComplete={(score) => console.log('Quiz completed with score:', score)} /> {/* Q&A Component */} <AnswerQuestionComponent title="Ask Your Questions" onAnswer={(question, answer) => console.log('Question answered:', question)} /> {/* Learning Path Component */} <LearningPathComponent title="Generate Learning Path" onGenerate={(path) => console.log('Learning path generated:', path)} /> </div> ); }; export default EducationPage; ``` ## UI Components ### Quiz Component The `QuizComponent` allows users to generate and take quizzes on any topic. ```tsx import { QuizComponent } from '@agent-framework/education-module'; <QuizComponent title="Custom Quiz Title" description="Custom description for this quiz generator" onComplete={(score) => { console.log(`Quiz completed with ${score.percentage}% correct`); }} className="custom-class-name" /> ``` #### Props - `title`: Optional custom title for the quiz component - `description`: Optional custom description text - `onComplete`: Optional callback function that's called when a quiz is completed - `className`: Optional CSS class name for styling ### Answer Question Component The `AnswerQuestionComponent` provides an interface for users to ask educational questions and get AI-powered answers. ```tsx import { AnswerQuestionComponent } from '@agent-framework/education-module'; <AnswerQuestionComponent title="Custom Q&A Title" description="Ask any question and get detailed answers" onAnswer={(question, answer) => { console.log(`Question: ${question}`); console.log(`Answer: ${answer.answer}`); }} className="custom-class-name" /> ``` #### Props - `title`: Optional custom title for the Q&A component - `description`: Optional custom description text - `onAnswer`: Optional callback function that's called when a question is answered - `className`: Optional CSS class name for styling ### Learning Path Component The `LearningPathComponent` generates personalized learning paths for any topic. ```tsx import { LearningPathComponent } from '@agent-framework/education-module'; <LearningPathComponent title="Custom Learning Path Title" description="Generate a personalized learning path for any topic" onGenerate={(path) => { console.log(`Learning path generated for: ${path.subject}`); }} className="custom-class-name" /> ``` #### Props - `title`: Optional custom title for the learning path component - `description`: Optional custom description text - `onGenerate`: Optional callback function that's called when a learning path is generated - `className`: Optional CSS class name for styling ## API Endpoints ### Educational Content - `GET /api/educational-contents`: Get all educational content - `GET /api/educational-contents/:id`: Get content by ID - `POST /api/educational-contents`: Create new content - `PUT /api/educational-contents/:id`: Update content - `DELETE /api/educational-contents/:id`: Delete content - `POST /api/educational-contents/generate`: Generate content using AI - `POST /api/educational-contents/quiz`: Generate a quiz - `GET /api/educational-contents/search`: Search for content - `GET /api/educational-contents/subject/:subject`: Get content by subject - `GET /api/educational-contents/level/:level`: Get content by level ### Learning Sessions - `GET /api/learning-sessions`: Get all learning sessions - `GET /api/learning-sessions/:id`: Get session by ID - `POST /api/learning-sessions/start`: Start a new learning session - `POST /api/learning-sessions/:id/end`: End a learning session - `POST /api/learning-sessions/:id/message`: Send a message in a session - `GET /api/learning-sessions/user/:userId`: Get all sessions for a user - `GET /api/learning-sessions/user/:userId/active`: Get active session for a user ### User Profiles - `GET /api/user-profiles`: Get all user profiles - `GET /api/user-profiles/:id`: Get profile by ID - `POST /api/user-profiles/initialize`: Initialize a new user profile - `PUT /api/user-profiles/:id/learning-styles`: Update learning styles - `POST /api/user-profiles/:id/subjects`: Add a subject to user profile - `GET /api/user-profiles/:id/recommendations`: Get learning recommendations - `GET /api/user-profiles/:id/progress/:subject`: Get subject progress - `POST /api/user-profiles/:id/attributes`: Add strength or weakness ## Models ### Educational Content ```typescript enum ContentType { LESSON = "lesson", EXERCISE = "exercise", QUIZ = "quiz", ARTICLE = "article", VIDEO = "video", INTERACTIVE = "interactive", } enum EducationalLevel { BEGINNER = "beginner", INTERMEDIATE = "intermediate", ADVANCED = "advanced", } enum Subject { MATHEMATICS = "mathematics", SCIENCE = "science", HISTORY = "history", LANGUAGE_ARTS = "language_arts", COMPUTER_SCIENCE = "computer_science", ART = "art", MUSIC = "music", PHYSICAL_EDUCATION = "physical_education", FOREIGN_LANGUAGE = "foreign_language", } interface EducationalContentResource { id: string; title: string; description: string; content: string; type: ContentType; subject: Subject; level: EducationalLevel; tags: string[]; createdAt: Date; updatedAt: Date; author?: string; relatedContentIds?: string[]; } ``` ### Learning Session ```typescript enum InteractionType { QUESTION = "question", ANSWER = "answer", EXPLANATION = "explanation", QUIZ_RESPONSE = "quiz_response", FEEDBACK = "feedback", } interface SessionMessage { role: "user" | "assistant"; content: string; timestamp: Date; interactionType: InteractionType; relatedContentIds?: string[]; } interface LearningSessionResource { id: string; userId: string; subject: Subject; level: EducationalLevel; startTime: Date; endTime?: Date; active: boolean; messages: SessionMessage[]; feedback?: string; } ``` ### User Profile ```typescript enum LearningStyle { VISUAL = "visual", AUDITORY = "auditory", READING_WRITING = "reading_writing", KINESTHETIC = "kinesthetic", LOGICAL = "logical", SOCIAL = "social", SOLITARY = "solitary", } interface SubjectProgress { level: EducationalLevel; completedSessions: number; lastSessionDate: Date | null; masteredConcepts: string[]; strugglingConcepts: string[]; score: number; } interface UserProfileResource { id: string; name?: string; email?: string; createdAt: Date; updatedAt: Date; subjectProgress: Record<Subject, SubjectProgress>; learningStyles: LearningStyle[]; strengths: string[]; weaknesses: string[]; } ``` ## License MIT