gpt4 book ai didi

javascript - OpenAI API 404 响应

转载 作者:行者123 更新时间:2023-12-02 22:45:30 29 4
gpt4 key购买 nike

我正在尝试将 ChatGPT 用于我的 Telegram机器人。我曾经使用“text-davinci-003”模型,它运行良好(即使现在也运行良好),但我对其响应不满意。

现在我尝试将模型更改为“gpt-3.5-turbo”,它抛出一个 404 响应代码,其中包含文本“错误:请求失败,状态代码 404”,仅此而已。这是我的代码:

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;
}
}

最佳答案

尝试使用createChatCompletion而不是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;
};

关于javascript - OpenAI API 404 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75724406/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com