add modes to profile

This commit is contained in:
MaxRobinsonTheGreat 2024-06-03 18:23:29 -05:00
parent af8252cd95
commit 25c4f68be7
3 changed files with 28 additions and 13 deletions

View file

@ -9,6 +9,17 @@
"saving_memory": "You are a minecraft bot named $NAME that has been talking and playing minecraft by using commands. Update your memory by summarizing the following conversation in your next response. Store information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you need to remember and what you've learned through player feedback or by executing code. Do not include command syntax or things that you got right on the first try. Be extremely brief and use as few words as possible.\nOld Memory: '$MEMORY'\nRecent conversation: \n$TO_SUMMARIZE\nSummarize your old memory and recent conversation into a new memory, and respond only with the memory text: ", "saving_memory": "You are a minecraft bot named $NAME that has been talking and playing minecraft by using commands. Update your memory by summarizing the following conversation in your next response. Store information that will help you improve as a Minecraft bot. Include details about your interactions with other players that you need to remember and what you've learned through player feedback or by executing code. Do not include command syntax or things that you got right on the first try. Be extremely brief and use as few words as possible.\nOld Memory: '$MEMORY'\nRecent conversation: \n$TO_SUMMARIZE\nSummarize your old memory and recent conversation into a new memory, and respond only with the memory text: ",
"modes": {
"self_preservation": true,
"cowardice": true,
"self_defense": true,
"hunting": true,
"item_collecting": true,
"torch_placing": true,
"idle_staring": true,
"cheat": false
},
"conversation_examples": [ "conversation_examples": [
[ [
{"role": "user", "content": "miner_32: Hey! What are you up to?"}, {"role": "user", "content": "miner_32: Hey! What are you up to?"},

View file

@ -11,7 +11,7 @@ import * as mc from '../../utils/mcdata.js';
export class NPCContoller { export class NPCContoller {
constructor(agent) { constructor(agent) {
this.agent = agent; this.agent = agent;
this.data = NPCData.fromObject(agent.prompter.prompts.npc); this.data = NPCData.fromObject(agent.prompter.profile.npc);
this.temp_goals = []; this.temp_goals = [];
this.item_goal = new ItemGoal(agent, this.data); this.item_goal = new ItemGoal(agent, this.data);
this.build_goal = new BuildGoal(agent); this.build_goal = new BuildGoal(agent);

View file

@ -15,12 +15,12 @@ import { Local } from '../models/local.js';
export class Prompter { export class Prompter {
constructor(agent, fp) { constructor(agent, fp) {
this.agent = agent; this.agent = agent;
this.prompts = JSON.parse(readFileSync(fp, 'utf8')); this.profile = JSON.parse(readFileSync(fp, 'utf8'));
this.convo_examples = null; this.convo_examples = null;
this.coding_examples = null; this.coding_examples = null;
let name = this.prompts.name; let name = this.profile.name;
let chat = this.prompts.model; let chat = this.profile.model;
if (typeof chat === 'string' || chat instanceof String) { if (typeof chat === 'string' || chat instanceof String) {
chat = {model: chat}; chat = {model: chat};
if (chat.model.includes('gemini')) if (chat.model.includes('gemini'))
@ -50,7 +50,7 @@ export class Prompter {
else else
throw new Error('Unknown API:', api); throw new Error('Unknown API:', api);
let embedding = this.prompts.embedding; let embedding = this.profile.embedding;
if (embedding === undefined) { if (embedding === undefined) {
if (chat.api !== 'ollama') if (chat.api !== 'ollama')
embedding = {api: chat.api}; embedding = {api: chat.api};
@ -76,7 +76,7 @@ export class Prompter {
} }
mkdirSync(`./bots/${name}`, { recursive: true }); mkdirSync(`./bots/${name}`, { recursive: true });
writeFileSync(`./bots/${name}/last_profile.json`, JSON.stringify(this.prompts, null, 4), (err) => { writeFileSync(`./bots/${name}/last_profile.json`, JSON.stringify(this.profile, null, 4), (err) => {
if (err) { if (err) {
throw err; throw err;
} }
@ -85,15 +85,19 @@ export class Prompter {
} }
getName() { getName() {
return this.prompts.name; return this.profile.name;
}
getInitModes() {
return this.profile.modes;
} }
async initExamples() { async initExamples() {
console.log('Loading examples...') console.log('Loading examples...')
this.convo_examples = new Examples(this.embedding_model); this.convo_examples = new Examples(this.embedding_model);
await this.convo_examples.load(this.prompts.conversation_examples); await this.convo_examples.load(this.profile.conversation_examples);
this.coding_examples = new Examples(this.embedding_model); this.coding_examples = new Examples(this.embedding_model);
await this.coding_examples.load(this.prompts.coding_examples); await this.coding_examples.load(this.profile.coding_examples);
console.log('Examples loaded.'); console.log('Examples loaded.');
} }
@ -149,25 +153,25 @@ export class Prompter {
} }
async promptConvo(messages) { async promptConvo(messages) {
let prompt = this.prompts.conversing; let prompt = this.profile.conversing;
prompt = await this.replaceStrings(prompt, messages, this.convo_examples); prompt = await this.replaceStrings(prompt, messages, this.convo_examples);
return await this.chat_model.sendRequest(messages, prompt); return await this.chat_model.sendRequest(messages, prompt);
} }
async promptCoding(messages) { async promptCoding(messages) {
let prompt = this.prompts.coding; let prompt = this.profile.coding;
prompt = await this.replaceStrings(prompt, messages, this.coding_examples); prompt = await this.replaceStrings(prompt, messages, this.coding_examples);
return await this.chat_model.sendRequest(messages, prompt); return await this.chat_model.sendRequest(messages, prompt);
} }
async promptMemSaving(prev_mem, to_summarize) { async promptMemSaving(prev_mem, to_summarize) {
let prompt = this.prompts.saving_memory; let prompt = this.profile.saving_memory;
prompt = await this.replaceStrings(prompt, null, null, prev_mem, to_summarize); prompt = await this.replaceStrings(prompt, null, null, prev_mem, to_summarize);
return await this.chat_model.sendRequest([], prompt); return await this.chat_model.sendRequest([], prompt);
} }
async promptGoalSetting(messages, last_goals) { async promptGoalSetting(messages, last_goals) {
let system_message = this.prompts.goal_setting; let system_message = this.profile.goal_setting;
system_message = await this.replaceStrings(system_message, messages); system_message = await this.replaceStrings(system_message, messages);
let user_message = 'Use the below info to determine what goal to target next\n\n'; let user_message = 'Use the below info to determine what goal to target next\n\n';