Merge pull request #5 from x3c3/linkback

Linkback
This commit is contained in:
Zac 2025-03-18 13:46:16 -04:00 committed by GitHub
commit bb96ce9792
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -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");

View file

@ -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<string> {
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)