I’m trying to use chatgpt for my telegram bot, I used to use "text-davinci-003" model, 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 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;
}
}
>Solution :
Did you 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;
};