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

相关文章

如何解决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 文件不匹配

基于Flask框架添加多个AI模型的API并进行交互

《基于Flask框架添加多个AI模型的API并进行交互》:本文主要介绍如何基于Flask框架开发AI模型API管理系统,允许用户添加、删除不同AI模型的API密钥,感兴趣的可以了解下... 目录1. 概述2. 后端代码说明2.1 依赖库导入2.2 应用初始化2.3 API 存储字典2.4 路由函数2.5 应

C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)

《C#集成DeepSeek模型实现AI私有化的流程步骤(本地部署与API调用教程)》本文主要介绍了C#集成DeepSeek模型实现AI私有化的方法,包括搭建基础环境,如安装Ollama和下载DeepS... 目录前言搭建基础环境1、安装 Ollama2、下载 DeepSeek R1 模型客户端 ChatBo

SpringBoot快速接入OpenAI大模型的方法(JDK8)

《SpringBoot快速接入OpenAI大模型的方法(JDK8)》本文介绍了如何使用AI4J快速接入OpenAI大模型,并展示了如何实现流式与非流式的输出,以及对函数调用的使用,AI4J支持JDK8... 目录使用AI4J快速接入OpenAI大模型介绍AI4J-github快速使用创建SpringBoot

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.