OpenAI API Error: Resource not found - Text Summarization in NodeJS
题意:OpenAI API 错误:资源未找到 - NodeJS 中的文本摘要
问题背景:
Here is the text summarization function. I have valid azure openai API, endpoint through a valid subscription and I have mentioned them in the .env file correctly. I do feel the issue is in this url - ${endpoint}/v1/chat/completions
. Please provide any solution.
这是文本摘要函数。我有有效的 Azure OpenAI API、有效订阅的终结点,并且我已经在 .env 文件中正确提及了它们。我觉得问题可能出在这个 URL 上——`${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;
I tried, 我尝试了以下方法
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
;
问题解决:
Make sure you have a valid subscription, valid Azure OpenAI API key and endpoint.
请确保您有有效的订阅、有效的 Azure OpenAI API 密钥和终结点。
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);
}
};