azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[QUERY] 404 Resource not found when trying to use Azure.AI.OpenAI 2.0.0 version of .net SDK

Open ThomasMaes opened this issue 1 year ago • 3 comments

Library name and version

Azure.AI.OpenAI 2.0.0

Query/Question

I have always developped against the preview packages of this SDK. Now I moved to the 2.0.0 version, but I can't seem to get it working. I always get the response 404 resource not found.

Some details: I use an Azure Open AI service with model GPT4-4o-mini deployment.

This is how i create the client:

// Init the OpenAI client
var openAiClient = new OpenAIClient(
   
    new ApiKeyCredential(openAiSettings.Key),
    new OpenAIClientOptions() {
        Endpoint = new Uri(openAiSettings.Endpoint)
    }
);

// Init the chat client
chatClient = openAiClient.GetChatClient(openAiSettings.ModelName);

This is how I try to call it:

// Build the completion options
var completionOptions = new ChatCompletionOptions()
{
    MaxOutputTokenCount = 800,
    Temperature = (float)0.2,
    FrequencyPenalty = 0,
    PresencePenalty = 0,
    ResponseFormat = ChatResponseFormat.CreateJsonSchemaFormat("QueryAnalysis",
        BinaryData.FromString("""
        {
            "type": "object",
            "properties": {
                "Words": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "Word": { "type": "boolean" },
                            "IsPossessive": { "type": "boolean" },
                            "IsTimeIndicator": { "type": "boolean" },
                            "IsFileFilter": { "type": "boolean" },
                            "IsSearchTerm": { "type": "boolean" },
                            "ImportanceToAnswerQueryWeight": { "type": "integer" }
                        },
                        "required": ["Word", "IsSearchTerm", "ImportanceToAnswerQueryWeight"],
                        "additionalProperties": false
                    }
                },
                "OptimizedSearchQuery": { "type": "string" },
                "ShouldGenerateAnswer": { "type": "boolean" },
                "AdditionalQueries": { "type": "array", "items": { "type": "string" } }
            },
            "required": ["Words", "OptimizedSearchQuery"],
            "additionalProperties": false
        }
        """)
    )
};

// Get the response
var completionsResponse = await chatClient.CompleteChatAsync(
    [systemMessage, userMessage],
    completionOptions
);

Things I tried:

  • Remove the response format
  • Create a new service
  • Create a new deployment
  • Talk to the model deployment via Http calls --> WORKS
  • Call the same model deployment with preview package --> WORKS

I think the problem may be that I cannot specify a version of the model? Or is it that the .net SDK cannot work with newer models yet?

Environment

.NET SDK: Version: 8.0.400 Commit: 36fe6dda56 Workload version: 8.0.400-manifests.251308be MSBuild version: 17.11.3+0c8610977

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.400\

.NET workloads installed: Configured to use loose manifests when installing new manifests. [aspire] Installation Source: VS 17.11.35312.102 Manifest Version: 8.1.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json Install Type: FileBased

Host: Version: 8.0.8 Architecture: x64 Commit: 08338fcaa5

.NET SDKs installed: 8.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

ThomasMaes avatar Oct 14 '24 11:10 ThomasMaes

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

github-actions[bot] avatar Oct 14 '24 16:10 github-actions[bot]

@trrwilson is this a different manifestation of https://github.com/Azure/azure-sdk-for-net/issues/46579?

AngelosP avatar Oct 18 '24 20:10 AngelosP

@AngelosP -- I don't believe so; that other error is an HTTP 400 with a specific "bad request" related to using a feature not supported on a specific service API version, while this issue is an HTTP 404 indicating the deployment isn't found.

@ThomasMaes , does the value of openAiSettings.ModelName in your code match the deployment name for your gpt-4o-mini deployment? Note that the deployment name and model name can be different, as pictured on the below AI Studio deployment entry where the top, green arrow points to a deployment name that's different from the model name pointed to by the bottom, red arrow:

Image

I ask about the model vs. deployment distinction because it's a common source of these 404 errors. Another might be including extra path information on the Azure resource endpoint for the client: AzureOpenAIClient should only be given the top-level resource URI as visible for the Azure OpenAI Service resource on Azure Portal -- https://my-resource-name.openai.azure.net, with no combination of /openai, /deployments, the model name, or /chat/completions included, would be an example of an expected value.

If the endpoint URI and deployment name both look correct, the next step to diagnose would be to capture logs per the following instructions; it'd be particularly good to verify the full request URI (masking hostname encouraged) and request body payload.

https://learn.microsoft.com/dotnet/azure/sdk/logging

trrwilson avatar Oct 18 '24 23:10 trrwilson

I ran into the exact same issue while upgrading to version 2. I verified that the model name is the name in the green arrow, and that the url is structured like https:/my-resource-name.openai.azure.com/.

How can we diagnose the logs? I unfortunately wasn't able to setup the local logging using the linked instructions. (they also contain multiple different ways and I'm not sure which way to choose. Also this project uses Serilog so I reckon I'll need to register it a bit differently too)

panmona avatar Nov 04 '24 11:11 panmona