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

相关文章

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.

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

浅析如何使用Swagger生成带权限控制的API文档

《浅析如何使用Swagger生成带权限控制的API文档》当涉及到权限控制时,如何生成既安全又详细的API文档就成了一个关键问题,所以这篇文章小编就来和大家好好聊聊如何用Swagger来生成带有... 目录准备工作配置 Swagger权限控制给 API 加上权限注解查看文档注意事项在咱们的开发工作里,API

一分钟带你上手Python调用DeepSeek的API

《一分钟带你上手Python调用DeepSeek的API》最近DeepSeek非常火,作为一枚对前言技术非常关注的程序员来说,自然都想对接DeepSeek的API来体验一把,下面小编就来为大家介绍一下... 目录前言免费体验API-Key申请首次调用API基本概念最小单元推理模型智能体自定义界面总结前言最

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

SpringBoot中的404错误:原因、影响及解决策略

《SpringBoot中的404错误:原因、影响及解决策略》本文详细介绍了SpringBoot中404错误的出现原因、影响以及处理策略,404错误常见于URL路径错误、控制器配置问题、静态资源配置错误... 目录Spring Boot中的404错误:原因、影响及处理策略404错误的出现原因1. URL路径错

C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep