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
120 stars 10 forks source link

Sweep: Add a new function in agent.ts to slow down conversations #2

Open ykhli opened 1 year ago

ykhli commented 1 year ago
Checklist - [X] `convex/agent.ts` > * At the top of the file, import the 'sleep' function from the 'utils' file in the 'lib' directory. If it doesn't exist, create it. The function should use the setTimeout function to create a promise that resolves after a specified number of milliseconds. The code should look like this: "import { sleep } from './lib/utils';" > • In the 'handleAgentInteraction' function, find the part of the code where the messages are being sent in the conversation. This should be inside the while loop that continues until the conversation ends. > • After each message is sent, call the sleep function with the number of milliseconds you want to delay. The number of milliseconds can be a constant defined at the top of the file. The code should look like this: "await sleep(CONVERSATION_DELAY);"
sweep-ai[bot] commented 1 year ago

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

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 4 GPT-4 tickets left for the month and 1 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/08b994e7f97d24e3defe98daadb18e4ee10ee001/convex/agent.ts#L1-L302 https://github.com/ykhli/cat-town/blob/08b994e7f97d24e3defe98daadb18e4ee10ee001/convex/testing.ts#L138-L255 https://github.com/ykhli/cat-town/blob/08b994e7f97d24e3defe98daadb18e4ee10ee001/convex/engine.ts#L12-L151 https://github.com/ykhli/cat-town/blob/08b994e7f97d24e3defe98daadb18e4ee10ee001/convex/lib/memory.ts#L349-L424 https://github.com/ykhli/cat-town/blob/08b994e7f97d24e3defe98daadb18e4ee10ee001/convex/chat.ts#L39-L112

Step 2: 🧐 Snippet Analysis

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

File Path Proposed Changes
convex/agent.ts Modify convex/agent.ts with contents:
* At the top of the file, import the 'sleep' function from the 'utils' file in the 'lib' directory. If it doesn't exist, create it. The function should use the setTimeout function to create a promise that resolves after a specified number of milliseconds. The code should look like this: "import { sleep } from './lib/utils';"
• In the 'handleAgentInteraction' function, find the part of the code where the messages are being sent in the conversation. This should be inside the while loop that continues until the conversation ends.
• After each message is sent, call the sleep function with the number of milliseconds you want to delay. The number of milliseconds can be a constant defined at the top of the file. The code should look like this: "await sleep(CONVERSATION_DELAY);"

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:

Add delay function to slow down conversations in agent.ts sweep/add-delay-function

Description

This PR adds a delay function to slow down conversations in the agent.ts file. The delay function pauses the execution of the conversation for a specified period of time after each message is sent.

Summary of Changes

  • Added import statement for the sleep function from the utils file in the lib directory
  • Introduced a delay function using setTimeout in the utils file
  • Called the delay function after each message is sent in the handleAgentInteraction function
  • Added a constant for the conversation delay at the top of the file

Step 4: ⌨️ Coding

File Instructions Progress
convex/agent.ts Modify convex/agent.ts with contents:
* At the top of the file, import the 'sleep' function from the 'utils' file in the 'lib' directory. If it doesn't exist, create it. The function should use the setTimeout function to create a promise that resolves after a specified number of milliseconds. The code should look like this: "import { sleep } from './lib/utils';"
• In the 'handleAgentInteraction' function, find the part of the code where the messages are being sent in the conversation. This should be inside the while loop that continues until the conversation ends.
• After each message is sent, call the sleep function with the number of milliseconds you want to delay. The number of milliseconds can be a constant defined at the top of the file. The code should look like this: "await sleep(CONVERSATION_DELAY);"
✅ Commit b94abdc 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/add-delay-function.

Here is the 1st review

No changes required. The code changes in the pull request are well implemented. The import of the 'sleep' function, the declaration of the 'CONVERSATION_DELAY' constant, and the use of the 'sleep' function inside the 'handleAgentInteraction' function are all correctly done. Keep up the good work!

I finished incorporating these changes.


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