azure OpenAI API错误:资源未找到-NodeJS中的文本摘要

ijnw1ujt  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(161)

这里是文本摘要功能。我有有效的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;

字符串
我试过了
const url = x1m1n;
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 ;

kx1ctssn

kx1ctssn1#

我设法解决了这个问题。我为遇到同样错误的人发布解决方案。请确保您拥有有效的订阅、有效的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);
  }
};

字符串

相关问题