Overview
The AI Chatbot feature provides an interactive conversational interface that uses the Groq API with the LLaMA 3.3 70B model. It answers questions about profile information in a personalized, first-person manner.Implementation
The chatbot is implemented insrc/sections/chatbot.astro and integrates:
- Groq API: Uses the
llama-3.3-70b-versatilemodel - Profile Data: Loads from
src/data/nico-profile.json - Conversation History: Maintains context across multiple questions
- Rate Limiting: Built-in cooldown mechanism
Core Components
Answer Card
Displays AI responses with animated states:Quick Questions
Pre-configured question buttons for common inquiries:Input Form
Custom text input with submit button:API Integration
The chatbot communicates with Groq’s OpenAI-compatible API:src/sections/chatbot.astro:156-170
System Prompt
The chatbot uses a detailed system prompt to maintain personality and context:src/sections/chatbot.astro:89
State Management
Loading State
src/sections/chatbot.astro:110-128
Answer Display
src/sections/chatbot.astro:130-140
Rate Limiting
Built-in cooldown mechanism prevents API abuse:src/sections/chatbot.astro:94,105-108,145-149
Error Handling
Comprehensive error handling for API failures:src/sections/chatbot.astro:155-208
Styling Features
Animated Card Glow
src/sections/chatbot.astro:250-270
Spinner Animation
src/sections/chatbot.astro:314-325
Configuration
Environment Variables
Set the Groq API key in your.env file:
Model Parameters
src/sections/chatbot.astro:164-168
Profile Data
Customize responses by editingsrc/data/nico-profile.json:
Event Handling
Form Submission
src/sections/chatbot.astro:211-218
Quick Question Clicks
src/sections/chatbot.astro:220-227
Accessibility
- Keyboard navigation support
- ARIA labels on interactive elements
- Disabled state management
- Reduced motion preferences respected (via CSS)
Responsive Design
Mobile optimizations:src/sections/chatbot.astro:470-515
Best Practices
- API Key Security: Never commit API keys to version control
- Rate Limiting: Implement cooldowns to prevent abuse
- Error Handling: Provide clear error messages to users
- Conversation History: Maintain context for better responses
- Loading States: Show clear feedback during API calls
- Fallback Messages: Always provide contact alternatives if chatbot fails