From 278643845ad23a2978b12e1bcb9bb2cd8cd21d3d Mon Sep 17 00:00:00 2001 From: Chris Lettieri Date: Tue, 15 Apr 2025 16:50:05 -0400 Subject: [PATCH] It works --- main.ts | 18 +++++++++++++++++- package.json | 6 ++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/main.ts b/main.ts index f11d91a..9ddd9c6 100644 --- a/main.ts +++ b/main.ts @@ -127,7 +127,23 @@ Transcript:\n${content}`; throw new Error('No response content received from OpenAI'); } - const structuredData = JSON.parse(messageContent); + // Clean up the response content in case it contains markdown formatting + let cleanedContent = messageContent; + + // Remove markdown code blocks if present (```json or just ```) + const codeBlockMatch = cleanedContent.match(/```(?:json)?\s*([\s\S]*?)```/); + if (codeBlockMatch) { + cleanedContent = codeBlockMatch[1].trim(); + } + + // Parse the JSON + let structuredData; + try { + structuredData = JSON.parse(cleanedContent); + } catch (parseError) { + console.error('Failed to parse JSON response:', cleanedContent); + throw new Error(`Failed to parse JSON response: ${parseError.message}`); + } // Output Summary await this.app.vault.create(`Parsed_Notes/summaries/${filename}_summary.md`, structuredData.summary); diff --git a/package.json b/package.json index f94efa4..cf535b6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "obsidian-sample-plugin", + "name": "open-augi", "version": "1.0.0", - "description": "This is a sample plugin for Obsidian (https://obsidian.md)", + "description": "", "main": "main.js", "scripts": { "dev": "node esbuild.config.mjs", @@ -22,7 +22,5 @@ "typescript": "^4.7.4" }, "dependencies": { - "dotenv": "^16.5.0", - "openai": "^4.94.0" } }