Multi-Provider AI Support - Test Guide¶
Overview¶
This guide explains how to test the new multi-provider AI support implemented in CodeSlick.
What Was Implemented¶
1. Provider Configuration (src/lib/ai/provider-config.ts)¶
- 5 AI Providers: OpenAI, Anthropic, Together.ai, Groq, Google Gemini
- 20+ Models across all providers
- Provider-specific pricing (automatic cost calculation)
- API key validation (format checking, prefix detection)
- Helper functions: validateApiKey(), detectProvider(), calculateCost()
2. Unified AI Client (src/lib/ai/unified-client.ts)¶
- Single interface for all providers
- Automatic routing to provider-specific API implementations
- Token counting and cost calculation
- Error handling with provider-specific error messages
- Latency tracking for performance monitoring
3. Multi-Provider Usage Tracking (src/lib/tracking/usage-tracker.ts)¶
- Provider field added to UsageRecord interface
- Separate tracking per provider (usage:openai, usage:anthropic, etc.)
- Backward compatible with existing Together.ai data
- New method:
getAllProvidersMetrics()for dashboard
4. Redesigned UI (src/components/ApiKeyManager.tsx)¶
- Provider dropdown (5 providers)
- Model dropdown (dynamically updates based on provider)
- Pricing display (shows cost per 1M tokens)
- Context window display
- Smart validation (provider-specific rules)
- Setup instructions with direct links to each provider
Testing the Implementation¶
Phase 1: Visual Verification (Browser)¶
-
Start the development server:
-
Open CodeSlick in your browser:
-
Navigate to
http://localhost:3000 -
Test ApiKeyManager UI:
- Click "Use My API Key" button
- Verify you see "Multi-Provider AI Configuration" modal
- Test provider dropdown - should show: OpenAI, Anthropic, Together.ai, Groq, Google Gemini
-
Change provider and verify:
- Model dropdown updates with provider-specific models
- Pricing info displays correctly
- Setup instructions change
- API key placeholder changes
-
Test API Key Validation:
- Together.ai: Enter a 64-character hex string (valid) → should show green checkmark
- OpenAI: Enter
sk-proj-+ random chars → should show green checkmark - Anthropic: Enter
sk-ant-api03-+ 88 chars → should show green checkmark - Groq: Enter
gsk_+ 52 chars → should show green checkmark - Gemini: Enter
AIzaSy+ 33 chars → should show green checkmark - Test invalid format → should show red error
Phase 2: Cost Calculation Verification¶
Run these calculations manually to verify pricing is correct:
// Together.ai Qwen 2.5 Coder
// 1M input tokens: $0.30
// 1M output tokens: $0.30
// Total for 2M tokens: $0.60
// OpenAI GPT-4 Turbo
// 1M input tokens: $10.00
// 1M output tokens: $30.00
// Total for 2M tokens: $40.00
// Anthropic Claude 3.5 Sonnet
// 1M input tokens: $3.00
// 1M output tokens: $15.00
// Total for 2M tokens: $18.00
// Groq Mixtral 8x7B
// 1M input tokens: $0.27
// 1M output tokens: $0.27
// Total for 2M tokens: $0.54
// Gemini 1.5 Flash 8B
// 1M input tokens: $0.075
// 1M output tokens: $0.30
// Total for 2M tokens: $0.375 (cheapest!)
Phase 3: Provider Comparison¶
| Provider | Best Model | Input Cost | Output Cost | Context | Best For |
|---|---|---|---|---|---|
| Gemini | Flash 8B | $0.075 | $0.30 | 1M tokens | Cheapest, largest context |
| Together.ai | Qwen Coder | $0.30 | $0.30 | 32K tokens | Code-specific tasks |
| Groq | Mixtral 8x7B | $0.27 | $0.27 | 32K tokens | Fastest inference |
| Anthropic | Sonnet 3.5 | $3.00 | $15.00 | 200K tokens | Safety & reasoning |
| OpenAI | GPT-4 Turbo | $10.00 | $30.00 | 128K tokens | Most capable |
Phase 4: Manual Integration Test¶
To test the complete flow:
- Configure a provider:
- Open ApiKeyManager
- Select "Together.ai"
- Select "Qwen 2.5 Coder 32B"
- Enter your API key
- Click "Validate" → should show green checkmark
-
Click "Save & Use" → should show success
-
Verify localStorage:
- Open browser DevTools → Application → Local Storage
- Find
codeslick_ai_config -
Should contain:
-
Test code fix generation:
- Paste code with an error
- Click "Analyze Code"
- Click "Generate Fix" on an issue
- Verify it uses your configured provider
Phase 5: Unit Test Coverage¶
The test file src/lib/ai/__tests__/multi-provider.test.ts covers:
Test Suite 1: Provider Configuration¶
- ✓ All 5 providers configured
- ✓ All 20+ models have pricing
- ✓ Base URLs are correct
- ✓ Key formats are defined
Test Suite 2: API Key Validation¶
- ✓ Valid keys accepted for all providers
- ✓ Invalid keys rejected
- ✓ Provider detection from key prefix
- ✓ Prefix matching works
Test Suite 3: Model Configuration¶
- ✓ Default models exist
- ✓ Model retrieval works
- ✓ Non-existent models return null
- ✓ Model pricing is defined
Test Suite 4: Cost Calculation¶
- ✓ Together.ai costs: $0.60 per 2M tokens
- ✓ OpenAI costs: $40.00 per 2M tokens
- ✓ Anthropic costs: $18.00 per 2M tokens
- ✓ Small requests: ~$0.00045
Test Suite 5: UnifiedAIClient¶
- ✓ Client creation for all providers
- ✓ Invalid provider throws error
- ✓ Invalid model throws error
- ✓ API routing works
Test Suite 6: Integration Scenarios¶
- ✓ Complete user workflow
- ✓ Cost comparison
- ✓ Provider switching
Known Limitations¶
- No actual API calls in tests - Tests verify configuration and validation only
- Requires manual testing - UI interactions must be tested in browser
- Cost calculation is estimation - Actual costs may vary slightly
Next Steps¶
Backend Integration (Not Yet Implemented)¶
The following still need to be updated to use UnifiedAIClient:
/api/generate-fix/route.ts- Individual fix generation/api/analyze/route.ts- Advanced AI analysis (if enabled)- Usage tracking integration
Dashboard Updates (Not Yet Implemented)¶
- Provider breakdown in metrics dashboard
- Cost comparison charts
- Per-provider analytics
Success Criteria¶
✅ Phase 1 Complete: - Provider configuration created - UnifiedAIClient implemented - UsageTracker supports multi-provider - ApiKeyManager redesigned
⏳ Phase 2 Pending: - Backend integration - Dashboard updates - End-to-end testing with real API keys
Quick Verification Checklist¶
- Dev server starts without errors
- ApiKeyManager modal opens
- All 5 providers appear in dropdown
- Model dropdown updates when changing providers
- Pricing displays correctly
- API key validation works for each provider
- Configuration saves to localStorage
- No console errors
Troubleshooting¶
Problem: Modal doesn't open - Fix: Check browser console for errors, verify imports in page.tsx
Problem: Provider dropdown is empty - Fix: Verify provider-config.ts exports correctly
Problem: Validation always fails - Fix: Check regex patterns in provider-config.ts
Problem: Pricing shows $0.00 - Fix: Verify model pricing in provider-config.ts
Support¶
For issues or questions: 1. Check browser console for errors 2. Verify all files are saved 3. Restart dev server 4. Clear browser cache and localStorage
Status: ✅ Core infrastructure complete and ready for testing Last Updated: 2025-10-18