OpenAI API 404 response
Asked Answered
L

1

5

I'm trying to use ChatGPT for my Telegram bot. I used to use "text-davinci-003" model, and it was working fine (even now it's working fine), but I'm not satisfied with its responses.

Now I'm trying to change the model to "gpt-3.5-turbo", and it's throwing a 404 response code with text "Error: Request failed with status code 404" and nothing else. Here's my code:

import { Configuration, OpenAIApi } from "openai";
import { env } from "../utils/env.js";

const model = "gpt-3.5-turbo"; // works fine when it's "text-davinci-003"
const configuration = new Configuration({
  apiKey: env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

export async function getChatGptResponse(request) {
  try {
    const response = await openai.createCompletion({
      model,
      prompt: request, // request comes as a string
      max_tokens: 2000,
      temperature: 1,
      stream: false
    });

    console.log("Full response: ", response, `Choices: `, ...response.data.choices)
    return response.data.choices[0].text;
  } catch (err) {
    console.log(`ChatGPT error: ` + err);
    return err;
  }
}
Lally answered 13/3, 2023 at 16:17 Comment(1)
E
13

Try to use createChatCompletion rather than createCompletion:

const response = async (message) => {
  const response = await openai.createChatCompletion({
    model: "gpt-3.5-turbo",
    messages: [{ role: "user", content: "Hello world" }],
  });

  return response.data.choices[0].message.content;
};
Embosom answered 13/3, 2023 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.