mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-22 06:02:07 +02:00
Merge pull request #1 from kolbytn/update-openai
updated open ai package and code
This commit is contained in:
commit
9682255f71
3 changed files with 14 additions and 18 deletions
|
@ -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`
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
18
utils/gpt.js
18
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue