Merge pull request #372 from kolbytn/convo-patch

Convo patch
This commit is contained in:
Max Robinson 2024-12-18 11:23:31 -06:00 committed by GitHub
commit afe43c000e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 30 deletions

View file

@ -38,10 +38,9 @@
], ],
[ [
{"role": "system", "content": "work together with the other bot"}, {"role": "system", "content": "work together with the other bot to build a house"},
{"role": "assistant", "content": "!startConversation(\"terrance\", \"Hey gpt! Let's work together on this.\"))"}, {"role": "assistant", "content": "!startConversation(\"terrance\", \"Hey gpt! Let's work together to build a house. Let's build it at x:942, y:54, z:1355\"))"},
{"role": "user", "content": "terrance: (FROM OTHER BOT)Sounds good, what should we do first?"}, {"role": "user", "content": "terrance: (FROM OTHER BOT)I can build the base, you can build the walls. !newAction(\"Build a 10x10 wall of a house at x:942, y:54, z:1355\")"}
{"role": "assistant", "content": "I'll start by collecting some resources. !collectBlocks('stone', 10)"}
], ],
[ [

View file

@ -266,13 +266,12 @@ export const actionsList = [
'num': { type: 'int', description: 'The number of times to smelt the item.', domain: [1, Number.MAX_SAFE_INTEGER] } 'num': { type: 'int', description: 'The number of times to smelt the item.', domain: [1, Number.MAX_SAFE_INTEGER] }
}, },
perform: runAsAction(async (agent, item_name, num) => { perform: runAsAction(async (agent, item_name, num) => {
let response = await skills.smeltItem(agent.bot, item_name, num); let success = await skills.smeltItem(agent.bot, item_name, num);
if (response.indexOf('Successfully') !== -1) { if (success) {
// there is a bug where the bot's inventory is not updated after smelting setTimeout(() => {
// only updates after a restart agent.cleanKill('Safely restarting to update inventory.');
agent.cleanKill(response + ' Safely restarting to update inventory.'); }, 500);
} }
return response;
}) })
}, },
{ {
@ -386,12 +385,12 @@ export const actionsList = [
'message': { type: 'string', description: 'The message to send.' }, 'message': { type: 'string', description: 'The message to send.' },
}, },
perform: async function (agent, player_name, message) { perform: async function (agent, player_name, message) {
if (convoManager.inConversation() && !convoManager.inConversation(player_name))
return 'You are already in conversation with other bot.';
if (!convoManager.isOtherAgent(player_name)) if (!convoManager.isOtherAgent(player_name))
return player_name + ' is not a bot, cannot start conversation.'; return player_name + ' is not a bot, cannot start conversation.';
if (convoManager.inConversation(player_name)) if (convoManager.inConversation() && !convoManager.inConversation(player_name))
agent.history.add('system', 'You are already in conversation with ' + player_name + ' Don\'t use this command to talk to them.'); convoManager.forceEndCurrentConversation();
else if (convoManager.inConversation(player_name))
agent.history.add('system', 'You are already in conversation with ' + player_name + '. Don\'t use this command to talk to them.');
convoManager.startConversation(player_name, message); convoManager.startConversation(player_name, message);
} }
}, },

View file

