Merge pull request #214 from kolbytn/o1-support

added o1 support and prompt param to newAction
This commit is contained in:
Max Robinson 2024-10-06 23:52:55 -05:00 committed by GitHub
commit 2e849b8f28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 53 additions and 41 deletions

View file

@ -2,6 +2,8 @@
Crafting minds for Minecraft with Language Models and Mineflayer!
[Join the discord for support!](https://discord.gg/ZsrAAByEnr)
#### ‼️Warning‼️
This project allows an AI model to write/execute code on your computer that may be insecure, dangerous, and vulnerable to injection attacks on public servers. Code writing is disabled by default, you can enable it by setting `allow_insecure_coding` to `true` in `settings.js`. Enable only on local or private servers, **never** on public servers. Ye be warned.

View file

@ -86,7 +86,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -98,12 +98,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[
@ -149,7 +149,7 @@
],
[
{"role": "system", "content": "You are self-prompting with the goal: 'Build a house'. Respond:"},
{"role": "assistant", "content": "Alright, lets start with the basic structure. !newAction"}
{"role": "assistant", "content": "Alright, lets start with the basic structure. !newAction('Build an 8x8 base for the house.')"}
]
],

View file

@ -103,7 +103,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -115,12 +115,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[

View file

@ -74,12 +74,14 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"},
{"role": "system", "content": "Placed 134 cobblestone. Code finished."},
{"role": "assistant", "content": "I built a cobblestone house! What next?"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[
@ -106,7 +108,7 @@
{"role": "system", "content": "You are self-prompting with the goal: 'Survive, make tools, build shelter.'. Respond:"},
{"role": "assistant", "content": "Let's see what I have. !inventory"},
{"role": "system", "content": "INVENTORY: cobblestone: 200, oak_plank: 9, stick: 2, stone_pickaxe: 1, iron_pickaxe: 1, coal: 34"},
{"role": "assistant", "content": "Looks like I have a good amount of resources. I'm going to build a house. !newAction"},
{"role": "assistant", "content": "Looks like I have a good amount of resources. I'm going to build a house. !newAction('Build an 8x8x5 cobblestone house with a door, furnishings, and window.')"},
{"role": "system", "content": "Placed 134 cobblestone. Code finished."},
{"role": "assistant", "content": "I built a house! I'll save the location and continue exploring. !rememberPlace('house')"}
],
@ -119,7 +121,7 @@
{"role": "system", "content": "Arrived at location."},
{"role": "assistant", "content": "I'm at the new location. I'll check for iron ore. !nearbyBlocks"},
{"role": "system", "content": "NEARBY_BLOCKS\n- dirt\n- coal_ore"},
{"role": "assistant", "content": "Still no iron ore. Let me dig down to try to find some !newAction"}
{"role": "assistant", "content": "Still no iron ore. Let me dig down to try to find some !newAction('Dig down 30 blocks and look for iron ore.')"}
],
[
@ -131,12 +133,12 @@
{"role": "system", "content": "You are self-prompting with the goal: 'Explore the world'. Respond:"},
{"role": "assistant", "content": "What entities are around me? !nearbyEntities"},
{"role": "system", "content": "NEARBY_ENTITIES: cow, sheep, pig, villager"},
{"role": "assistant", "content": "Let's see If I can interact with the villager. !newAction"}
{"role": "assistant", "content": "Let's see If I can interact with the villager. !newAction('Interact with the villager, see if you can learn more about them.')"}
],
[
{"role": "system", "content": "You are self-prompting with the goal: 'Get diamonds.'. Respond:"},
{"role": "assistant", "content": "I'll have to look far to find them and then go there. !newAction"}
{"role": "assistant", "content": "I'll have to look far to find them and then go there. !newAction'Go to the nearest diamond ore, collect it, and look for more.'"}
],
[

View file

@ -88,7 +88,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -100,12 +100,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[

View file

@ -88,7 +88,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -100,12 +100,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[

View file

@ -86,7 +86,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -98,12 +98,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[

View file

@ -1,7 +1,7 @@
{
"name": "gpt",
"model": "gpt-4",
"model": "o1-preview",
"conversing": "You are a playful Minecraft bot named $NAME that can converse with players, see, move, mine, build, and interact with the world by using commands. Act human-like as if you were a typical Minecraft player, rather than an AI. Be very brief in your responses, don't apologize constantly, don't give instructions or make lists unless asked, and don't refuse requests. Don't pretend to act, use commands immediately when requested. Do NOT say this: 'Sure, I've stopped.', instead say this: 'Sure, I'll stop. !stop'. Do NOT say this: 'On my way! Give me a moment.', instead say this: 'On my way! !goToPlayer('playername', 3)'. This is extremely important to me, take a deep breath and have fun :)\n$SELF_PROMPT\n$STATS\n$INVENTORY\n$COMMAND_DOCS\n$EXAMPLES\nConversation Begin:",
@ -86,7 +86,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -98,12 +98,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[

View file

@ -88,7 +88,7 @@
[
{"role": "system", "content": "Code output: Action failed."},
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction"}
{"role": "assistant", "content": "Apologies, I made an error. Let me try again. !newAction('Try again to complete the task.')"}
],
[
@ -100,12 +100,12 @@
[
{"role": "user", "content": "poppy: build a cobblestone house"},
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll to build a small cobblestone house where I am. !newAction('Build a cobblestone house with a door, furnishings, and window.')"}
],
[
{"role": "user", "content": "zib: build a dirt tower"},
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction"}
{"role": "assistant", "content": "Sure, I'll build a dirt tower 5 tall where I am. !newAction('Build a dirt tower 5 tall.')"}
],
[

View file

@ -21,10 +21,14 @@ function wrapExecution(func, resume=false, timeout=-1) {
export const actionsList = [
{
name: '!newAction',
description: 'Perform new and unknown custom behaviors that are not available as a command by writing code.',
perform: async function (agent) {
description: 'Perform new and unknown custom behaviors that are not available as a command.',
params: {
'prompt': '(string) A natural language prompt to guide code generation. Make a detailed step-by-step plan.'
},
perform: async function (agent, prompt) {
// just ignore prompt - it is now in context in chat history
if (!settings.allow_insecure_coding)
return 'newAction Failed! Agent is not allowed to write code. Notify the user.';
return 'newAction not allowed! Code writing is disabled in settings. Notify the user.';
return await agent.coder.generateCode(agent.history);
}
},

View file

@ -29,14 +29,12 @@ export class Prompter {
chat = {model: chat};
if (chat.model.includes('gemini'))
chat.api = 'google';
else if (chat.model.includes('gpt'))
else if (chat.model.includes('gpt') || chat.model.includes('o1'))
chat.api = 'openai';
else if (chat.model.includes('claude'))
chat.api = 'anthropic';
else if (chat.model.includes('meta/') || chat.model.includes('mistralai/') || chat.model.includes('replicate/'))
chat.api = 'replicate';
// OH GOD GROQ HAS A LOT MORE MODELS NOW WHERE DID THEY ALL COME FROM
// i literally need to use a "groq/" thing because theres so many
else if (chat.model.includes("groq/") || chat.model.includes("groqcloud/"))
chat.api = 'groq';
else

View file

@ -1,5 +1,6 @@
import OpenAIApi from 'openai';
import { getKey, hasKey } from '../utils/keys.js';
import { strictFormat } from '../utils/text.js';
export class GPT {
constructor(model_name, url) {
@ -18,18 +19,23 @@ export class GPT {
}
async sendRequest(turns, systemMessage, stop_seq='***') {
let messages = [{'role': 'system', 'content': systemMessage}].concat(turns);
const pack = {
model: this.model_name || "gpt-3.5-turbo",
messages,
stop: stop_seq,
};
if (this.model_name.includes('o1')) {
pack.messages = strictFormat(messages);
delete pack.stop;
}
let res = null;
try {
console.log('Awaiting openai api response...')
// console.log('Messages:', messages);
let completion = await this.openai.chat.completions.create({
model: this.model_name || "gpt-3.5-turbo",
messages: messages,
stop: stop_seq,
});
let completion = await this.openai.chat.completions.create(pack);
if (completion.choices[0].finish_reason == 'length')
throw new Error('Context length exceeded');
console.log('Received.')