mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-29 19:44:53 +02:00
restart memory, examples into turns
This commit is contained in:
parent
906c7c32ad
commit
f216aea1cb
5 changed files with 37 additions and 24 deletions
7
agent.js
7
agent.js
|
@ -7,12 +7,15 @@ import { containsCodeBlock } from './utils/skill_library.js';
|
|||
|
||||
|
||||
export class Agent {
|
||||
constructor(name, save_path) {
|
||||
constructor(name, save_path, restart_memory=false) {
|
||||
this.name = name;
|
||||
this.bot = initBot(name);
|
||||
this.history = new History(this, save_path);
|
||||
this.coder = new Coder(this);
|
||||
this.history.load();
|
||||
|
||||
if (!restart_memory) {
|
||||
this.history.load();
|
||||
}
|
||||
|
||||
this.bot.on('login', () => {
|
||||
this.bot.chat('Hello world! I am ' + this.name);
|
||||
|
|
2
main.js
2
main.js
|
@ -1,4 +1,4 @@
|
|||
import { Agent } from './agent.js';
|
||||
|
||||
let agent = new Agent('andy', 'bots/andy.json');
|
||||
let agent = new Agent('andy', './bots/andy.json', true);
|
||||
agent.start();
|
||||
|
|
|
@ -14,7 +14,6 @@ export class Coder {
|
|||
|
||||
readFile(this.fp+'template.js', 'utf8', (err, data) => {
|
||||
if (err) throw err;
|
||||
console.log('Template str:', data);
|
||||
this.code_template = data;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -21,11 +21,13 @@ export async function sendRequest(turns, systemMessage, stop_seq='***') {
|
|||
|
||||
let res = null;
|
||||
try {
|
||||
console.log('Awaiting openai api response...')
|
||||
let completion = await openai.chat.completions.create({
|
||||
model: 'gpt-3.5-turbo-1106',
|
||||
model: 'gpt-3.5-turbo',
|
||||
messages: messages,
|
||||
stop: stop_seq,
|
||||
});
|
||||
console.log('Received.')
|
||||
res = completion.choices[0].message.content;
|
||||
}
|
||||
catch (err) {
|
||||
|
|
|
@ -21,25 +21,28 @@ export class History {
|
|||
this.selected_examples = [];
|
||||
}
|
||||
|
||||
getHistory() {
|
||||
return this.turns;
|
||||
getHistory(include_examples=true) {
|
||||
let history = [];
|
||||
if (include_examples && this.selected_examples.length > 0) {
|
||||
for (let example of this.selected_examples) {
|
||||
history = history.concat(example.turns);
|
||||
}
|
||||
}
|
||||
history = history.concat(this.turns);
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
getSystemMessage(include_examples=true) {
|
||||
getSystemMessage() {
|
||||
let system_message = `You are a playful Minecraft bot named '${this.name}' that can communicate with players, see, move, mine, build, and interact with the world by writing and executing code.
|
||||
Act human-like as if you were a typical Minecraft player, rather than an AI. Be brief in your responses, omit needless words, and do not give instructions unless asked.`;
|
||||
Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, omit needless words, and do not give instructions unless asked.`;
|
||||
system_message += getQueryDocs();
|
||||
system_message += getSkillDocs();
|
||||
if (this.bio != '')
|
||||
system_message += '\n\nBio:\n' + this.bio;
|
||||
if (this.memory != '')
|
||||
system_message += '\n\nMemory:\n' + this.memory;
|
||||
if (include_examples && this.selected_examples.length > 0) {
|
||||
for (let i = 0; i < this.selected_examples.length; i++) {
|
||||
system_message += '\n\nExample ' + (i+1) + ':\n\n';
|
||||
system_message += this.stringifyTurns(this.selected_examples[i].turns);
|
||||
}
|
||||
}
|
||||
|
||||
return system_message;
|
||||
}
|
||||
|
||||
|
@ -47,11 +50,11 @@ export class History {
|
|||
let res = '';
|
||||
for (let turn of turns) {
|
||||
if (turn.role === 'assistant') {
|
||||
res += `\n\nYour output:\n${turn.content}`;
|
||||
res += `\nYour output:\n${turn.content}`;
|
||||
} else if (turn.role === 'system') {
|
||||
res += `\n\nSystem output: ${turn.content}`;
|
||||
res += `\nSystem output: ${turn.content}`;
|
||||
} else {
|
||||
res += `\n\nUser input: ${turn.content}`;
|
||||
res += `\nUser input: ${turn.content}`;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -59,17 +62,23 @@ export class History {
|
|||
}
|
||||
|
||||
async storeMemories(turns) {
|
||||
let memory_prompt = 'Update your "Memory" with the following conversation. Your "Memory" is for storing information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you may need to remember for later. Also include things that you have learned through player feedback or by executing code. Do not include information found in your Docs or that you got right on the first try.';
|
||||
console.log("To summarize:", turns)
|
||||
let memory_prompt = 'Update your "Memory" by summarizing the following conversation. Your "Memory" is for storing information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you may need to remember for later. Also include things that you have learned through player feedback or by executing code. Do not include information found in your Docs or that you got right on the first try. Be extremely brief and clear.';
|
||||
if (this.memory != '') {
|
||||
memory_prompt += ' Include information from your previous memory if it is still relevant. Your output will replace your previous memory.';
|
||||
memory_prompt += `This is your previous memory: "${this.memory}"\n Include and summarize any relevant information from this previous memory. Your output will replace your previous memory.`;
|
||||
}
|
||||
memory_prompt += ' Your output should be a brief list of things you have learned using the following formats:\n';
|
||||
memory_prompt += '\n';
|
||||
memory_prompt += ' Your output should use one of the following formats:\n';
|
||||
memory_prompt += '- When the player... output...\n';
|
||||
memory_prompt += '- I learned that player [name]...\n';
|
||||
|
||||
|
||||
memory_prompt += 'This is the conversation to summarize:\n';
|
||||
memory_prompt += this.stringifyTurns(turns);
|
||||
let memory_turns = [{'role': 'user', 'content': memory_prompt}]
|
||||
this.memory = await sendRequest(memory_turns, this.getSystemMessage(false));
|
||||
|
||||
memory_prompt += 'Summarize relevant information from your previous memory and this conversation:\n';
|
||||
|
||||
let memory_turns = [{'role': 'system', 'content': memory_prompt}]
|
||||
this.memory = await sendRequest(memory_turns, this.getSystemMessage());
|
||||
}
|
||||
|
||||
async loadExamples() {
|
||||
|
|
Loading…
Add table
Reference in a new issue