当前位置: 首页 > article >正文

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


http://www.kler.cn/news/283014.html

相关文章:

  • QT中引入SQLITE3数据库
  • 自定义全局变量在SpringBoot的应用
  • 后端完成api顺序
  • 外卖霸王餐项目是什么?怎么搭建属于自己的外卖霸王餐小程序 ?
  • 灰度发布-介绍-全链路灰度实现
  • 由浅入深学习 C 语言:Hello World【提高篇】
  • 浏览器缓存
  • 网络安全-安全渗透简介和安全渗透环境准备
  • 【CSP:202109-2】非零段划分(Java)
  • 4.sklearn-K近邻算法、模型选择与调优
  • MySQL集群技术1——编译部署mysql
  • “重启就能解决一切问题”,iPhone重启方法大揭秘
  • 解决:无法从域控制器读取配置信息
  • 2024.8.29 C++
  • C#面:ASP.NET MVC 中还有哪些注释属性用来验证?
  • RKNPU2从入门到实践 ---- 【8】借助 RKNN Toolkit lite2 在RK3588开发板上部署RKNN模型
  • 设计模式--装饰器模式
  • 理解torch.argmax() ,我是错误的
  • 融资和融券分别是什么意思,融资融券开通后能融到多少资金?
  • Datawhale X 李宏毅苹果书 AI夏令营_深度学习基础学习心得Task2.2
  • Java 入门指南:Java NIO —— Selector(选择器)
  • 【hot100篇-python刷题记录】【搜索二维矩阵】
  • 分布式锁的实现:ZooKeeper 的解决方案
  • hive数据迁移
  • 低代码革命:JNPF平台如何简化企业应用开发
  • Linux 中的中断响应机制
  • TCP keepalive和HTTP keepalive区别
  • SCP拷贝失败解决办法
  • 基于单片机的指纹识别考勤系统设计
  • Web应用服务器Tomcat