当前位置: 首页 > news >正文

resource not found with Azure OpenAI service

题意:使用 Azure OpenAI 服务时,系统未能找到所请求的资源

问题背景:

when I am using this demo code to use the Azure OpenAI service in Java 11:

当我在Java 11环境中使用这段示例代码来调用Azure OpenAI服务时:

package com.dolphin.soa.post.config.ai.azure;import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.*;
import com.azure.core.credential.AzureKeyCredential;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;import java.util.ArrayList;
import java.util.List;@Slf4j
public class AzureOpenAIClient {public static void getChatCompletion(){String azureOpenaiKey = "the-key";String endpoint = "https://reddwarfcv.openai.azure.com/";String deploymentOrModelId = "gpt-35-turbo";OpenAIClient client = new OpenAIClientBuilder().endpoint(endpoint).credential(new AzureKeyCredential(azureOpenaiKey)).buildClient();List<ChatMessage> chatMessages = new ArrayList<>();chatMessages.add(new ChatMessage(ChatRole.SYSTEM).setContent("You are a helpful assistant."));chatMessages.add(new ChatMessage(ChatRole.USER).setContent("Does Azure OpenAI support customer managed keys?"));chatMessages.add(new ChatMessage(ChatRole.ASSISTANT).setContent("Yes, customer managed keys are supported by Azure OpenAI?"));chatMessages.add(new ChatMessage(ChatRole.USER).setContent("Do other Azure Cognitive Services support this too?"));ChatCompletions chatCompletions = client.getChatCompletions(deploymentOrModelId, new ChatCompletionsOptions(chatMessages));System.out.printf("Model ID=%s is created at %d.%n", chatCompletions.getId(), chatCompletions.getCreated());for (ChatChoice choice : chatCompletions.getChoices()) {ChatMessage message = choice.getMessage();System.out.printf("Index: %d, Chat Role: %s.%n", choice.getIndex(), message.getRole());System.out.println("Message:");System.out.println(message.getContent());}System.out.println();CompletionsUsage usage = chatCompletions.getUsage();System.out.printf("Usage: number of prompt token is %d, "+ "number of completion token is %d, and number of total tokens in request and response is %d.%n",usage.getPromptTokens(), usage.getCompletionTokens(), usage.getTotalTokens());}public static void main(String[] args) {getChatCompletion();}}

show error:        显示错误:

com.azure.core.exception.ResourceNotFoundException: Status code 404, "{"error":{"code":"DeploymentNotFound", "message":"The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again."}}"
Exception in thread "main"  at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:347)at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:130)at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:213)
com.azure.core.exception.ResourceNotFoundException: Status code 404, "{"error":{"code":"DeploymentNotFound", "message":"The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again."}}"at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:347)at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:130)at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:213)at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:81)at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:81)at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:109)at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:91)at jdk.proxy2/jdk.proxy2.$Proxy3.getChatCompletionsSync(Unknown Source)at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:109)at com.azure.ai.openai.implementation.OpenAIClientImpl.getChatCompletionsWithResponse(OpenAIClientImpl.java:757)at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:91)at jdk.proxy2/jdk.proxy2.$Proxy3.getChatCompletionsSync(Unknown Source)at com.azure.ai.openai.implementation.OpenAIClientImpl.getChatCompletionsWithResponse(OpenAIClientImpl.java:757)at com.azure.ai.openai.OpenAIClient.getChatCompletionsWithResponse(OpenAIClient.java:255)at com.azure.ai.openai.OpenAIClient.getChatCompletionsWithResponse(OpenAIClient.java:255)at com.azure.ai.openai.OpenAIClient.getChatCompletions(OpenAIClient.java:381)at com.dolphin.soa.post.config.ai.azure.AzureOpenAIClient.getChatCompletion(AzureOpenAIClient.java:37)at com.azure.ai.openai.OpenAIClient.getChatCompletions(OpenAIClient.java:381)at com.dolphin.soa.post.config.ai.azure.AzureOpenAIClient.main(AzureOpenAIClient.java:55)at com.dolphin.soa.post.config.ai.azure.AzureOpenAIClient.getChatCompletion(AzureOpenAIClient.java:37)at com.dolphin.soa.post.config.ai.azure.AzureOpenAIClient.main(AzureOpenAIClient.java:55)
13:35:44.075 [main] ERROR com.azure.core.implementation.http.rest.RestProxyBase - Status code 404, "{"error":{"code":"DeploymentNotFound", "message":"The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again."}}"
com.azure.core.exception.ResourceNotFoundException: Status code 404, "{"error":{"code":"DeploymentNotFound", "message":"The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again."}}"at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:347)at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:130)at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:213)at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:81)at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:109)at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:91)at jdk.proxy2/jdk.proxy2.$Proxy3.getChatCompletionsSync(Unknown Source)at com.azure.ai.openai.implementation.OpenAIClientImpl.getChatCompletionsWithResponse(OpenAIClientImpl.java:757)at com.azure.ai.openai.OpenAIClient.getChatCompletionsWithResponse(OpenAIClient.java:255)at com.azure.ai.openai.OpenAIClient.getChatCompletions(OpenAIClient.java:381)at com.dolphin.soa.post.config.ai.azure.AzureOpenAIClient.getChatCompletion(AzureOpenAIClient.java:37)at com.dolphin.soa.post.config.ai.azure.AzureOpenAIClient.main(AzureOpenAIClient.java:55)

