Add AI-powered price extraction fallback

- Add AI extraction service supporting Anthropic (Claude) and OpenAI
- Add AI settings UI in Settings page with provider selection
- Add database migration for AI settings columns
- Integrate AI fallback into scraper when standard methods fail
- Add API endpoints for AI settings and test extraction

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-21 21:49:55 -05:00
parent cfca33b4ea
commit d98138fe7c
11 changed files with 887 additions and 10 deletions

View file

@ -27,6 +27,13 @@ export interface NotificationSettings {
discord_webhook_url: string | null;
}
export interface AISettings {
ai_enabled: boolean;
ai_provider: 'anthropic' | 'openai' | null;
anthropic_api_key: string | null;
openai_api_key: string | null;
}
export const userQueries = {
findByEmail: async (email: string): Promise<User | null> => {
const result = await pool.query(
@ -155,6 +162,50 @@ export const userQueries = {
);
return (result.rowCount ?? 0) > 0;
},
getAISettings: async (id: number): Promise<AISettings | null> => {
const result = await pool.query(
'SELECT ai_enabled, ai_provider, anthropic_api_key, openai_api_key FROM users WHERE id = $1',
[id]
);
return result.rows[0] || null;
},
updateAISettings: async (
id: number,
settings: Partial<AISettings>
): Promise<AISettings | null> => {
const fields: string[] = [];
const values: (string | boolean | null)[] = [];
let paramIndex = 1;
if (settings.ai_enabled !== undefined) {
fields.push(`ai_enabled = $${paramIndex++}`);
values.push(settings.ai_enabled);
}
if (settings.ai_provider !== undefined) {
fields.push(`ai_provider = $${paramIndex++}`);
values.push(settings.ai_provider);
}
if (settings.anthropic_api_key !== undefined) {
fields.push(`anthropic_api_key = $${paramIndex++}`);
values.push(settings.anthropic_api_key);
}
if (settings.openai_api_key !== undefined) {
fields.push(`openai_api_key = $${paramIndex++}`);
values.push(settings.openai_api_key);
}
if (fields.length === 0) return null;
values.push(id.toString());
const result = await pool.query(
`UPDATE users SET ${fields.join(', ')} WHERE id = $${paramIndex}
RETURNING ai_enabled, ai_provider, anthropic_api_key, openai_api_key`,
values
);
return result.rows[0] || null;
},
};
// System settings queries