OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API
https://www.nuget.org/packages/OpenAI/
Other
1.86k stars 432 forks source link

Azure - HTTP status code: NotFound. Content: {"error":{"code":"404","message": "Resource not found"}})' #179

Open AlexGrossi opened 1 year ago

AlexGrossi commented 1 year ago

I am trying to connect to Azure using OpenAIAPI. However, despite my deployment ID and resourcename being correct, I am encountering the following error:

System.AggregateException 'One or more errors occurred. (Error at images/generations (https://LSopenAIUS.openai.azure.com/openai/deployments/lasetestai/images/generations?api-version=2022-12-01) with HTTP status code: NotFound. Content: {"error":{"code":"404","message": "Resource not found"}})'

Inner Exception: HttpRequestException: Error at images/generations (https://LSopenAIUS.openai.azure.com/openai/deployments/lasetestai/images/generations?api-version=2022-12-01) with HTTP status code: NotFound. Content: {"error":{"code":"404","message": "Resource not found"}}

The code

public void CreateImageWithUrl(string query)
        {
            OpenAIAPI api = OpenAIAPI.ForAzure(deployment, deploymentID, key);
            //OpenAIAPI api = new OpenAIAPI(testkey2);
            var results = api.ImageGenerations.CreateImageAsync(new ImageGenerationRequest(query, 1, ImageSize._256)).Result;

            Assert.That(results.Data.First().Url.Length > 0);
            Assert.That(results.Data.First().Url.StartsWith("https://"));
            Console.WriteLine(results.Data[0].Url);
        }

What I tried I can confirm that deployment and deployment ID are correct. However, not much more testing can be conducted further until I understand what is causing this issue.

OkGoDoIt commented 11 months ago

I think you need to specify a more up to date Azure API version using api.ApiVersion = "2023-03-15-preview";, although as I don't have access to the Azure API it's hard for me to debug. See https://github.com/OkGoDoIt/OpenAI-API-dotnet#azure for Azure details.