An intelligent chatbot designed to help users navigate MarginFi's platform and understand DeFi concepts. Powered by GPT-4 and RAG (Retrieval Augmented Generation), this AI assistant provides context-aware, real-time responses with a sleek, modern interface.
π Note: RAG (Retrieval Augmented Generation) enhances the AI's responses by pulling relevant information from MarginFi's documentation in real-time. This means the chatbot provides accurate, up-to-date answers specific to MarginFi's platform, rather than relying solely on GPT-4's general knowledge.
MarginFiDemo.mov
Currently, MarginFi's website has limited search capabilities:
- Search is restricted to FAQ pages only
- Requires exact keyword matching
- Limited support for natural language questions
- New users struggle to find basic information about MarginFi
- Difficult for beginners to understand DeFi concepts
My AI Chatbot addresses these challenges by providing:
- Natural language understanding with MarginFi-specific context
- Real-time, conversational responses
- RAG-powered accurate information about MarginFi and DeFi
- Beginner-friendly explanations
- Instant access to platform navigation help
- Sleek Interface: Built with modern design principles
- Responsive Layout: Adapts perfectly to any device
- Smooth Animations: Polished user interactions
- Custom Theming: Matches MarginFi's brand identity
- Floating Chat Window: Easy access from any page
- Context-Aware Responses: Understands user's knowledge level
- Suggested Questions: Common queries for new users
- Dark/Light Mode: Toggle between dark and light themes
- File Attachments: Share files through the paperclip icon
- Message Actions: Edit and copy message content
- Expandable Window: Toggle between compact and full-screen modes
- Live Streaming: See answers as they're being generated
- Interactive Guidance: Step-by-step help for complex tasks
- Voice Input: Speak your questions naturally
- GPT-4 + RAG Integration: Context-aware responses using MarginFi's documentation
- Real-Time Streaming: Instant response generation
- Server-Sent Events: Efficient data transmission
- Modern Stack: Next.js 14, TypeScript, Tailwind CSS
- Responsive Design: Works seamlessly on all devices
- Accessibility: WCAG 2.1 compliant
- Clone the repository:
git clone https://github.com/stephanienguyen2020/marginfi_chatbot
- Install dependencies:
npm install
# or
yarn install
# or
pnpm install
- Set up your environment variables:
- Copy
.env.sample
to.env.local
- Add your API keys to
.env.local
:
- Copy
OPENAI_API_KEY=your_api_key_here
LANGCHAIN_API_KEY=your_langchain_api_key_here
Note: The LangChain API key is required for tracing and monitoring your RAG pipeline. You can get it from LangSmith.
- Run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
- Open http://localhost:3000 in your browser
src/
βββ app/
β βββ api/
β β βββ chat/
β β βββ route.ts # API endpoint for chat
β β βββ prompts.ts # System and response guidelines
β βββ page.tsx # Main page
βββ components/
β βββ FloatingChatbot.tsx # Main chat interface
β βββ Message.tsx # Message component
β βββ ThinkingDots.tsx # Loading animation component
β βββ ui/ # UI components
βββ hooks/
β βββ useChat.ts # Chat logic and state management
βββ lib/
β βββ documentLoader.ts # RAG document loading utilities
β βββ ragChain.ts # LangChain RAG implementation
β βββ vectorstore.ts # Vector storage for embeddings
β βββ utils.ts # Shared utility functions
βββ types/
βββ global.d.ts # TypeScript declarations
- Dynamic Web Scraping: Fetch real-time data from MarginFi's documentation website
- Link Processing: Extract and understand content from shared URLs during conversations
- PDF Document Support: Process uploaded PDF documents for context-aware responses
- Multi-Source Integration: Combine information from multiple documentation sources
- Advanced Vector Storage:
- Replace MemoryStore with MongoDB Atlas Search for better scalability
- Improved semantic search capabilities
- Persistent storage for embeddings
- Better handling of large document collections
-
Multi-Agent System:
- Specialized agents for different tasks (technical support, DeFi education, etc.)
- Agent collaboration for complex queries
- Automatic agent selection based on user needs
-
Enhanced Learning:
- Learn from user interactions to improve responses
- Build a knowledge base of common queries and solutions
- Adaptive response style based on user preferences
-
Performance Optimization:
- Faster response times through caching
- Improved context retrieval algorithms
- Better memory management for long conversations
-
Integration Features:
- Direct wallet connection support
- Real-time market data integration
- Transaction simulation capabilities
-
Personalization:
- User preference remembering
- Customizable UI themes
- Saved conversation history
-
Accessibility:
- Enhanced screen reader support
- Keyboard navigation improvements
- Multi-language support
Note: This roadmap is dynamic and will be updated based on user feedback and platform needs.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.