最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a

programmeradmin3浏览0评论

I am creating a POC for a Chat bot using Azure OpenAI and .Net Core. I have created Open AI resource and Deployment Model in Azure. But I am getting error when calling Completechat() function.

Error : HTTP 404 (DeploymentNotFound) 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.

Note: I am using free trial version of Azure OpenAI.

I tried passing Endpoint and API key both ways i.e.

  1. one which is in Manage Key section of OpenAI resource main screen i.e. "/" and its key
  2. second from model deployment screen i.e. ";

Below is my Azure OpenAI and model setup -

.Net code as below -

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using E360_ChatBot.Models;
using Azure.AI.OpenAI;
using System.ClientModel;
using Microsoft.AspNetCore.Http;
using OpenAI.Chat;
using Azure.Core;
using E360_ChatBot.Extensions;

namespace E360_ChatBot.Controllers;

public class HomeController : Controller
{
    private readonly ILogger<HomeController> _logger;
    private readonly AzureOpenAIClient _aiClient;
    private readonly string _deploymentName = "GPT4Model";
    public HomeController(ILogger<HomeController> logger)
    {
        _logger = logger;
        string endpoint = "/";
        string apiKey = <I have added My api Key>;

        _aiClient = new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(apiKey));
        
    }
    //Load the chat window (GET request)
    public IActionResult Index()
    {
        var chatHistory = HttpContext.Session.Get<List<string>>("ChatHistory") ?? new List<string>();

        if (chatHistory.Count == 0)
        {
            chatHistory.Add("E360: Hello, Welcome to E360, how may I help you today?");
            HttpContext.Session.Set("ChatHistory", chatHistory);
        }

        var model = new ChatViewModel
        {
            ChatHistory = chatHistory
        };
        return View("ChatBotHome",model);
    }


    // Handle user input and return AI response (POST request)
    [HttpPost]
    public IActionResult Index(ChatViewModel model)
    {
        var chatHistory = HttpContext.Session.Get<List<string>>("ChatHistory") ?? new List<string>();

        if (!string.IsNullOrEmpty(model.UserInput))
        {
            ChatClient chatClient = _aiClient.GetChatClient(_deploymentName);

      //I am getting chatClient details properly
      //But getting error in below line

            ChatCompletion completion = chatClient.CompleteChat(model.UserInput);

            chatHistory.Add($"You: {model.UserInput}");
            chatHistory.Add($"E360: {completion.Content[0].Text}");

            HttpContext.Session.Set("ChatHistory", chatHistory);
            model.UserInput = string.Empty;
        }
        model.ChatHistory = chatHistory;

        return View(model);
    }

I have been trying since couple of days but not getting any solution. Any leads will be helpful :)

I am creating a POC for a Chat bot using Azure OpenAI and .Net Core. I have created Open AI resource and Deployment Model in Azure. But I am getting error when calling Completechat() function.

Error : HTTP 404 (DeploymentNotFound) 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.

Note: I am using free trial version of Azure OpenAI.

I tried passing Endpoint and API key both ways i.e.

  1. one which is in Manage Key section of OpenAI resource main screen i.e. "https://uschatbot.openai.azure/" and its key
  2. second from model deployment screen i.e. "https://aksha-m88bx4tg-eastus2.cognitiveservices.azure/openai/deployments/GPT4Model"

Below is my Azure OpenAI and model setup -

.Net code as below -

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using E360_ChatBot.Models;
using Azure.AI.OpenAI;
using System.ClientModel;
using Microsoft.AspNetCore.Http;
using OpenAI.Chat;
using Azure.Core;
using E360_ChatBot.Extensions;

namespace E360_ChatBot.Controllers;

public class HomeController : Controller
{
    private readonly ILogger<HomeController> _logger;
    private readonly AzureOpenAIClient _aiClient;
    private readonly string _deploymentName = "GPT4Model";
    public HomeController(ILogger<HomeController> logger)
    {
        _logger = logger;
        string endpoint = "https://uschatbot.openai.azure/";
        string apiKey = <I have added My api Key>;

        _aiClient = new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(apiKey));
        
    }
    //Load the chat window (GET request)
    public IActionResult Index()
    {
        var chatHistory = HttpContext.Session.Get<List<string>>("ChatHistory") ?? new List<string>();

        if (chatHistory.Count == 0)
        {
            chatHistory.Add("E360: Hello, Welcome to E360, how may I help you today?");
            HttpContext.Session.Set("ChatHistory", chatHistory);
        }

        var model = new ChatViewModel
        {
            ChatHistory = chatHistory
        };
        return View("ChatBotHome",model);
    }


    // Handle user input and return AI response (POST request)
    [HttpPost]
    public IActionResult Index(ChatViewModel model)
    {
        var chatHistory = HttpContext.Session.Get<List<string>>("ChatHistory") ?? new List<string>();

        if (!string.IsNullOrEmpty(model.UserInput))
        {
            ChatClient chatClient = _aiClient.GetChatClient(_deploymentName);

      //I am getting chatClient details properly
      //But getting error in below line

            ChatCompletion completion = chatClient.CompleteChat(model.UserInput);

            chatHistory.Add($"You: {model.UserInput}");
            chatHistory.Add($"E360: {completion.Content[0].Text}");

            HttpContext.Session.Set("ChatHistory", chatHistory);
            model.UserInput = string.Empty;
        }
        model.ChatHistory = chatHistory;

        return View(model);
    }

I have been trying since couple of days but not getting any solution. Any leads will be helpful :)

Share Improve this question asked Mar 20 at 9:35 Ak CAk C 497 bronze badges 2
  • 1 Ensure your deployment name matches exactly in Azure and use OpenAIClient with GetChatCompletionsAsync() instead of AzureOpenAIClient. – Dasari Kamali Commented Mar 20 at 9:57
  • My issue resolved. I was using key and endpoint of another resource but my model is deployed to another resource. The resource I wanted to use was not having Quota to create model somehow I managed to create a model but that got deployed to another resource and thats where I was confused. – Ak C Commented Mar 20 at 10:56
Add a comment  | 

1 Answer 1

Reset to default 0

Posting the comment as an answer so that it will help the community find a better solution.

The HTTP 404 (DeploymentNotFound) error occurs when the API deployment for this resource does not exist.

  1. This issue happens when using an incorrect endpoint or API key that does not match the resource where the model is actually deployed.
  2. The OpenAI resource did not have the required quota to create the model, and the model was mistakenly deployed to a different resource.
  3. Additionally, Azure OpenAI deployments may take a few minutes to become active. If the deployment was just created, waiting a few minutes before making API calls can help.
  4. Another important point is checking Azure quotas. If the resource doesn’t have enough quota, the model deployment might have failed.

By updating the endpoint and key to match the correct OpenAI resource, the issue was resolved.

Reference: Azure OpenAI Service quotas and limits - Azure AI services | Microsoft Learn

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论