From 509e6e658c9b72bfbb8384530e6296346a5bb1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Wed, 16 Apr 2025 15:40:07 -0700 Subject: [PATCH] feat(llmExtract): more logging --- apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts index 041fd036..21572c9d 100644 --- a/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts +++ b/apps/api/src/scraper/scrapeURL/transformers/llmExtract.ts @@ -386,6 +386,8 @@ export async function generateCompletions({ const repairConfig = { experimental_repairText: async ({ text, error }) => { // AI may output a markdown JSON code block. Remove it - mogery + logger.debug("Repairing text", { textType: typeof text, error }); + if (typeof text === "string" && text.trim().startsWith("```")) { if (text.trim().startsWith("```json")) { text = text.trim().slice("```json".length).trim(); @@ -400,6 +402,7 @@ export async function generateCompletions({ // If this fixes the JSON, just return it. If not, continue - mogery try { JSON.parse(text); + logger.debug("Repaired text with string manipulation"); return text; } catch (e) { logger.error("Even after repairing, failed to parse JSON", { error: e }); @@ -418,6 +421,7 @@ export async function generateCompletions({ }, }, }); + logger.debug("Repaired text with LLM"); return fixedText; } catch (repairError) { lastError = repairError as Error;