I have checked all the configuration and make sure the endpoint was correct, the deployment was created more than 10 hours. Am I missing something? This is the dependencies:

我已经检查了所有配置,并确保端点地址是正确的,部署已经超过10个小时了。我是不是遗漏了什么?这是依赖项:"

implementation'com.azure:azure-ai-openai:1.0.0-beta.1'

I have already tried to upgrade the azure openai dependencies version to 1.0.0-beta.2 but still could not fixed this issue.

我已经尝试将Azure OpenAI的依赖项版本升级到1.0.0-beta.2,但仍然无法解决这个问题。

问题解决:

I tried in my environment and got the below results:

“我在我的环境中尝试了,并得到了以下结果:”

Initially, I got the same error in my environment.

“最初,我在我的环境中遇到了同样的错误。”

[main] ERROR com.azure.core.implementation.http.rest.RestProxyBase Status code 404, "{"error":{"code":"DeploymentNotFound", "message":"The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again."}}"

In your code, at deploymentOrModelId, you have given gpt-35-turbo but you need to mention your deployment name. You can get the deployment name using the portal below.

在你的代码中,deploymentOrModelId 这个位置你填写了 gpt-35-turbo,但你需要提供你的部署名称。你可以使用下面的门户来获取你的部署名称。

Portal:

I tried with the same code change deployment id into deployment1 it executed successfully.

我尝试用相同的代码将部署ID更改为deployment1,它成功执行了。

Code:

import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.*;
import com.azure.core.credential.AzureKeyCredential;import java.util.ArrayList;
import java.util.List;public class App {public static void getChatCompletion(){String azureOpenaiKey = "";String endpoint = "https://xxxxx.openai.azure.com/";String deploymentOrModelId = "deployment1";OpenAIClient client = new OpenAIClientBuilder().endpoint(endpoint).credential(new AzureKeyCredential(azureOpenaiKey)).buildClient();List<ChatMessage> chatMessages = new ArrayList<>();chatMessages.add(new ChatMessage(ChatRole.SYSTEM).setContent("You are a helpful assistant."));chatMessages.add(new ChatMessage(ChatRole.USER).setContent("Does Azure OpenAI support customer managed keys?"));chatMessages.add(new ChatMessage(ChatRole.ASSISTANT).setContent("Yes, customer managed keys are supported by Azure OpenAI?"));chatMessages.add(new ChatMessage(ChatRole.USER).setContent("Do other Azure Cognitive Services support this too?"));ChatCompletions chatCompletions = client.getChatCompletions(deploymentOrModelId, new ChatCompletionsOptions(chatMessages));System.out.printf("Model ID=%s is created at %d.%n", chatCompletions.getId(), chatCompletions.getCreated());for (ChatChoice choice : chatCompletions.getChoices()) {ChatMessage message = choice.getMessage();System.out.printf("Index: %d, Chat Role: %s.%n", choice.getIndex(), message.getRole());System.out.println("Message:");System.out.println(message.getContent());}System.out.println();CompletionsUsage usage = chatCompletions.getUsage();System.out.printf("Usage: number of prompt token is %d, "+ "number of completion token is %d, and number of total tokens in request and response is %d.%n",usage.getPromptTokens(), usage.getCompletionTokens(), usage.getTotalTokens());}public static void main(String[] args) {getChatCompletion();}}

