dont stack llm requests, remove serialization

This commit is contained in:
MaxRobinsonTheGreat 2024-12-04 20:30:57 -06:00
parent cff47d772d
commit 132a535068
3 changed files with 22 additions and 7 deletions

View file

@ -96,10 +96,10 @@ class ConversationManager {
end,
};
sendBotChatToServer(send_to, JSON.stringify(json));
sendBotChatToServer(send_to, json);
}
async recieveFromBot(sender, json) {
async recieveFromBot(sender, recieved) {
const convo = this._getConvo(sender);
// check if any convo is active besides the sender
@ -108,7 +108,6 @@ class ConversationManager {
return;
}
const recieved = JSON.parse(json);
if (recieved.start) {
convo.reset();
}
@ -243,7 +242,7 @@ function _compileInMessages(convo) {
}
function _handleFullInMessage(sender, recieved) {
console.log(`responding to **${JSON.stringify(recieved)}**`);
console.log(`${agent.name} responding to "${recieved.message}" from ${sender}`);
const convo = convoManager._getConvo(sender);
convo.active = true;

View file

@ -34,6 +34,8 @@ export class Prompter {
let chat = this.profile.model;
this.cooldown = this.profile.cooldown ? this.profile.cooldown : 0;
this.last_prompt_time = 0;
this.awaiting_convo = false;
this.awaiting_coding = false;
// try to get "max_tokens" parameter, else null
let max_tokens = null;
@ -225,6 +227,11 @@ export class Prompter {
}
async promptConvo(messages) {
if (this.awaiting_convo) {
console.warn('Already awaiting conversation response, returning no response.');
return '';
}
this.awaiting_convo = true;
for (let i = 0; i < 3; i++) { // try 3 times to avoid hallucinations
await this.checkCooldown();
let prompt = this.profile.conversing;
@ -236,16 +243,25 @@ export class Prompter {
console.warn('LLM hallucinated message as another bot. Trying again...');
continue;
}
this.awaiting_convo = false;
return generation;
}
return "*no response*";
this.awaiting_convo = false;
return "";
}
async promptCoding(messages) {
if (this.awaiting_coding) {
console.warn('Already awaiting coding response, returning no response.');
return '';
}
this.awaiting_coding = true;
await this.checkCooldown();
let prompt = this.profile.coding;
prompt = await this.replaceStrings(prompt, messages, this.coding_examples);
return await this.chat_model.sendRequest(messages, prompt);
let resp = await this.chat_model.sendRequest(messages, prompt);
this.awaiting_coding = false;
return resp;
}
async promptMemSaving(to_summarize) {

View file

@ -72,7 +72,7 @@ export function createMindServer(port = 8080) {
console.warn(`Agent ${agentName} tried to send a message but is not logged in`);
return;
}
console.log(`${curAgentName} sending message to ${agentName}: ${json}`);
console.log(`${curAgentName} sending message to ${agentName}: ${json.message}`);
inGameAgents[agentName].emit('chat-message', curAgentName, json);
});