GithubHelp home page GithubHelp logo

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

manekinekko avatar manekinekko commented on June 3, 2024
minecraft-openai.api:error api response failed with statis Not Found +27s minecraft-openai.bot:log OpenAI response was empty. Ignore. +189ms

from minecraft-openai.

Comments (1)

ranguisj avatar ranguisj commented on June 3, 2024

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)

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.