From 3aca21e2cb02c515aaf7f108264112d0815a6504 Mon Sep 17 00:00:00 2001 From: Mark Ayers Date: Thu, 13 Mar 2025 02:09:02 -0400 Subject: [PATCH] Add a link back to the original --- src/main.ts | 7 +++++-- src/openai-service.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index e61c673..33194f3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,4 @@ import { - App, Editor, MarkdownView, MarkdownFileInfo, @@ -9,8 +8,8 @@ import { import { AtomizerSettings, - DEFAULT_SETTINGS, AtomizerSettingTab, + DEFAULT_SETTINGS, } from "./settings"; import { OpenAIService } from "./openai-service"; @@ -89,9 +88,13 @@ export default class AtomizerPlugin extends Plugin { this.settings.outputFolder, ); + // Get the source file name to include in the generated notes + const sourceFileName = view.file?.basename || "Unknown Source"; + const responseContent = await openAIService.generateAtomicNotes( content, getISOTimestamp(), + sourceFileName, ); if (!responseContent) throw new Error("No content received from OpenAI"); diff --git a/src/openai-service.ts b/src/openai-service.ts index 2d1d61d..f560aab 100644 --- a/src/openai-service.ts +++ b/src/openai-service.ts @@ -15,10 +15,14 @@ export class OpenAIService { /** * Generate atomic notes from content using OpenAI + * @param content The content to process + * @param timestamp ISO timestamp + * @param sourceFilePath Path to the source file */ async generateAtomicNotes( content: string, timestamp: string, + sourceFilePath: string, ): Promise { if (!this.apiKey) { new Notice( @@ -40,7 +44,7 @@ export class OpenAIService { messages: [ { role: "system", - content: this.getSystemPrompt(), + content: this.getSystemPrompt(sourceFilePath), }, { role: "user", @@ -56,8 +60,9 @@ export class OpenAIService { /** * Generate the system prompt for OpenAI + * @param sourceFilePath Path to the source file for back-linking */ - private getSystemPrompt(): string { + private getSystemPrompt(sourceFilePath: string): string { return `You are an expert at creating atomic notes from a single, larger note. Take the content from a larger note and break it down into separate compact yet detailed atomic notes. Each note MUST be separated by placing '<<<>>>' on its own line between notes. Do not include an index or main note. Follow these rules: 1. Each note should contain exactly one clear idea. This can contain multiple lines. @@ -65,6 +70,7 @@ export class OpenAIService { --- date: "${getFormattedDateTime()}" tags: ${this.settings.enableAtomizedTag ? "atomized" : ""}${this.settings.customTags ? (this.settings.enableAtomizedTag ? ", " : "") + this.settings.customTags : ""} +source: "[[${sourceFilePath}]]" --- 3. You MUST separate each note by placing '<<<>>>' on its own line between notes 4. After the frontmatter, each note must start with a level 1 heading (# Title)