Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.35k stars 4.66k forks source link

Azure OpenAI: non-Azure OpenAI API key should be a strongly-typed credential object #35080

Open trrwilson opened 1 year ago

trrwilson commented 1 year ago

PR #35045 added the capability to use Azure.AI.OpenAI's OpenAIClient to connect to the non-Azure OpenAI endpoint using an API key from https://platform.openai.com.

This is currently represented as a plain string, but needs to be updated to a strongly-typed credential object that derives from TokenCredential and mirrors the functionality of AzureKeyCredential.

Additionally, when adding this new type:

annelo-msft commented 6 months ago

@trrwilson, can this be closed now that we have the new ClientModel APIs for this?

jmrtnz94 commented 6 months ago

Dropping this incase anyone else is trying to figure out how to register this with the ClientModel APIs

builder.Services.AddAzureClients(azBuilder =>
{
    azBuilder.AddClient<OpenAIClient, OpenAIClientOptions>(options =>
        new OpenAIClient(builder.Configuration.GetValue<string>("MY_OPEN_AI_KEY"), options));
});