diff --git a/README.md b/README.md index a439161..f592839 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,7 @@ Crafting minds for Minecraft with AI! Install Node.js >= 14 from [nodejs.org](https://nodejs.org/) -Then, install mineflayer -``` -npm install mineflayer -npm install mineflayer-pathfinder -npm install mineflayer-collectblock -``` +Install node modules with `npm install` ## Usage @@ -19,4 +14,4 @@ Start minecraft server on localhost port `55916` Add `OPENAI_API_KEY` (and optionally `OPENAI_ORG_ID`) to your environment variables. -run `npm main.js` +run `node main.js` diff --git a/package.json b/package.json index 314ebb3..4f9767c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "type": "module", "dependencies": { - "mineflayer": "^4.11.0", + "mineflayer": "^4.14.0", "mineflayer-collectblock": "^1.4.1", - "mineflayer-pathfinder": "^2.4.4" + "mineflayer-pathfinder": "^2.4.4", + "openai": "^4.4.0" } } diff --git a/utils/gpt.js b/utils/gpt.js index ffd5c10..7f52586 100644 --- a/utils/gpt.js +++ b/utils/gpt.js @@ -1,16 +1,16 @@ -import { Configuration, OpenAIApi } from 'openai'; +import OpenAIApi from 'openai'; -var openAiConfig = null; +let openAiConfig = null; if (process.env.OPENAI_ORG_ID) { - openAiConfig = new Configuration({ + openAiConfig = { organization: process.env.OPENAI_ORG_ID, apiKey: process.env.OPENAI_API_KEY, - }); + }; } else { - openAiConfig = new Configuration({ + openAiConfig = { apiKey: process.env.OPENAI_API_KEY, - }); + }; } const openai = new OpenAIApi(openAiConfig); @@ -28,16 +28,16 @@ export async function sendRequest(turns, systemMessage, stop_seq) { let res = null; try { - let completion = await openai.createChatCompletion({ + let completion = await openai.chat.completions.create({ model: 'gpt-3.5-turbo', messages: messages, stop: stop_seq, }); - res = completion.data.choices[0].message.content; + res = completion.choices[0].message.content; } catch (err) { console.log(err); - res = 'I amm sorry, I do not know how to respond to that.'; + res = 'I am sorry, I do not know how to respond to that.'; } return res; }