Skip to content

Commit

Permalink
Merge pull request #135 from room302studio/store-robot-responses
Browse files Browse the repository at this point in the history
feat(remember): add function to remember robot responses
  • Loading branch information
ejfox authored Jul 1, 2024
2 parents 045bd96 + c77a5d7 commit 5d6d792
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
getAllMemories,
storeUserMemory,
getRelevantMemories,
storeRobotMessage,
} = require("./remember.js");
const {
createTodo,
Expand All @@ -21,8 +22,6 @@ const DISABLE_MEMORIES = true; // Set to false to enable memory storage
const DISABLE_TASK_ANALYSIS = true; // Set to false to enable task analysis
const DISABLE_REMEMBER_COMPLETIONS = true; // Set to false to enable remember completions

const { getPromptsFromSupabase, getConfigFromSupabase } = require("../helpers");

// Initialize prompts and config
let PROMPT_REMEMBER,
PROMPT_CAPABILITY_REMEMBER,
Expand Down Expand Up @@ -115,6 +114,12 @@ module.exports = {
logger.info(`Processed response: ${JSON.stringify(processedResponse)}`);
logger.info(`Response processed, ${processedResponse.length} characters`);

// store the robot message response
await storeRobotMessage(
{ username, channel, conversation_id: channel, related_message_id },
processedResponse
);

let rememberText = "";
if (!DISABLE_REMEMBER_COMPLETIONS) {
try {
Expand Down
25 changes: 25 additions & 0 deletions src/remember.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,30 @@ async function storeUserMessage(
return data[0].id;
}

// now, a similar function to store robot response messages
async function storeRobotMessage({ channel, guild, conversation_id }, value) {
const { getConfigFromSupabase } = require("../helpers.js");
const { supabase } = require("./supabaseclient.js");
const { NAME } = await getConfigFromSupabase();
const { data, error } = await supabase
// .from("messages")
.from(MESSAGES_TABLE_NAME)
.insert({
user_id: NAME,
channel_id: channel,
guild_id: guild,
conversation_id: conversation_id,
value,
})
.select();

if (error) {
logger.info(`Error storing robot message: ${error.message}`);
}

return data[0].id;
}

/**
* Retrieves the message history of a user.
* @param {string} userId - The ID of the user.
Expand Down Expand Up @@ -600,4 +624,5 @@ module.exports = {
getMemoriesBetweenDates,
getMemoriesByString,
deleteMemoriesOfResource,
storeRobotMessage,
};

0 comments on commit 5d6d792

Please sign in to comment.