Output:        输出

Model ID=chatcmpl-xxxxx is created at 168776xxx.
Index: 0, Chat Role: assistant.
Message:
Yes, most Azure Cognitive Services support customer managed keys for enhanced security and compliance. Some of the popular services that support customer managed keys include Azure Cognitive Search, Azure Speech Services, Azure Language Understanding, and Azure Computer Vision.Usage: number of prompt token is 59, number of completion token is 44, and number of total tokens in request and response is 103.

Reference:        引用

Azure OpenAI client library for Java | Microsoft Learn

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • day16-测试自动化之selenium的PO模式
  • # Spring Cloud Alibaba Nacos_配置中心与服务发现(四)
  • 八、MyBatis
  • 《网络编程实战系列》(17)网络桥接模式
  • 【设计模式】一文读懂策略模式
  • 【ML】Pre-trained Language Models及其各种微调模型的实现细节和特点
  • zip压缩包的格式不标准导致C++开源unzip.cpp解压失败问题的排查
  • loginApi
  • 每天五分钟深度学习pytorch:训练神经网络模型的基本步骤
  • 【竞品分析】竞品分析报告的基本模板
  • 裁剪或填充张量(Tensor)(四维与五维)(Python代码)
  • 【Python】requests的response.text 和 urllib.request 的 response.read()的区别
  • 编程-设计模式 26:业务代表模式
  • Android11 关于三方应用获取su权限
  • 以Zed项目为例学习大型Rust项目的组织与管理
  • avalon2.2的VM生成过程
  • IDEA常用插件整理
  • Javascript Math对象和Date对象常用方法详解
  • JavaScript 一些 DOM 的知识点
  • JAVA并发编程--1.基础概念
  • Linux gpio口使用方法
  • Python socket服务器端、客户端传送信息
  • Spring框架之我见(三)——IOC、AOP
  • 爱情 北京女病人
  • -- 查询加强-- 使用如何where子句进行筛选,% _ like的使用
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 微信小程序--------语音识别(前端自己也能玩)
  • 用Canvas画一棵二叉树
  • 原生JS动态加载JS、CSS文件及代码脚本
  • 《天龙八部3D》Unity技术方案揭秘
  • ​​​【收录 Hello 算法】10.4 哈希优化策略
  • ​secrets --- 生成管理密码的安全随机数​
  • ​人工智能书单(数学基础篇)
  • !!Dom4j 学习笔记
  • #Lua:Lua调用C++生成的DLL库
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • (LLM) 很笨
  • (Note)C++中的继承方式
  • (pojstep1.1.1)poj 1298(直叙式模拟)
  • (Python第六天)文件处理
  • (笔试题)合法字符串
  • (附源码)springboot课程在线考试系统 毕业设计 655127
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (转)Android学习笔记 --- android任务栈和启动模式
  • (转)用.Net的File控件上传文件的解决方案
  • (转载)Google Chrome调试JS
  • ./configure、make、make install 命令
  • .NET CF命令行调试器MDbg入门(一)
  • .NET CORE 2.0发布后没有 VIEWS视图页面文件
  • .net core 3.0 linux,.NET Core 3.0 的新增功能
  • .NET Core 控制台程序读 appsettings.json 、注依赖、配日志、设 IOptions
  • .net framework4与其client profile版本的区别
  • .net 怎么循环得到数组里的值_关于js数组
  • .NET/C# 异常处理:写一个空的 try 块代码,而把重要代码写到 finally 中(Constrained Execution Regions)
  • .NET/MSBuild 中的发布路径在哪里呢?如何在扩展编译的时候修改发布路径中的文件呢?