KeyserDSoze / Rystem.OpenAi

.Net wrapper for OpenAI with Dependency injection integration, factory integration: you may inject more than one endpoint, azure integration: you may swap among openai endpoint and any azure endpoint quickly and easily. You can calculate tokens and cost for each request (before the request) and for each response.
MIT License
91 stars 12 forks source link

Resource not found #22

Closed ReinoutWW closed 1 year ago

ReinoutWW commented 1 year ago

Describe the bug

Hello,

We've come across the following issue: {“error”:{“code”:“404”,“message”: “Resource not found”}}.

We're using Azure, chat model GPT-4. This error only occurs on the Chat model type, and not the completion model type. Is there a fault in the code?

Azure resource: image

To Reproduce

  1. Add code to startup
  2. Use Azure resource group
  3. Deploy chat model
  4. Add chat model code

Code snippets

services.AddOpenAi(settings =>
            {
                settings.Azure.ResourceName = "Echo-GPT4-Preview";
                settings.ApiKey = Configuration["Azure:OpenAIKey"];
                settings.Azure.MapDeploymentChatModel("EchoDynamic", ChatModelType.Gpt4);
            }, "Azure");

            -----

            var openAiApi = _openAiFactory.Create("Azure");

            var results = new List<ChatResult>();
            await foreach (var x in openAiApi.Chat
                .Request(new ChatMessage { Role = ChatRole.User, Content = "Hello!! How are you?" })
                .WithModel(ChatModelType.Gpt4)
                .WithTemperature(Temperature)
                .ExecuteAsStreamAsync())
            {
                results.Add(x);
            }

OS

Windows

.Net version

.Net 7.0

Library version

3.0.4

KeyserDSoze commented 1 year ago

For GPT4 you need to use a different version for api. For instance for chat I added 2023-03-15-preview here

  services.AddOpenAi(settings =>
            {
                settings.ApiKey = configuration["OpenAi:ApiKey"];
                settings.Azure.ResourceName = configuration["OpenAi:ResourceName"];
                settings.Azure
                    .MapDeploymentEmbeddingModel(configuration["OpenAi:EmbeddingModelName"]!, EmbeddingModelType.AdaTextEmbedding);
                settings.Azure
                    .MapDeploymentChatModel(configuration["OpenAi:ChatModelName"]!, ChatModelType.Gpt35Turbo);
                settings.UseVersionForChat("2023-03-15-preview");
                settings.CustomRetryPolicy = Policy
                .HandleResult<HttpResponseMessage>(r => r.StatusCode != System.Net.HttpStatusCode.OK)
                .WaitAndRetryAsync(3, x => TimeSpan.FromSeconds(2));
            });

Usually when Azure gets Not Found is a problem of endpoint, therefore it could be the name of the resource, the version or a missing endpoint on Azure.