Giter Club home page Giter Club logo

Comments (7)

github-actions avatar github-actions commented on July 3, 2024

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

from azure-sdk-for-net.

trrwilson avatar trrwilson commented on July 3, 2024

Hello, @godefroi! The client configuration pattern is a little different from before; you need to create your ChatClient instance via the method on the AzureOpenAIClient you configured, as described in more detail in the readme:

https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/openai/Azure.AI.OpenAI#authenticate-the-client

Modifying your shared code:

var azureClient = new AzureOpenAIClient(
    _endpointUri,
    _apiKey,
    new AzureOpenAIClientOptions(AzureOpenAIClientOptions.ServiceVersion.V2024_04_01_Preview));

ChatClient client = azureClient.GetChatClient("my-gpt-35-turbo-deployment");

var completion = client.CompleteChat([new UserChatMessage("What model are you?")]);

Could you please try with the above and report back?

from azure-sdk-for-net.

godefroi avatar godefroi commented on July 3, 2024

@trrwilson Shoot, I managed to copy/paste the wrong code. This code:

var client = new AzureOpenAIClient(_endpointUri, _apiKey, new AzureOpenAIClientOptions(AzureOpenAIClientOptions.ServiceVersion.V2024_04_01_Preview));

var chatClient = client.GetChatClient("my-gpt-35-turbo-deployment");

var completion = chatClient.CompleteChat([new UserChatMessage("What model are you?")]);

foreach (var c in completion.Value.Content) {
	Console.WriteLine(c.Text);
}

This code fails with the "400 (Missing Authorization header)" error.

from azure-sdk-for-net.

JadynWong avatar JadynWong commented on July 3, 2024

According to the api description shown in the documentation, AzureML provides an API that is compatible with OpenAI endpoints. It does not seem to be exactly the same as Azure OpenAI, e.g. chat/completions, embeddings, the authentication methods etc. paths.

I think the original OpenAI SDK should be used, not the Azure OpenAI SDK. As you mentioned at the beginning the OpenAI SDK works fine.

However, the documentation does mention compatibility with Azure OpenAI. This may require an explanation from Microsoft.

The API is compatible with Azure OpenAI model deployments.

Azure ML Interface API: https://learn.microsoft.com/en-us/azure/machine-learning/reference-model-inference-api?view=azureml-api-2&tabs=rest

Azure OpenAI REST API: https://learn.microsoft.com/en-us/azure/ai-services/openai/reference

from azure-sdk-for-net.

godefroi avatar godefroi commented on July 3, 2024

The issue isn't with the API, it's with how the SDK configures the ChatClient. The Azure OpenAI SDK is based on the OpenAI SDK, and the OpenAI SDK works. The Azure OpenAI SDK (contained in this project) fails to configure the underlying classes correctly. Thus, this is an issue with the Azure OpenAI SDK.

from azure-sdk-for-net.

trrwilson avatar trrwilson commented on July 3, 2024

Does the non-Azure client (i.e. substituting OpenAIClient for AzureOpenAIClient) properly connect to the endpoint?

OpenAI and Azure OpenAI authenticate differently -- that's one of the primary drivers for the client being needed -- and it sounds like AzureML may be matching OpenAI rather than Azure OpenAI. Specifically, Azure OpenAI uses an api-key header for keys, while OpenAI (and, from that error message, AzureML) use Authorization.

Alternatively -- and although I believe this will work, I haven't confirmed it -- you could use a DelegatedTokenCredential to "spoof" the expected Authorization: bearer header, e.g.:

TokenCredential authorizationCredential = DelegatedTokenCredential.Create(
    (context, cancellationToken) =>
    {
        return new AccessToken(Environment.GetEnvironmentVariable("AZUREML_API_KEY"), DateTime.MaxValue);
    });

AzureOpenAIClient azureClient = new(
    new Uri(Environment.GetEnvironmentVariable("AZUREML_ENDPOINT")),
    authorizationCredential,
    new AzureOpenAIClientOptions(
        AzureOpenAIClientOptions.ServiceVersion.V2024_04_01_Preview));

from azure-sdk-for-net.

godefroi avatar godefroi commented on July 3, 2024

Does the non-Azure client (i.e. substituting OpenAIClient for AzureOpenAIClient) properly connect to the endpoint?

Yes. OpenAIClient works as expected. Your alternate workaround with DelegatedTokenCredential, however, does not. It results in a 405 (Method Not Allowed) response.

from azure-sdk-for-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.