mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-06-23 15:48:08 +02:00
Add AI price verification feature
When enabled, AI verifies every scraped price to ensure accuracy. This catches issues like scraped "savings" amounts instead of actual prices. - Add ai_verification_enabled column to users table - Create verification prompt and functions for Anthropic, OpenAI, Ollama - Integrate verification step into scraper after traditional scraping - Add verification toggle to Settings page (separate from AI extraction) - AI verification is independent of AI extraction fallback Flow: Traditional scraping -> AI verification (if enabled) -> AI extraction fallback (if no price found) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7afa3ccec3
commit
dc4e7b9665
6 changed files with 278 additions and 4 deletions
|
|
@ -36,6 +36,7 @@ export interface NotificationSettings {
|
|||
|
||||
export interface AISettings {
|
||||
ai_enabled: boolean;
|
||||
ai_verification_enabled: boolean;
|
||||
ai_provider: 'anthropic' | 'openai' | 'ollama' | null;
|
||||
anthropic_api_key: string | null;
|
||||
openai_api_key: string | null;
|
||||
|
|
@ -209,7 +210,9 @@ export const userQueries = {
|
|||
|
||||
getAISettings: async (id: number): Promise<AISettings | null> => {
|
||||
const result = await pool.query(
|
||||
'SELECT ai_enabled, ai_provider, anthropic_api_key, openai_api_key, ollama_base_url, ollama_model FROM users WHERE id = $1',
|
||||
`SELECT ai_enabled, COALESCE(ai_verification_enabled, false) as ai_verification_enabled,
|
||||
ai_provider, anthropic_api_key, openai_api_key, ollama_base_url, ollama_model
|
||||
FROM users WHERE id = $1`,
|
||||
[id]
|
||||
);
|
||||
return result.rows[0] || null;
|
||||
|
|
@ -227,6 +230,10 @@ export const userQueries = {
|
|||
fields.push(`ai_enabled = $${paramIndex++}`);
|
||||
values.push(settings.ai_enabled);
|
||||
}
|
||||
if (settings.ai_verification_enabled !== undefined) {
|
||||
fields.push(`ai_verification_enabled = $${paramIndex++}`);
|
||||
values.push(settings.ai_verification_enabled);
|
||||
}
|
||||
if (settings.ai_provider !== undefined) {
|
||||
fields.push(`ai_provider = $${paramIndex++}`);
|
||||
values.push(settings.ai_provider);
|
||||
|
|
@ -253,7 +260,8 @@ export const userQueries = {
|
|||
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, ollama_base_url, ollama_model`,
|
||||
RETURNING ai_enabled, COALESCE(ai_verification_enabled, false) as ai_verification_enabled,
|
||||
ai_provider, anthropic_api_key, openai_api_key, ollama_base_url, ollama_model`,
|
||||
values
|
||||
);
|
||||
return result.rows[0] || null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue