Skip to content

Commit 3aca21e

Browse files
committed
Add a link back to the original
1 parent 13bab9c commit 3aca21e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/main.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
App,
32
Editor,
43
MarkdownView,
54
MarkdownFileInfo,
@@ -9,8 +8,8 @@ import {
98

109
import {
1110
AtomizerSettings,
12-
DEFAULT_SETTINGS,
1311
AtomizerSettingTab,
12+
DEFAULT_SETTINGS,
1413
} from "./settings";
1514

1615
import { OpenAIService } from "./openai-service";
@@ -89,9 +88,13 @@ export default class AtomizerPlugin extends Plugin {
8988
this.settings.outputFolder,
9089
);
9190

91+
// Get the source file name to include in the generated notes
92+
const sourceFileName = view.file?.basename || "Unknown Source";
93+
9294
const responseContent = await openAIService.generateAtomicNotes(
9395
content,
9496
getISOTimestamp(),
97+
sourceFileName,
9598
);
9699
if (!responseContent)
97100
throw new Error("No content received from OpenAI");

src/openai-service.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ export class OpenAIService {
1515

1616
/**
1717
* Generate atomic notes from content using OpenAI
18+
* @param content The content to process
19+
* @param timestamp ISO timestamp
20+
* @param sourceFilePath Path to the source file
1821
*/
1922
async generateAtomicNotes(
2023
content: string,
2124
timestamp: string,
25+
sourceFilePath: string,
2226
): Promise<string> {
2327
if (!this.apiKey) {
2428
new Notice(
@@ -40,7 +44,7 @@ export class OpenAIService {
4044
messages: [
4145
{
4246
role: "system",
43-
content: this.getSystemPrompt(),
47+
content: this.getSystemPrompt(sourceFilePath),
4448
},
4549
{
4650
role: "user",
@@ -56,15 +60,17 @@ export class OpenAIService {
5660

5761
/**
5862
* Generate the system prompt for OpenAI
63+
* @param sourceFilePath Path to the source file for back-linking
5964
*/
60-
private getSystemPrompt(): string {
65+
private getSystemPrompt(sourceFilePath: string): string {
6166
return `You are an expert at creating atomic notes from a single, larger note.
6267
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:
6368
1. Each note should contain exactly one clear idea. This can contain multiple lines.
6469
2. Each note must have a YAML frontmatter section at the top with:
6570
---
6671
date: "${getFormattedDateTime()}"
6772
tags: ${this.settings.enableAtomizedTag ? "atomized" : ""}${this.settings.customTags ? (this.settings.enableAtomizedTag ? ", " : "") + this.settings.customTags : ""}
73+
source: "[[${sourceFilePath}]]"
6874
---
6975
3. You MUST separate each note by placing '<<<>>>' on its own line between notes
7076
4. After the frontmatter, each note must start with a level 1 heading (# Title)

0 commit comments

Comments
 (0)