gpt4 book ai didi

node.js - OpenAI API错误: Resource not found - Text Summarization in NodeJS

转载 作者:行者123 更新时间:2023-12-03 03:22:32 25 4
gpt4 key购买 nike

这里是文本摘要功能。我有有效的 azure openai API、通过有效订阅的端点,并且我已在 .env 文件中正确提及它们。我确实觉得问题出在这个网址 - ${endpoint}/v1/chat/completions 中。请提供任何解决方案。


const prompt = `Provide a summary of the text: ${data}`;
const apiKey = process.env.AZURE_OPENAI_API_KEY;
const endpoint = process.env.AZURE_OPENAI_ENDPOINT;
const url = `${endpoint}/v1/chat/completions`;

const response = await axios.post(
url,
{
model: "gpt-35-turbo",
prompt: prompt,
temperature: 0.3,
max_tokens: 250,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
}
);
const summary = response.data.choices[0].text.trim();
return summary;

我试过了,

const url = ${endpoint}/v1/completions;

const url = ${endpoint}/openai/deployments/MY_DEPLOYMENT_NAME/completions?api-version=2023-05-15;

const url = ${endpoint}/openai/deployments/MY_DEPLOYMENT_NAME/completions?api-version=2023-05-15-preview;

最佳答案

我设法解决了这个问题。我为遇到同样错误的人发布了解决方案。确保您拥有有效的订阅、有效的 Azure OpenAI API key 和终结点。可能有比这更好的解决方案。如果您有,请在这里评论。

const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");

const generateSummary = async (data) => {
const messages = [
{ role: "user", content: `Provide a summary of the text: ${data}` },
];

try {
const client = new OpenAIClient(endpoint, new AzureKeyCredential(azureApiKey));
const deploymentId = "<MY_DEPLOYMENT_NAME>";
const result = await client.getChatCompletions(deploymentId, messages);

for (const choice of result.choices) {
const summary = choice.message.content;
return summary;
}
} catch (err) {
console.error("The sample encountered an error:", err);
}
};

关于node.js - OpenAI API错误: Resource not found - Text Summarization in NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76687184/

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