Giter Club home page Giter Club logo

minecraft-openai's Introduction

Minecraft OpenAI

A proof of concept for controlling a Minecraft Non-Player Characters using OpenAI and GPT-3.

playing-minecraft-with-ai-gpt-3-no-text

Requirements

  • Clone this project on your local machine.
  • Minecraft (Java Edition) version 1.17
  • Node.js version 14+
  • An OpenAI account
  • Create a .env file and copy your OpenAI API key and save it
CODEX_API_KEY=<your_api_key>

Slide deck

https://slides.com/wassimchegham/playing-minecraft-artificial-intelligence-open-ai-gpt-3-javascript

How to use

Start the Minecraft server

Here is how to start the Minecraft server:

  1. Choose a host computer. This computer should be fast enough to play Minecraft, while running a server for other players as well.
  2. Launch the game and click Single Player.
  3. Create a new world or open an existing one.
  4. Inside that world, press the Esc key, and click Open to LAN.
  5. Choose a game mode to set for the other players.
  6. Choose Creative mode that allows you to fly and place an infinite number of blocks.
  7. Click Start LAN World, and you'll see a message that a local game has been hosted.
  8. Take note of the port number.

Launch the bot

From your terminal, run the following commands:

npm install
npm start -- --port [PORT]

In a few seconds, you should see a message that the bot is running, and you should see the NPC pop up in Minecraft.

Sending commands

Inside the Minecraft client, press the T key to open the chat box.

Loading context

There are mulptiple supported contexts:

  1. empty: An empty context (default).
  2. simple: A basic context.
  3. advanced: A more complex context.

To load a context, type load context [context_name].

You can also reset the current context by typing reset context.

Disclaimer

This is a proof of concept. It is not intended to be used in production.

Troubleshooting

On WSL

If you are using WSL, you may need to provide the host computer's IP address to the bot.

npm start -- --port [PORT] --host [HOST]

To get the IP address of your host computer, run the following command:

wsl.exe hostname -I

minecraft-openai's People

Contributors

amagash avatar manekinekko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minecraft-openai's Issues

error with npm start -- --port

Cannot find module '../minecraft-data/data/pc/common/features.json'
Node.js v18.13.0
[nodemon] app crashed - waiting for file changes before starting...
i cant find were is this features.json

Problem recognizing API key

Happy new year! I'm a bit lost setting this program up on my computer, I created a .env with the required API key in my local copy, though trying to interact with the bot in any way aside from giving it its context causes the bot to crash with the following output:

minecraft-openai.api:error ERROR: CODEX_API_KEY is required.
[nodemon] app crashed - waiting for file changes before starting...

I'm not super savvy with this sort of stuff, so I assume its something fairly obvious which I am getting wrong. In any case, help is much appreciated!

Edit: Fixed the issue, I named the file with the api key incorrectly, very simple fix. Thanks anyway!

Bot not working. [nodemon] clean exit - waiting for changes before restart.

I did everything according to the instructions, entered the port. But alas, nothing worked.

  minecraft-openai.cli:log starting bot +0ms
Error: connect ENOENT [51145]
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'connect',
  address: '[51145]'
}
  minecraft-openai.bot:error Error: connect ENOENT [51145]
  minecraft-openai.bot:error     at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) +0ms
  minecraft-openai.bot:log Error: connect ENOENT [51145]
  minecraft-openai.bot:log     at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) +0ms
Error: connect ENOENT [51145]
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'connect',
  address: '[51145]'
}
  minecraft-openai.bot:error Error: connect ENOENT [51145]
  minecraft-openai.bot:error     at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) +10ms
  minecraft-openai.bot:log Error: connect ENOENT [51145]
  minecraft-openai.bot:log     at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) +10ms
[nodemon] clean exit - waiting for changes before restart

"OpenAi response was empty"

Project Clone
Minecraft: 1.17
Node: 16.15.0
The bot connects, takes the context, but when it has to call the OpenAi API, no response from the API
the log:
cmd_h9D5fydgD8
cmd_qX8YPnJh12

minecraft-openai.api:error api response failed with statis Not Found +27s minecraft-openai.bot:log OpenAI response was empty. Ignore. +189ms

It looks like the API isn't working correctly


 +0ms
  minecraft-openai.api:log payload { prompt: '\n' + '// Go forward\n' + "bot.setControlState('forward', true);\n" + '\n' + '// Go back\n' + "bot.setControlState('back', true);\n" + '\n' + '// jump\n' + "bot.setControlState('jump', true);\n" + '\n' + '// Hello !\n' + 'bot.chat("Hello friend!");\n' + '  \n' + '// Hi how are you ?\n' + `bot.chat("I'm fine, thanks!");\n` + '\n' + "// What's your name ?\n" + 'bot.chat("My name is " + bot.username);\n' + '\n' + "// What's your favorite color ?\n" + 'bot.chat("I like red");\n' + '\n' + "// What's your favorite conference?\n" + 'bot.chat("Devoxx France, of course!");\n' + '  \n' + '// hello\n', max_tokens: 300, temperature: 0, stop: '//', n: 1 } +27s
  minecraft-openai.api:log context:
  minecraft-openai.api:log 
// Go forward
bot.setControlState('forward', true);

// Go back
bot.setControlState('back', true);

// jump
bot.setControlState('jump', true);

// Hello !
bot.chat("Hello friend!");

// Hi how are you ?
bot.chat("I'm fine, thanks!");

// What's your name ?
bot.chat("My name is " + bot.username);

// What's your favorite color ?
bot.chat("I like red");

// What's your favorite conference?
bot.chat("Devoxx France, of course!");

// hello
 +1ms
  minecraft-openai.api:error api response failed with statis Not Found +27s
  minecraft-openai.bot:log OpenAI response was empty. Ignore. +189ms

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.