Skip to content

Commit

Permalink
Merge pull request #1205 from tobbelobb/main
Browse files Browse the repository at this point in the history
fix: write summary file before trying to cache it
  • Loading branch information
odilitime authored Dec 20, 2024
2 parents 78dd9f1 + 5cf3d7a commit e201228
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ tsup.config.bundled_*.mjs

coverage
.eslintcache

agent/content
41 changes: 31 additions & 10 deletions packages/client-discord/src/actions/chat_with_attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ModelClass,
State,
} from "@ai16z/eliza";
import * as fs from 'fs';

export const summarizationTemplate = `# Summarized so far (we are adding to this)
{{currentSummary}}
Expand Down Expand Up @@ -225,16 +227,35 @@ ${currentSummary.trim()}
`;
await callback(callbackData);
} else if (currentSummary.trim()) {
const summaryFilename = `content/summary_${Date.now()}`;
await runtime.cacheManager.set(summaryFilename, currentSummary);
// save the summary to a file
await callback(
{
...callbackData,
text: `I've attached the summary of the requested attachments as a text file.`,
},
[summaryFilename]
);
const summaryFilename = `content/summary_${Date.now()}.md`;

try {
// Debug: Log before file operations
console.log("Creating summary file:", {
filename: summaryFilename,
summaryLength: currentSummary.length
});

// Write file directly first
await fs.promises.writeFile(summaryFilename, currentSummary, 'utf8');
console.log("File written successfully");

// Then cache it
await runtime.cacheManager.set(summaryFilename, currentSummary);
console.log("Cache set operation completed");

await callback(
{
...callbackData,
text: `I've attached the summary of the requested attachments as a text file.`,
},
[summaryFilename]
);
console.log("Callback completed with summary file");
} catch (error) {
console.error("Error in file/cache process:", error);
throw error;
}
} else {
console.warn(
"Empty response from chat with attachments action, skipping"
Expand Down

0 comments on commit e201228

Please sign in to comment.