From 68a6dfe585e6b0c2a3bddcceace70e4278a014c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Ludvigsen?= Date: Wed, 18 Dec 2024 13:17:01 +0100 Subject: [PATCH 1/2] Write summary file before trying to cache it - Also give a .md file extension for prettier rendering in Discord --- .../src/actions/chat_with_attachments.ts | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/client-discord/src/actions/chat_with_attachments.ts b/packages/client-discord/src/actions/chat_with_attachments.ts index c55aca1a93..f5cbd46c0c 100644 --- a/packages/client-discord/src/actions/chat_with_attachments.ts +++ b/packages/client-discord/src/actions/chat_with_attachments.ts @@ -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}} @@ -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" From 9948cdfe9243930c73460d7de0f96f2f961e25df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Ludvigsen?= Date: Fri, 20 Dec 2024 10:17:04 +0100 Subject: [PATCH 2/2] Ignore agent content --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index abc2305272..97c88ce295 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ tsup.config.bundled_*.mjs coverage .eslintcache + +agent/content