Comments (1)
Solution : modifier le fichier api.js pour qu'il corresponde à la nouvelle version de l'API OpenAI.
En effet, il faut maintenant spécifier le modèle dans le corps de la requête et non plus dans l'URL.
import fetch from "isomorphic-fetch";
import dotenv from "dotenv";
dotenv.config();
import debug from "debug";
const error = debug("minecraft-openai.api:error");
const log = debug("minecraft-openai.api:log");
const STOP_WORD = "//";
const EOL = "\n";
/**
* Call the OpenAI API with the previous context and the new user input.
*
* @param {string} input The user's input from the Minecraft chat.
* @param {string} context The previous context to be sent to the OpenAI API
* @returns {Pormise<{ id: string, object: string, created: number, mode: string, choices: Array<{ text: string, index: number, logprobs: any, finish_reason: text }> }>}
*/
export async function callOpenAI(input, context) {
const openAIkey = process.env.CODEX_API_KEY;
if (!openAIkey) {
error("ERROR: CODEX_API_KEY is required.");
process.exit(1);
}
const body = {
prompt: `${context}${EOL}${STOP_WORD} ${input}${EOL}`,
model: "text-davinci-003",
temperature: 1,
max_tokens: 256,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
};
log("payload %o", body);
log("context:%s\n", body.prompt);
const response = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${openAIkey}`,
},
body: JSON.stringify(body),
});
log(response);
if (!response.ok) {
error("api response failed with statis %s", response.statusText);
return;
}
return await response.json();
}
Enjoy ;)
from minecraft-openai.
Related Issues (7)
- error with npm start -- --port
- Bot not working. [nodemon] clean exit - waiting for changes before restart.
- "OpenAi response was empty" HOT 4
- Come discuss with us (from PrismarineJS team) HOT 1
- problem with nodemon: [nodemon] clean exit - waiting for changes before restart HOT 2
- Problem recognizing API key
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minecraft-openai.