mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-05-06 06:12:56 +02:00
Add per-product AI verification disable option
Users can now disable AI verification for individual products that AI is having trouble with (e.g., Amazon products where AI keeps picking the main buy box price instead of "other sellers"). Changes: - Add ai_verification_disabled column to products table - Add toggle in product detail page under "Advanced Settings" - Pass skip flag to scrapeProductWithVoting - Skip AI verification when flag is set Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d2e1cc70fc
commit
b9d8d15e68
7 changed files with 147 additions and 6 deletions
|
|
@ -168,6 +168,10 @@ async function runMigrations() {
|
|||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'products' AND column_name = 'anchor_price') THEN
|
||||
ALTER TABLE products ADD COLUMN anchor_price DECIMAL(10,2);
|
||||
END IF;
|
||||
-- Per-product AI verification disable flag
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'products' AND column_name = 'ai_verification_disabled') THEN
|
||||
ALTER TABLE products ADD COLUMN ai_verification_disabled BOOLEAN DEFAULT false;
|
||||
END IF;
|
||||
END $$;
|
||||
`);
|
||||
|
||||
|
|
|
|||
|
|
@ -313,6 +313,7 @@ export interface Product {
|
|||
price_drop_threshold: number | null;
|
||||
target_price: number | null;
|
||||
notify_back_in_stock: boolean;
|
||||
ai_verification_disabled: boolean;
|
||||
created_at: Date;
|
||||
}
|
||||
|
||||
|
|
@ -476,6 +477,7 @@ export const productQueries = {
|
|||
price_drop_threshold?: number | null;
|
||||
target_price?: number | null;
|
||||
notify_back_in_stock?: boolean;
|
||||
ai_verification_disabled?: boolean;
|
||||
}
|
||||
): Promise<Product | null> => {
|
||||
const fields: string[] = [];
|
||||
|
|
@ -502,6 +504,10 @@ export const productQueries = {
|
|||
fields.push(`notify_back_in_stock = $${paramIndex++}`);
|
||||
values.push(updates.notify_back_in_stock);
|
||||
}
|
||||
if (updates.ai_verification_disabled !== undefined) {
|
||||
fields.push(`ai_verification_disabled = $${paramIndex++}`);
|
||||
values.push(updates.ai_verification_disabled);
|
||||
}
|
||||
|
||||
if (fields.length === 0) return null;
|
||||
|
||||
|
|
@ -581,6 +587,14 @@ export const productQueries = {
|
|||
);
|
||||
return result.rows[0]?.anchor_price ? parseFloat(result.rows[0].anchor_price) : null;
|
||||
},
|
||||
|
||||
isAiVerificationDisabled: async (id: number): Promise<boolean> => {
|
||||
const result = await pool.query(
|
||||
'SELECT ai_verification_disabled FROM products WHERE id = $1',
|
||||
[id]
|
||||
);
|
||||
return result.rows[0]?.ai_verification_disabled === true;
|
||||
},
|
||||
};
|
||||
|
||||
// Price History types and queries
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ router.put('/:id', async (req: AuthRequest, res: Response) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const { name, refresh_interval, price_drop_threshold, target_price, notify_back_in_stock } = req.body;
|
||||
const { name, refresh_interval, price_drop_threshold, target_price, notify_back_in_stock, ai_verification_disabled } = req.body;
|
||||
|
||||
const product = await productQueries.update(productId, userId, {
|
||||
name,
|
||||
|
|
@ -227,6 +227,7 @@ router.put('/:id', async (req: AuthRequest, res: Response) => {
|
|||
price_drop_threshold,
|
||||
target_price,
|
||||
notify_back_in_stock,
|
||||
ai_verification_disabled,
|
||||
});
|
||||
|
||||
if (!product) {
|
||||
|
|
|
|||
|
|
@ -29,14 +29,18 @@ async function checkPrices(): Promise<void> {
|
|||
// Get anchor price for variant products (the price the user confirmed)
|
||||
const anchorPrice = await productQueries.getAnchorPrice(product.id);
|
||||
|
||||
console.log(`[Scheduler] Product ${product.id} - preferredMethod: ${preferredMethod}, anchorPrice: ${anchorPrice}`);
|
||||
// Check if AI verification is disabled for this product
|
||||
const skipAiVerification = await productQueries.isAiVerificationDisabled(product.id);
|
||||
|
||||
console.log(`[Scheduler] Product ${product.id} - preferredMethod: ${preferredMethod}, anchorPrice: ${anchorPrice}, skipAi: ${skipAiVerification}`);
|
||||
|
||||
// Use voting scraper with preferred method and anchor price if available
|
||||
const scrapedData = await scrapeProductWithVoting(
|
||||
product.url,
|
||||
product.user_id,
|
||||
preferredMethod as ExtractionMethod | undefined,
|
||||
anchorPrice || undefined
|
||||
anchorPrice || undefined,
|
||||
skipAiVerification
|
||||
);
|
||||
|
||||
console.log(`[Scheduler] Product ${product.id} - scraped price: ${scrapedData.price?.price}, candidates: ${scrapedData.priceCandidates.map(c => `${c.price}(${c.method})`).join(', ')}`);
|
||||
|
|
|
|||
|
|
@ -1355,12 +1355,14 @@ export async function scrapeProduct(url: string, userId?: number): Promise<Scrap
|
|||
*
|
||||
* @param anchorPrice - The price the user previously confirmed. Used to select the correct
|
||||
* variant on refresh when multiple prices are found.
|
||||
* @param skipAiVerification - If true, skip AI verification entirely for this product.
|
||||
*/
|
||||
export async function scrapeProductWithVoting(
|
||||
url: string,
|
||||
userId?: number,
|
||||
preferredMethod?: ExtractionMethod,
|
||||
anchorPrice?: number
|
||||
anchorPrice?: number,
|
||||
skipAiVerification?: boolean
|
||||
): Promise<ScrapedProductWithCandidates> {
|
||||
const result: ScrapedProductWithCandidates = {
|
||||
name: null,
|
||||
|
|
@ -1637,10 +1639,12 @@ export async function scrapeProductWithVoting(
|
|||
}
|
||||
|
||||
// If we have a price but AI is available, verify it
|
||||
// SKIP verification if we have multiple candidates - let user choose from modal instead
|
||||
// SKIP verification if:
|
||||
// - User disabled AI verification for this product
|
||||
// - We have multiple candidates (let user choose from modal instead)
|
||||
// This prevents AI from "correcting" valid alternative prices (e.g., other sellers on Amazon)
|
||||
const hasMultipleCandidates = allCandidates.length > 1;
|
||||
if (result.price && userId && html && !result.aiStatus && !hasMultipleCandidates) {
|
||||
if (result.price && userId && html && !result.aiStatus && !hasMultipleCandidates && !skipAiVerification) {
|
||||
try {
|
||||
const { tryAIVerification } = await import('./ai-extractor');
|
||||
const verifyResult = await tryAIVerification(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue