feat(llmExtract): more logging

This commit is contained in:
Gergő Móricz 2025-04-16 15:40:07 -07:00
parent 4c5120e081
commit 509e6e658c

View File

@ -386,6 +386,8 @@ export async function generateCompletions({
const repairConfig = { const repairConfig = {
experimental_repairText: async ({ text, error }) => { experimental_repairText: async ({ text, error }) => {
// AI may output a markdown JSON code block. Remove it - mogery // 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 (typeof text === "string" && text.trim().startsWith("```")) {
if (text.trim().startsWith("```json")) { if (text.trim().startsWith("```json")) {
text = text.trim().slice("```json".length).trim(); 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 // If this fixes the JSON, just return it. If not, continue - mogery
try { try {
JSON.parse(text); JSON.parse(text);
logger.debug("Repaired text with string manipulation");
return text; return text;
} catch (e) { } catch (e) {
logger.error("Even after repairing, failed to parse JSON", { error: 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; return fixedText;
} catch (repairError) { } catch (repairError) {
lastError = repairError as Error; lastError = repairError as Error;