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

2024-08-30 12:28

本文主要是介绍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 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中部署的正确部署名称。"

 

这篇关于Openai api via azure error: NotFoundError: 404 Resource not found的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1120817

相关文章

使用Python实现调用API获取图片存储到本地的方法

《使用Python实现调用API获取图片存储到本地的方法》开发一个自动化工具,用于从JSON数据源中提取图像ID,通过调用指定API获取未经压缩的原始图像文件,并确保下载结果与Postman等工具直接... 目录使用python实现调用API获取图片存储到本地1、项目概述2、核心功能3、环境准备4、代码实现

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

python通过curl实现访问deepseek的API

《python通过curl实现访问deepseek的API》这篇文章主要为大家详细介绍了python如何通过curl实现访问deepseek的API,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编... API申请和充值下面是deepeek的API网站https://platform.deepsee

Java对接Dify API接口的完整流程

《Java对接DifyAPI接口的完整流程》Dify是一款AI应用开发平台,提供多种自然语言处理能力,通过调用Dify开放API,开发者可以快速集成智能对话、文本生成等功能到自己的Java应用中,本... 目录Java对接Dify API接口完整指南一、Dify API简介二、准备工作三、基础对接实现1.

一文详解如何在Vue3中封装API请求

《一文详解如何在Vue3中封装API请求》在现代前端开发中,API请求是不可避免的一部分,尤其是与后端交互时,下面我们来看看如何在Vue3项目中封装API请求,让你在实现功能时更加高效吧... 目录为什么要封装API请求1. vue 3项目结构2. 安装axIOS3. 创建API封装模块4. 封装API请求

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

springboot项目中常用的工具类和api详解

《springboot项目中常用的工具类和api详解》在SpringBoot项目中,开发者通常会依赖一些工具类和API来简化开发、提高效率,以下是一些常用的工具类及其典型应用场景,涵盖Spring原生... 目录1. Spring Framework 自带工具类(1) StringUtils(2) Coll

Springboot @Autowired和@Resource的区别解析

《Springboot@Autowired和@Resource的区别解析》@Resource是JDK提供的注解,只是Spring在实现上提供了这个注解的功能支持,本文给大家介绍Springboot@... 目录【一】定义【1】@Autowired【2】@Resource【二】区别【1】包含的属性不同【2】@

mysql出现ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost‘ (10061)的解决方法

《mysql出现ERROR2003(HY000):Can‘tconnecttoMySQLserveron‘localhost‘(10061)的解决方法》本文主要介绍了mysql出现... 目录前言:第一步:第二步:第三步:总结:前言:当你想通过命令窗口想打开mysql时候发现提http://www.cpp

springboot报错Invalid bound statement (not found)的解决

《springboot报错Invalidboundstatement(notfound)的解决》本文主要介绍了springboot报错Invalidboundstatement(not... 目录一. 问题描述二.解决问题三. 添加配置项 四.其他的解决方案4.1 Mapper 接口与 XML 文件不匹配