@ -172,9 +172,13 @@ class ConversationManager {
async recieveFromBot(sender, recieved) { async recieveFromBot(sender, recieved) {
const convo = this._getConvo(sender); const convo = this._getConvo(sender);
if (convo.ignore_until_start && !recieved.start)
return;
// check if any convo is active besides the sender // check if any convo is active besides the sender
if (Object.values(this.convos).some(c => c.active && c.name !== sender)) { if (this.inConversation() && !this.inConversation(sender)) {
this.sendToBot(sender, `I'm talking to someone else, try again later. !endConversation("${sender}")`, false, false); this.sendToBot(sender, `I'm talking to someone else, try again later. !endConversation("${sender}")`, false, false);
this.endConversation(sender);
return; return;
} }
@ -182,8 +186,6 @@ class ConversationManager {
convo.reset(); convo.reset();
this.startConversationFromOtherBot(sender); this.startConversationFromOtherBot(sender);
} }
if (convo.ignore_until_start)
return;
this._clearMonitorTimeouts(); this._clearMonitorTimeouts();
convo.queue(recieved); convo.queue(recieved);
@ -230,6 +232,7 @@ class ConversationManager {
endConversation(sender) { endConversation(sender) {
if (this.convos[sender]) { if (this.convos[sender]) {
this.convos[sender].end(); this.convos[sender].end();
if (this.activeConversation.name === sender) {
this._stopMonitor(); this._stopMonitor();
this.activeConversation = null; this.activeConversation = null;
if (self_prompter_paused && !this.inConversation()) { if (self_prompter_paused && !this.inConversation()) {
@ -237,6 +240,7 @@ class ConversationManager {
} }
} }
} }
}
endAllConversations() { endAllConversations() {
for (const sender in this.convos) { for (const sender in this.convos) {
@ -247,6 +251,14 @@ class ConversationManager {
} }
} }
forceEndCurrentConversation() {
if (this.activeConversation) {
let sender = this.activeConversation.name;
this.sendToBot(sender, '!endConversation("' + sender + '")', false, false);
this.endConversation(sender);
}
}
scheduleSelfPrompter() { scheduleSelfPrompter() {
self_prompter_paused = true; self_prompter_paused = true;
} }
@ -332,8 +344,8 @@ function _handleFullInMessage(sender, recieved) {
let message = _tagMessage(recieved.message); let message = _tagMessage(recieved.message);
if (recieved.end) { if (recieved.end) {
convoManager.endConversation(sender); convoManager.endConversation(sender);
sender = 'system'; // bot will respond to system instead of the other bot
message = `Conversation with ${sender} ended with message: "${message}"`; message = `Conversation with ${sender} ended with message: "${message}"`;
sender = 'system'; // bot will respond to system instead of the other bot
} }
else if (recieved.start) else if (recieved.start)
agent.shut_up = false; agent.shut_up = false;
@ -348,6 +360,8 @@ function _tagMessage(message) {
async function _resumeSelfPrompter() { async function _resumeSelfPrompter() {
await new Promise(resolve => setTimeout(resolve, 5000)); await new Promise(resolve => setTimeout(resolve, 5000));
if (self_prompter_paused && !convoManager.inConversation()) {
self_prompter_paused = false; self_prompter_paused = false;
agent.self_prompter.start(); agent.self_prompter.start();
} }
}

View file

@ -230,6 +230,9 @@ export class Prompter {
let current_msg_time = this.most_recent_msg_time; let current_msg_time = this.most_recent_msg_time;
for (let i = 0; i < 3; i++) { // try 3 times to avoid hallucinations for (let i = 0; i < 3; i++) { // try 3 times to avoid hallucinations
await this.checkCooldown(); await this.checkCooldown();
if (current_msg_time !== this.most_recent_msg_time) {
return '';
}
let prompt = this.profile.conversing; let prompt = this.profile.conversing;
prompt = await this.replaceStrings(prompt, messages, this.convo_examples); prompt = await this.replaceStrings(prompt, messages, this.convo_examples);
let generation = await this.chat_model.sendRequest(messages, prompt); let generation = await this.chat_model.sendRequest(messages, prompt);

View file

@ -85,9 +85,9 @@
`} `}
</div> </div>
</div> </div>
<button class="stop-btn" onclick="killAllAgents()">Stop All</button> `).join('') +
<button class="stop-btn" onclick="shutdown()">Shutdown</button> `<button class="stop-btn" onclick="killAllAgents()">Stop All</button>
`).join('') : <button class="stop-btn" onclick="shutdown()">Shutdown</button>` :
'<div class="agent">No agents connected</div>'; '<div class="agent">No agents connected</div>';
}); });