Files
Dramlog-Prod/src/lib/openrouter.ts
robin 9ba0825bcd feat: Add Spotify-style backdrop, Cascade OCR, Smart Scan Flow & OCR Dashboard
- BottleGrid: Implement blurred backdrop effect for bottle cards
- Cascade OCR: TextDetector → RegEx → Fuzzy Match → window.ai pipeline
- Smart Scan: Native OCR for Android, Live Text fallback for iOS
- OCR Dashboard: Admin page at /admin/ocr-logs with stats and scan history
- Features: Add feature flags in src/config/features.ts
- SQL: Add ocr_logs table migration
- Services: Update analyze-bottle to use OpenRouter, add save-ocr-log
2026-01-18 20:38:48 +01:00

51 lines
1.4 KiB
TypeScript

import OpenAI from 'openai';
/**
* AI Provider configuration
*
* Set AI_PROVIDER in .env.local to switch:
* - "openrouter" (default) - Uses OpenRouter with Gemma 3 27B via Nebius/FP8
* - "gemini" - Uses Google Gemini 2.5 Flash
*/
export type AIProvider = 'openrouter';
export function getAIProvider(): AIProvider {
return 'openrouter';
}
/**
* OpenRouter client for vision tasks
* Uses OpenAI-compatible API
*/
export function getOpenRouterClient(): OpenAI {
const apiKey = process.env.OPENROUTER_API_KEY;
if (!apiKey) {
throw new Error('OPENROUTER_API_KEY is not configured.');
}
return new OpenAI({
baseURL: 'https://openrouter.ai/api/v1',
apiKey: apiKey,
defaultHeaders: {
'HTTP-Referer': 'https://whiskyvault.app',
'X-Title': 'WhiskyVault',
},
});
}
// Default OpenRouter model for vision tasks
export const OPENROUTER_VISION_MODEL = 'google/gemma-3-27b-it';
//export const OPENROUTER_VISION_MODEL = 'google/gemma-3n-e4b-it';
/**
* OpenRouter provider preferences
* - Prioritize Nebius provider for better availability
* - Request FP8 quantization for quality/speed balance
*/
export const OPENROUTER_PROVIDER_PREFERENCES = {
order: ['Nebius'], // Prioritize Nebius
quantizations: ['fp8'], // Use FP8 for quality
allow_fallbacks: true, // Allow fallback to other providers
};