Fix AI extraction JSON-LD parsing and add debug logging

- Extract JSON-LD scripts BEFORE removing script tags
- Add logging for prepared HTML, AI responses, and parsed data
- Include more detailed error messages in test endpoint

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-21 21:58:39 -05:00
parent d98138fe7c
commit 906212e6ae
2 changed files with 28 additions and 13 deletions

View file

@ -199,16 +199,21 @@ router.post('/ai/test', async (req: AuthRequest, res: Response) => {
return;
}
console.log(`[AI Test] Testing URL: ${url} with provider: ${settings.ai_provider}`);
const { extractWithAI } = await import('../services/ai-extractor');
const result = await extractWithAI(url, settings);
console.log(`[AI Test] Result:`, JSON.stringify(result, null, 2));
res.json({
success: !!result.price,
...result,
});
} catch (error) {
console.error('Error testing AI extraction:', error);
res.status(500).json({ error: 'Failed to test AI extraction' });
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
res.status(500).json({ error: `Failed to test AI extraction: ${errorMessage}` });
}
});