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

news/2024/9/18 21:16:09/ 标签: ai, azure, openai api, chatgpt api, azure openai
aidu_pl">

题意:"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 foundat 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 keyconst 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 namelet 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.ppmy.cn/news/1518514.html

相关文章

Zookeeper官网Java示例代码解读(一)

2024-08-22 1. 基本信息 官网地址: https://zookeeper.apache.org/doc/r3.8.4/javaExample.html 示例设计思路 Conventionally, ZooKeeper applications are broken into two units, one which maintains the connection, and the other which monitors data. I…

c-数据结构(顺序表、链表)

概念 对于n各元素的线性表,严格数学定义:其中任意一个数据元素a[i],有且仅有一个前驱a[i-1],有且仅有一个后继a[i1];首元素a[0]无前驱,尾元素a[n-1]无后继。 顺序表 属于线性表,数据之间的空…

在 Java 中使用泛型时遇到的问题,,无法正确将响应数据映射为需要的数据

public <T> List<T> getOrderList(String shopId, Class<T> tClass) {// --- 省略一些中间过程----ParameterizedTypeReference<KeRuYunCommonResultVO<KPOSPageResultVO<T>>> responseType new ParameterizedTypeReference<KeRuYunCom…

Python日志,按日期分割日志文件(每天一个新的日志文件)

为了创建一个Python类来管理日志&#xff0c;并使其支持按日期分割日志文件&#xff08;每天一个新的日志文件&#xff09;&#xff0c;你可以使用Python标准库中的logging模块和logging.handlers.TimedRotatingFileHandler。下面是一个简单的示例&#xff0c;展示了如何实现这…

linux怎么安装Android Studio

方法一 下载安装包到linux系统解压 tar.gz文件的解压方式为 tar -zxvf 文件名&#xff08;tar -zxvf filename.tar.gz 命令的作用是&#xff0c;使用gzip解压缩&#xff08;-z&#xff09;&#xff0c;解包&#xff08;-x&#xff09;名为filename.tar.gz的归档文件&#xf…

使用PostgreSQL的CLI客户端查询数据不显示问题

问题 今天在使用PostgreSQL的命令行工具&#xff08;CLI&#xff09;查询数据时&#xff0c;数据不显示问题。 解决 使用CLI客户端登录数据库后&#xff0c;需要设置打印&#xff0c;设置边框为2: peterlocalhost testdb> \pset border 2或者&#xff0c;使用元组方式显…

clerk中authenticateWithRedirect方法讲解

clerk.authenticateWithRedirect 主要用于处理 Clerk 的 OAuth 登录过程&#xff0c;其工作流程大致如下&#xff1a; 1、用户发起登录请求&#xff1a; 用户点击登录按钮&#xff0c;触发 OAuth 登录流程。 2、重定向到 OAuth 提供商&#xff1a; clerk.authenticateWithRed…

回溯法-0/1背包问题

什么是回溯法&#xff1f; 回溯法是一种搜索算法&#xff0c;它通过深度优先搜索的方式来解决决策问题。它从根节点开始&#xff0c;逐步扩展节点&#xff0c;直到找到所有可能的解。 回溯法的基本思想 开始节点&#xff1a;从根节点出发&#xff0c;这个节点是解空间的起点…

word文档转html(只支持段落和表格)

maven依赖<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>5.2.3</version> </dependency> import org.apache.poi.xwpf.usermodel.*;import java.io.*;public class Wor…

基于Java+SpringMvc+Vue求职招聘系统详细设计实现

基于JavaSpringMvcVue求职招聘系统详细设计实现 &#x1f345; 作者主页 网顺技术团队 &#x1f345; 欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; &#x1f345; 文末获取源码联系方式 &#x1f4dd; &#x1f345; 查看下方微信号获取联系方式 承接各种定制系统 &…

【60天备战软考高级系统架构设计师——第三天:软件工程原则与常用方法】

开篇 软件工程的原则和方法指导开发团队在项目中组织和管理代码及架构。这些原则和方法可以帮助团队提高软件的可维护性和可扩展性。今天&#xff0c;我将重点介绍软件工程中的一些基本原则以及常用方法和工具&#xff0c;帮助大家更好地应对实际开发中的挑战。 软件工程的基…

【Spring Boot 3】【Web】配置HTTPS

【Spring Boot 3】【Web】配置HTTPS 背景介绍开发环境开发步骤及源码工程目录结构背景 软件开发是一门实践性科学,对大多数人来说,学习一种新技术不是一开始就去深究其原理,而是先从做出一个可工作的DEMO入手。但在我个人学习和工作经历中,每次学习新技术总是要花费或多或…

【Android】UIMode

要修改 Android 设备的 UiMode&#xff08;用户界面模式&#xff09;&#xff0c;可以使用 UiModeManager 类进行设置。不同的 UI 模式适用于不同的使用场景&#xff0c;比如夜间模式、汽车模式等。下面是一些常见的修改方法&#xff1a; 1. 修改夜间模式 夜间模式可以通过 U…

Ubuntu/Linux 配置 locale

文章目录 Ubuntu/Linux 配置 locale1 概述2 locale2.1 locale 规则命令规则环境变量优先级 2.2 查看当前 locale 设置2.3 查看当前系统所有可用的 locale2.4 安装中文 locale 语言环境/字符集2.5 安装 locales 包2.6 使用 locale-gen 命令生成语言支持2.7 设置当前默认字符集 3…

基于机器学习的工业制造缺陷分析预测系统

B站视频及代码下载&#xff1a;基于机器学习的工业制造缺陷分析预测系统-视频-代码 1. 项目简介 制造缺陷是工业生产过程中面临的重大挑战之一&#xff0c;对产品质量和生产效率产生直接影响。准确预测和分析制造缺陷的发生&#xff0c;可以帮助企业提高生产质量、降低成本&…

【Linux】:文件IO

目录 1.C文件接口 1.1 当前路径是什么&#xff1f; 1.2 "w"和"a"​编辑 2.系统文件I/O 2.1 "比特宏"标识符的实现: 2.2 open 1.系统默认创建文件的权限只写 2.设置新建文件的权限 3. 覆盖写/清空写/追加写 3.访问文件的本质 3.1 文件…

Java 入门指南:Java Socket 网络通信编程

Socket Socket&#xff08;套接字&#xff09;是用于网络通信的编程接口、网络通信的基础&#xff0c;通过它可以实现不同计算机之间的数据传输&#xff0c;应用程序可以通过它发送或接收数据&#xff1b;就像操作文件那样可以打开、读写和关闭。它提供了一种机制&#xff0c;…

Scrcpy手机投屏投屏到电脑上(windows/mac)

项目场景&#xff1a; 在开发app程序时&#xff0c;需要进行投屏演示程序。市面上有很多可用软件&#xff0c;但是体验感不友好&#xff08;1收费、2操作繁琐&#xff0c;3手机端PC端都需要下载对应的软件&#xff09;很头痛&#xff01;&#xff01;&#xff01; Scrcpy是真的…

需方软件供应链安全保障要求及开源场景对照自评表(上)

国标《信息安全技术 软件供应链安全要求》确立了软件供应链安全目标&#xff0c;规定了软件供应链安全风险管理要求和供需双方的组织管理和供应活动管理安全要求。 开源软件供应链作为软件供应链的一种特殊形式&#xff0c;该国标亦适用于指导开源软件供应链中的供需双方开展组…

灵神算法题单——不定长滑动窗口(求最长最大)

1208. 尽可能使字符串相等 简单的滑动窗口三部曲&#xff1a;移入窗口、是否移出、更新结果。 算差值这里采用abs()函数来实现 class Solution { public:int equalSubstring(string s, string t, int maxCost) {int ls.size();int ant0,miINT_MIN;for(int i0,j0;i<l;i){a…