๐ AskMaster
AskMaster is a lightweight SvelteKit application that leverages Google Gemini (Generative AI) to generate multiple-choice questions on any topic. Features include an interactive quiz interface and JSON export capabilities for generated question sets.
โจ Features
- AI-Powered Generation: Uses Google Gemini 2.5-pro to create high-quality multiple-choice questions
- Dual Provider Support: Choose between Gemini SDK and OpenAI-compatible endpoints
- Interactive Quiz Experience: Navigate through questions with immediate feedback
- Customizable Parameters: Control question count (1-20) and creativity level (temperature 0.0-1.0)
- Export Functionality: Download generated questions as structured JSON files
- NeoBrutalism Design: Bold, high-contrast UI with geometric styling
- Responsive Design: Optimized for both desktop and mobile devices
๐ฆ Prerequisites
- Node.js: Version 18 or higher
- npm: Package manager for dependencies
- Google Gemini API Key: Obtain from Google AI Studio
- (Optional) Custom OpenAI-compatible configuration:
CUSTOM_API_KEY: API key for custom endpoint
- `CUSTOM_MODEL**: Model name for custom endpoint
- `CUSTOM_BASE_URL**: Base URL for custom OpenAI-compatible API
๐ Quick Start
1. Clone the Repository
git clone <repository-url>
cd askmaster
2. Install Dependencies
npm install
cp .env.example .env
Edit the .env file and configure your API keys:
# Required for Gemini provider
GEMINI_API_KEY=your_gemini_api_key_here
# Optional - for custom OpenAI-compatible endpoint
CUSTOM_API_KEY=your_custom_api_key
CUSTOM_MODEL=your_custom_model
CUSTOM_BASE_URL=https://your-custom-api-endpoint.com
4. Start Development Server
npm run dev
The application will be available at http://localhost:5174
๐ Using the Application
Question Generation
- Enter Topic: Provide any subject or topic (e.g., "JavaScript", "World History", "Biology")
๐งญ API Reference
Provider Configuration
AskMaster supports two AI provider options:
Google Gemini SDK (default)
- Uses
@google/generative-ai with the gemini-2.5-pro model
- Requires
GEMINI_API_KEY environment variable
- Direct integration with Google's Generative AI services
Custom OpenAI-compatible Endpoint
- Sends requests to your configured
CUSTOM_BASE_URL
- Uses OpenAI-compatible chat completion format
POST /api/generate-questions
Generates multiple-choice questions based on the provided topic and parameters.
Request Body
{
"topic": "string (required)",
"questionCount": "number (1-20, required)",
"temperature": "number (0.0-1.0, optional, defaults to 0.7)
"provider": "string ('google' or 'custom', optional, defaults to 'google')"
}
Success (200 OK)
[
{
"question": "What is the capital of France?",
"answers": ["Paris", "London", "Berlin", "Madrid"],
"correctAnswerIndex": 0
}
HTTP Status Codes
- 200: Successfully generated questions
- 400: Bad request (missing required fields)
- 429: Rate limit exceeded
- 503: Service temporarily unavailable
- 500: Internal server error
Example Usage
curl -X POST \
-H "Content-Type: application/json" \
-d '{"topic":"JavaScript","questionCount":10,"temperature":0.7,"provider":"google"}' \
http://localhost:5174/api/generate-questions
๐ Environment & Security
Environment Variables
Create a .env file with the following variables:
# Required for Gemini provider
GEMINI_API_KEY=your_gemini_api_key_here
# Optional - for custom OpenAI-compatible endpoint
CUSTOM_API_KEY=your_custom_api_key
CUSTOM_MODEL=your_custom_model
CUSTOM_BASE_URL=https://your-custom-api-endpoint.com
Security Best Practices
- API Key Protection: Store sensitive keys in environment variables, not in code
- Input Validation: All user inputs are validated server-side
- Error Handling: User-friendly error messages instead of exposing server details
- Secret Management: Use platform-specific secret managers for production deployments
Available Scripts
# Start development server
npm run dev
# Build for production
npm run build
# Preview production build locally
npm run preview
# Type checking and Svelte diagnostics
npm run check
# Code formatting and linting
npm run format
npm run lint
Development Workflow
- Local Development: Use
npm run dev for hot-reload development
- Type Checking: Run
npm run check to verify TypeScript compilation
- Code Quality: Use
npm run lint to check for issues
๐ฆ Deployment
- Vercel: Zero-config deployment with automatic environment variable configuration
- Netlify: Supports SvelteKit with adapter-auto
- Node.js Hosting: Any platform supporting Node.js 18+
Deployment Steps
Build the Application:
npm run build
Configure Environment Variables:
- Set
GEMINI_API_KEY in your hosting platform's environment settings
Environment Configuration
For production deployments, set the following environment variables:
GEMINI_API_KEY=your_production_api_key
- Deploy:
- For Vercel: Connect your repository and configure environment variables
- For Netlify: Use the build settings and environment variables panel
โ ๏ธ Notes & Caveats
Current Limitations
- AI Response Consistency: Gemini's output format may vary; the system includes parsing logic but perfect structure isn't guaranteed
- Rate Limiting: Subject to Google Gemini API quotas and rate limits
- Error Handling: Falls back to user-friendly error messages rather than mock data
- Question Quality: AI-generated questions may vary in quality and consistency
Recommendations
- Input Validation: Always validate user inputs on both client and server sides
- API Reliability: Consider implementing retry mechanisms for production use
๐ Troubleshooting
Common Issues
- API Key Errors
- Ensure
GEMINI_API_KEY is set in your .env file
- Verify the key is valid and has sufficient quota
- Network Connectivity: Check internet connection for API calls
- Port Conflicts: Ensure port 5174 is available, or configure a different port in
vite.config.ts
- Build Failures
- Run
npm run check to identify TypeScript errors
- Use
npm run lint to check for code quality issues
Error Messages
- "Gemini API key is missing or empty": Check your
.env file configuration
- "Failed to generate questions": Check API key validity and network connectivity
๐งโ๐คโ๐ง Contributing
How to Contribute
- Fork the repository
- Create a 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
Pre-PR Checklist
๐ License
This project is licensed under the MIT License โ see LICENSE.
โค๏ธ Acknowledgements
Built with SvelteKit, Vite, and the Google Generative AI SDK.
Technologies Used: