resource not found with Azure OpenAI service

news/2025/1/16 1:35:38/
aidu_pl">

题意:使用 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


http://www.ppmy.cn/news/1508788.html

相关文章

Ubuntu20.04 运行深蓝路径规划hw1

前言 环境&#xff1a; ubuntu 20.04 &#xff1b; ROS版本&#xff1a; noetic&#xff1b; 问题 1、出现PCL报错&#xff1a;#error PCL requires C14 or above catkin_make 编译时&#xff0c;出现如下错误 解决&#xff1a; 在grid_path_searcher文件夹下面的CMakeLis…

mysql 5.XX 设置中文数据报错

mysql 5.XX 默认是 拉丁文&#xff0c;需要手动修改为 utf8&#xff0c; 查看 库 表 ddl show create database mydatabase; show create table mytable; 可以看到 字符集信息 方法&#xff1a;修改mysql文件 my.ini

SEO之网站结构优化(十-网址规范化2)

初创企业搭建网站的朋友看1号文章&#xff1b;想学习云计算&#xff0c;怎么入门看2号文章谢谢支持&#xff1a; 1、我给不会敲代码又想搭建网站的人建议 2、“新手上云”能够为你开启探索云世界的第一步 博客&#xff1a;阿幸SEO~探索搜索排名之道 4、301转向 1.什么是301转…

嵌入式内存管理高频面试题及参考答案(4万字长文)

目录 嵌入式系统中内存管理的重要性 嵌入式系统中的内存主要分为哪几类&#xff1f; 静态内存分配和动态内存分配的特点 内存对齐的概念及其作用 嵌入式系统中为什么需要关注内存碎片问题 内存分区的概念及其在嵌入式系统中的应用 内存映射文件的概念及其在嵌入式系统中…

C++相关概念和易错语法(25)(列表初始化、initializer_list)

列表初始化是C11中新增的初始化规则&#xff0c;大大增强了初始化的灵活性&#xff0c;在本篇文章中&#xff0c;我会详细讲解列表初始化的各种使用场景。 1.从C语言初始化语法开始改变——不带赋值号的初始化方式 列表初始化可以说是将C语言的一些初始化语法进行放大的结果。…

redis模块和ioredis的注意事项

redis模块和ioredis的注意事项 文章目录 redis模块和ioredis的注意事项前言一、ioredis和redis使用zrange的比较二、出现zrange结果不同的原因总结 前言 node.js在使用redis的时候有两个库可以选择&#xff0c;一个是redis、另一个是ioredis&#xff0c;我一直以来也没有太大关…

基于单片机的智能空气净化系统

【摘 要】 设计了一种基于单片机的智能空气净化系统。通过传感器实时采集空气中 PM2.5 、甲醛等有害健康物质的浓度&#xff0c;将各项数据显示到液晶显示屏&#xff0c;当浓度超过设置的警戒值时&#xff0c;控制蜂鸣器发出警报。根据浓度大小控制空气净化器电机转速&#xf…

高翔【自动驾驶与机器人中的SLAM技术】学习笔记(七)卡尔曼滤波器三:卡尔曼滤波器公式推导【转载】

卡尔曼滤波器三&#xff1a;卡尔曼公式推导 转载来源&#xff1a;卡尔曼滤波&#xff1a;从入门到精通 简述 考虑一个SLAM 问题&#xff0c;它由一个运动方程&#xff1a; x t f ( x t − 1 , u t ) ω t (1) \mathbf{x}_{t}f(\mathbf{x}_{t-1},\mathbf{u}_{t}) \omega_…