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. 使用下面的代码

cs 复制代码
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中部署的正确部署名称。"

相关推荐
shelby_loo9 小时前
Azure学生订阅上手实操:快速搭建Docker+WordPress环境
microsoft·docker·azure
AI2AGI11 小时前
天天AI-20250121:全面解读 AI 实践课程:动手学大模型(含PDF课件)
大数据·人工智能·百度·ai·文心一言
鸭鸭鸭进京赶烤15 小时前
OpenAI秘密重塑机器人军团: 实体AGI的崛起!
人工智能·opencv·机器学习·ai·机器人·agi·机器翻译引擎
佛州小李哥17 小时前
在亚马逊云科技上用AI提示词优化功能写出漂亮提示词(下)
人工智能·科技·ai·语言模型·云计算·aws·亚马逊云科技
大模型铲屎官19 小时前
玩转 LangChain:从文档加载到高效问答系统构建的全程实战
人工智能·python·ai·langchain·nlp·文档加载·问答系统构建
Ai多利1 天前
2025发文新方向:AI+量化 人工智能与金融完美融合!
人工智能·ai·金融·量化
p2052 天前
搭建个人AI知识库-DIFY
ai
佛州小李哥2 天前
在亚马逊云科技上高效蒸馏低成本、高精度的Llama 3.1 405B模型(上篇)
人工智能·科技·ai·语言模型·云计算·aws·亚马逊云科技
wit_@2 天前
【深入解析】棋类游戏算法:Minimax, Negamax, 蒙特卡洛树搜索与AlphaZero
python·ai·negamax
xianfianpan3 天前
史上最简单open-webui安装方式!!!
python·深度学习·神经网络·ai