-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net: HomeAutomation AzureOpenAI Configuration Fix #10054
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the SectionName property/field was missing in the AzureOpenAIOptions and OpenAIOptions classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the field in line with another demo project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanaka-takayoshi Consider changing the Program.cs
to something like this.
Adding the namespaces and UserSecrets support and making it AzureOpenAI friendly right out of the bat.
Namespaces
// For Azure OpenAI configuration
#pragma warning disable IDE0005 // Using directive is unnecessary.
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using Microsoft.SemanticKernel.Connectors.OpenAI;
Main (Loading both OpenAI and AzureOpenAI (commented) options)
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Configuration.AddUserSecrets<Worker>();
// Actual code to execute is found in Worker class
builder.Services.AddHostedService<Worker>();
// Get configuration
builder.Services.AddOptions<OpenAIOptions>()
.Bind(builder.Configuration.GetSection(OpenAIOptions.SectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
/* Alternatively, you can use plain, Azure OpenAI after loading AzureOpenAIOptions instead of OpenAI
builder.Services.AddOptions<AzureOpenAIOptions>()
.Bind(builder.Configuration.GetSection(AzureOpenAIOptions.SectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
*/
// Chat completion service that kernels will use
builder.Services.AddSingleton<IChatCompletionService>(sp =>
{
OpenAIOptions openAIOptions = sp.GetRequiredService<IOptions<OpenAIOptions>>().Value;
// A custom HttpClient can be provided to this constructor
return new OpenAIChatCompletionService(openAIOptions.ChatModelId, openAIOptions.ApiKey);
/* Alternatively, you can use plain, Azure OpenAI after loading AzureOpenAIOptions instead of OpenAI
AzureOpenAIOptions azureOpenAIOptions = sp.GetRequiredService<IOptions<AzureOpenAIOptions>>().Value;
return new AzureOpenAIChatCompletionService(azureOpenAIOptions.ChatDeploymentName, azureOpenAIOptions.Endpoint, azureOpenAIOptions.ApiKey);
*/
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget also to change the dependency in the HomeAutomation.csproj
from OpenAI to AzureOpenAI csproj.
- <ProjectReference Include="..\..\..\src\Connectors\Connectors.OpenAI\Connectors.OpenAI.csproj" />
+ <ProjectReference Include="..\..\..\src\Connectors\Connectors.AzureOpenAI\Connectors.AzureOpenAI.csproj" />
Fixed the secret section name.
f903dfe
to
76e2ccb
Compare
Fixed the secret section name.
Motivation and Context
Fixing #10049
Description
Fix the secret section name to
AzureOpenAI
, described in README.Contribution Checklist