Azure AI Studio Chat Playground sample code returns 404 - Error: NotFound, Resource Not Found

Matthew H 20 Reputation points
2024-03-24T17:32:35.0433333+00:00

Using the C# sample code taken directly from the Azure AI Studio Chat Playground, results in a 404 "Resource Not Found" error. I replaced the GPT4V_KEY, IMAGE_PATH, and QUESTION appropriately. Can anyone else get this code to work?

Screenshot 2024-03-24 131709

  
using Newtonsoft.Json;
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
    private const string GPT4V_KEY = "xxxxxxxxxxxxxxxxxxxx"; // Set your key here
    private const string IMAGE_PATH = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // Set your image path here
    private const string QUESTION = "How many people are in this image"; // Set your question here
    private const string GPT4V_ENDPOINT = "https://xxxxxxxxxxx.openai.azure.com/openai/deployments/gpt-4-vision/extensions/chat/completions?api-version=2024-02-15-preview";
    static async Task Main()
    {
        var encodedImage = Convert.ToBase64String(File.ReadAllBytes(IMAGE_PATH));
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("api-key", GPT4V_KEY);
            var payload = new
            {
                enhancements = new
                {
                    ocr = new { enabled = true },
                    grounding = new { enabled = true }
                },
                messages = new object[]
                {
                  new {
                      role = "system",
                      content = new object[] {
                          new {
                              type = "text",
                              text = "You are an AI assistant that helps people find information."
                          }
                      }
                  },
                  new {
                      role = "user",
                      content = new object[] {
                          new {
                              type = "image_url",
                              image_url = new {
                                  url = $"data:image/jpeg;base64,{encodedImage}"
                              }
                          },
                          new {
                              type = "text",
                              text = QUESTION
                          }
                      }
                  }
                },
                temperature = 0.7,
                top_p = 0.95,
                max_tokens = 800,
                stream = false
            };
            var response = await httpClient.PostAsync(GPT4V_ENDPOINT, new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json"));
            if (response.IsSuccessStatusCode)
            {
                var responseData = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync());
                Console.WriteLine(responseData);
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}, {response.ReasonPhrase}");
            }
        }
    }
}

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,132 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,866 questions
{count} votes

Accepted answer
  1. navba-MSFT 24,795 Reputation points Microsoft Employee
    2024-03-26T06:02:40.4566667+00:00

    @Matthew H Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I tried with your above sample and it failed with the same 404 error. You need to change the api-version to 2023-12-01-preview in the GPT4V_ENDPOINT and this should fix this issue.

    private const string GPT4V_ENDPOINT = "https://XXXXXXX/openai/deployments/XXXXX/extensions/chat/completions?api-version=2023-12-01-preview";
    

    More info here. Hope this helps.

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.