Open philibertschlutzki opened 1 year ago
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 ;)
It looks like the API isn't working correctly