ykhli / cat-town

A custom AI-town with cats. Based on https://github.com/a16z-infra/AI-town
https://cat-town.fly.dev/
MIT License
118 stars 10 forks source link

Sweep: When calling converse(), use the top 5 reflection memories #5

Open ykhli opened 1 year ago

ykhli commented 1 year ago

Details

the bug may be in conversation.ts

Checklist - [X] `convex/conversation.ts` > * Import the `filterMemoriesType` function from `./lib/memory` at the top of the file. > • Inside the `converse()` function, after the line where `conversationMemories` is defined, add a new line to define `reflectionMemories`. Call `filterMemoriesType()` with 'reflection' as the memory type and `memories` as the second argument. Use the `slice()` method to limit the result to the top 5 memories. > • Modify the `prefixPrompt` variable to include the `reflectionMemories`. After the line where `relevantMemories` is defined, add a new line to define `relevantReflections`. Map over the `reflectionMemories` and join their descriptions with a newline character. Include `relevantReflections` in the `prefixPrompt` string.
sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/ykhli/cat-town/pull/6.

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 3 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/ykhli/cat-town/blob/d76e3ca18db7fd8f743d47232c8fcd07a0d80a36/convex/conversation.ts#L1-L186 https://github.com/ykhli/cat-town/blob/d76e3ca18db7fd8f743d47232c8fcd07a0d80a36/convex/agent.ts#L100-L283 https://github.com/ykhli/cat-town/blob/d76e3ca18db7fd8f743d47232c8fcd07a0d80a36/convex/lib/memory.ts#L1-L314 https://github.com/ykhli/cat-town/blob/d76e3ca18db7fd8f743d47232c8fcd07a0d80a36/convex/lib/memory.ts#L1-L80 https://github.com/ykhli/cat-town/blob/d76e3ca18db7fd8f743d47232c8fcd07a0d80a36/convex/lib/memory.ts#L311-L429

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
convex/conversation.ts Modify convex/conversation.ts with contents:
* Import the filterMemoriesType function from ./lib/memory at the top of the file.
• Inside the converse() function, after the line where conversationMemories is defined, add a new line to define reflectionMemories. Call filterMemoriesType() with 'reflection' as the memory type and memories as the second argument. Use the slice() method to limit the result to the top 5 memories.
• Modify the prefixPrompt variable to include the reflectionMemories. After the line where relevantMemories is defined, add a new line to define relevantReflections. Map over the reflectionMemories and join their descriptions with a newline character. Include relevantReflections in the prefixPrompt string.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Include top 5 reflection memories in converse() function sweep/fix-converse-function

Description

This PR addresses the issue #5 by modifying the converse() function in conversation.ts to include the top 5 reflection memories in the chat prompt. Currently, the function only fetches conversation memories and does not consider reflection memories. This update ensures that the chat prompt includes relevant reflection memories, providing a more contextually aware conversation experience.

Summary of Changes

  • Imported the filterMemoriesType function from ./lib/memory in conversation.ts.
  • Added a new line in the converse() function to fetch the top 5 reflection memories using filterMemoriesType() with 'reflection' as the memory type.
  • Modified the prefixPrompt variable to include the reflectionMemories in the chat prompt.
  • Updated the prefixPrompt to include the descriptions of the relevant reflection memories.
  • Created a new branch fix-converse-function for these changes.

Step 4: ⌨️ Coding

File Instructions Progress
convex/conversation.ts Modify convex/conversation.ts with contents:
* Import the filterMemoriesType function from ./lib/memory at the top of the file.
• Inside the converse() function, after the line where conversationMemories is defined, add a new line to define reflectionMemories. Call filterMemoriesType() with 'reflection' as the memory type and memories as the second argument. Use the slice() method to limit the result to the top 5 memories.
• Modify the prefixPrompt variable to include the reflectionMemories. After the line where relevantMemories is defined, add a new line to define relevantReflections. Map over the reflectionMemories and join their descriptions with a newline character. Include relevantReflections in the prefixPrompt string.
✅ Commit d76e3ca I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/fix-converse-function.

Here is the 1st review

Hi there,

Great job on your work so far. I've noticed a few things that need to be addressed:

  • In the file convex/conversation.ts, there is a duplicate line of code on lines 122 and 123. You only need to join the reflectionMemories descriptions once, so one of these lines can be removed.

Keep up the good work!

I finished incorporating these changes.


To recreate the pull request edit the issue title or description. Join Our Discord