OpenAI API 错误:资源未找到 – 在NodeJS中进行文本摘要

这是文本摘要功能。我拥有有效的Azure OpenAI API和通过有效订阅的端点,并且我在.env文件中正确提到了它们。我觉得问题出在这个URL上 – ${endpoint}/v1/chat/completions。请提供任何解决方案。

    const prompt = `提供文本摘要:${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密钥和端点。

const { OpenAIClient, AzureKeyCredential } = require("@azure/openai");const generateSummary = async (data) => {  const messages = [    { role: "user", content: `提供文本摘要:${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("样本遇到错误:", err);  }};

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注