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

Openai api via azure error: NotFoundError: 404 Resource not found

题意:"OpenAI API通过Azure出错:NotFoundError: 404 找不到资源"

问题背景:

thanks to the university account my team and I were able to get openai credits through microsoft azure. The problem is that now, trying to use the openai library for javascript, rightly specifying the key and endpoint that azure gave us, we can't connect and a 404 error comes up:

"多亏了大学账户,我的团队和我能够通过Microsoft Azure获得OpenAI的额度。但问题是,现在我们尝试使用OpenAI的JavaScript库,并正确指定了Azure提供的密钥和端点,却无法连接,出现了404错误:"

NotFoundError: 404 Resource not found
    at APIError.generate (file:///home/teo/social_stories_creator/node_modules/openai/error.mjs:48:20)
    at OpenAI.makeStatusError (file:///home/teo/social_stories_creator/node_modules/openai/core.mjs:244:25)
    at OpenAI.makeRequest (file:///home/teo/social_stories_creator/node_modules/openai/core.mjs:283:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (file:///home/teo/social_stories_creator/test.mjs:9:22) {
  status: 404,
  headers: {
    'apim-request-id': 'e04bf750-6d8c-478e-b6d5-967bbbc44b62',
    'content-length': '56',
    'content-type': 'application/json',
    date: 'Sat, 18 Nov 2023 10:14:24 GMT',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    'x-content-type-options': 'nosniff'
  },
  error: { code: '404', message: 'Resource not found' },
  code: '404',
  param: undefined,
  type: undefined
}

Node.js v21.1.0

The code we are testing, is this:        "我们正在测试的代码如下:"

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: 'OUR_KEY',
  baseURL: 'OUR_ENDPOINT',
});

async function main() {
  const completion = await openai.chat.completions.create({
    messages: [{ role: 'system', content: 'You are a helpful assistant.' }],
    model: 'gpt-3.5-turbo',
  });

  console.log(completion.choices[0]);
}

main();

问题解决:

You need to use the Azure client library like below.

"您需要像下面这样使用Azure客户端库。"

Install the package below.        安装下面的包

npm install @azure/openai

And use the following code.        使用下面的代码

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

async function main(){
  // Replace with your Azure OpenAI key
  const key = "YOUR_AZURE_OPENAI_KEY";
  const endpoint = "https://myaccount.openai.azure.com/";
  const client = new OpenAIClient(endpoint, new AzureKeyCredential(key));

  const examplePrompts = [
    "How are you today?",
    "What is Azure OpenAI?",
    "Why do children love dinosaurs?",
    "Generate a proof of Euler's identity",
    "Describe in single words only the good things that come into your mind about your mother.",
  ];

  const deploymentName  =  "gpt35turbo"; //Your deployment name

  let promptIndex = 0;
  const { choices } = await client.getCompletions(deploymentName, examplePrompts);
  for (const choice of choices) {
    const completion = choice.text;
    console.log(`Input: ${examplePrompts[promptIndex++]}`);
    console.log(`Chatbot: ${completion}`);
  }
}

main().catch((err) => {
  console.error("The sample encountered an error:", err);
});

Here, you need to provide the correct deployment name you deployed in Azure OpenAI.

"在这里,您需要提供在Azure OpenAI中部署的正确部署名称。"

 


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

相关文章:

  • 优化系统性能:深入探讨Web层缓存与Redis应用的挑战与对策
  • 虹科技术|全新Linux环境PCAN驱动程序发布!CAN/CAN FD通信体验全面升级!
  • C# 什么是属性
  • Linux操作系统在虚拟机VM上的安装【CentOS版本】
  • 深入解析 Maven 子父模块的依赖管理
  • Java 面试题:HTTP版本演变--xunznux
  • Web-gpt
  • UR5e Gazebo仿真
  • Go 服务调试精解
  • 备战秋招60天算法挑战,Day28
  • 个人旅游网(1)——数据库表详解
  • 爬虫入门学习
  • Java Web —— 第十天(AOP切面编程)
  • Dxf文件中多段线弧线的计算
  • 三星与海力士发力决战HBM4
  • 【知识】缓存类型和策略
  • 数据合规性分析:守护信息安全的关键防线
  • 原生开发柱状图
  • 钉钉好用吗?类似钉钉的内部知识库有哪些?
  • 【微信小程序】微信小程序如何使用 MobX 进行状态管理?
  • 【已解决】win11笔记本电脑突然无法检测到其他显示器 / 无法使用扩展屏(2024.8.29 / 驱动更新问题)
  • Linux使用ifconfig配置临时ip地址
  • ET6框架(八)事件系统
  • UE5 摄像机图像采集到材质 映射到 UI 和 物体表面
  • C语言内存操作函数
  • gitee版本控制
  • 记录|如何全局监听鼠标和键盘等事件
  • ARCGIS 纸质小班XY坐标转电子要素面(2)
  • JavaScript中DOW和BOW;笔记分享;知识回顾
  • YOLOv9改进策略【模型轻量化】| PP-LCnet