Skip to content

Commit

Permalink
feat: add context in meeting notes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminshafii committed Jan 21, 2025
1 parent f155d3c commit 67a2eee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
23 changes: 16 additions & 7 deletions packages/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
normalizePath,
loadPdfJs,
arrayBufferToBase64,
CachedMetadata,
LinkCache,
} from "obsidian";
import { logMessage, sanitizeTag } from "./someUtils";
import { FileOrganizerSettingTab } from "./views/settings/view";
Expand Down Expand Up @@ -286,7 +288,6 @@ export default class FileOrganizer extends Plugin {
formattedContent = partialContent;
await this.app.vault.modify(file, formattedContent);
};

await this.formatStream(
content,
formattingInstruction,
Expand All @@ -307,25 +308,27 @@ export default class FileOrganizer extends Plugin {
file,
formattingInstruction,
content,
chunkMode = 'line',
chunkMode = "line",
}: {
file: TFile;
formattingInstruction: string;
content: string;
chunkMode?: 'line' | 'partial';
chunkMode?: "line" | "partial";
}): Promise<void> {
try {
new Notice("Formatting content line by line...", 3000);

// Backup the file before formatting
const backupFile = await this.backupTheFileAndAddReferenceToCurrentFile(file);
const backupFile = await this.backupTheFileAndAddReferenceToCurrentFile(
file
);

// Prepare streaming
let formattedContent = "";
let lastLineCount = 0;

const updateCallback = async (chunk: string) => {
if (chunkMode === 'line') {
if (chunkMode === "line") {
// Split chunk into lines and only append new lines
const lines = chunk.split("\n");
const newLines = lines.slice(lastLineCount);
Expand All @@ -349,10 +352,9 @@ export default class FileOrganizer extends Plugin {
updateCallback
);

// Insert reference to backup
// Insert reference to backup
await this.appendBackupLinkToCurrentFile(file, backupFile);
new Notice("Line-by-line update done!", 3000);

} catch (error) {
logger.error("Error formatting content line by line:", error);
new Notice("An error occurred while formatting the content.", 6000);
Expand Down Expand Up @@ -387,6 +389,12 @@ export default class FileOrganizer extends Plugin {
getApiKey(): string {
return this.settings.API_KEY;
}
async getCurrentFileLinks(file: TFile): Promise<LinkCache[]> {
// force metadata cache to be loaded
await this.app.vault.read(file);
const cache = this.app.metadataCache.getFileCache(file);
return cache?.links || [];
}

async formatStream(
content: string,
Expand All @@ -399,6 +407,7 @@ export default class FileOrganizer extends Plugin {
content,
formattingInstruction,
enableFabric: this.settings.enableFabric,

};

const response = await fetch(`${serverUrl}/api/format-stream`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,18 @@ export const Meetings: React.FC<MeetingsProps> = ({
Provide an updated version of these meeting notes in a cohesive style.
`;

const links = await plugin.getCurrentFileLinks(file);
console.log("links", links);
// get all link content and inject into the content
const linkContents = await Promise.all(links.map(link => plugin.app.vault.read(link)));
const linkContentsString = linkContents.join("\n\n");
const contentWithLinks = `${content}\n\n${linkContentsString}`;

// Stream the formatted content into the current note line by line
await plugin.streamFormatInCurrentNoteLineByLine({
file,
formattingInstruction,
content,
content: contentWithLinks,
chunkMode: 'line', // Use line-by-line mode for more granular updates
});

Expand Down

0 comments on commit 67a2eee

Please sign in to comment.