Skip to content

Add a .NET ChatApp example for AI configuration#1055

Merged
zhenlan merged 4 commits intomainfrom
ChatApp
May 21, 2025
Merged

Add a .NET ChatApp example for AI configuration#1055
zhenlan merged 4 commits intomainfrom
ChatApp

Conversation

@zhenlan
Copy link
Copy Markdown
Member

@zhenlan zhenlan commented May 20, 2025

Example output of the ChatApp:

image

@zhenlan zhenlan requested a review from Copilot May 20, 2025 17:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a .NET 8.0 console example illustrating how to load AI model settings from Azure App Configuration, refresh them at runtime, and drive an Azure OpenAI chat loop.

  • Loads ChatLLM settings via Microsoft.Extensions.Configuration.AzureAppConfiguration with auto-refresh.
  • Builds and invokes an Azure OpenAI chat client in a continuous console loop.
  • Introduces ModelConfiguration and Message classes for binding configuration sections.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
examples/DotNetCore/ChatApp/ChatApp/Program.cs Top‐level console app: loads config, refreshes, loops chat interactions
examples/DotNetCore/ChatApp/ChatApp/ModelConfiguration.cs Binds ChatLLM:Model section to a typed configuration object
examples/DotNetCore/ChatApp/ChatApp/Message.cs Defines Message type for config-based chat messages
examples/DotNetCore/ChatApp/ChatApp/ChatApp.csproj New .NET 8.0 project file with required package refs
examples/DotNetCore/ChatApp/ChatApp.sln Solution file including the ChatApp project
Comments suppressed due to low confidence (6)

examples/DotNetCore/ChatApp/ChatApp/Program.cs:38

  • The .NET SDK ships an OpenAIClient class under Azure.AI.OpenAI, not AzureOpenAIClient. Replace AzureOpenAIClient with OpenAIClient to compile against the Azure.AI.OpenAI package.
AzureOpenAIClient azureClient = new(chatEndpoint, credential);

examples/DotNetCore/ChatApp/ChatApp/Program.cs:61

  • There is no CompleteChat method on ChatClient in the Azure.AI.OpenAI SDK. Use the appropriate GetChatCompletions or GetChatCompletionsAsync call for chat completions.
var response = chatClient.CompleteChat(modelConfig.ChatMessages, requestOptions);

examples/DotNetCore/ChatApp/ChatApp/ModelConfiguration.cs:9

  • With Nullable enabled, non-nullable properties must be initialized. Consider adding a default initializer (e.g., = string.Empty;) or use = default!; to suppress warnings.
public string Model { get; set; }

examples/DotNetCore/ChatApp/ChatApp/ModelConfiguration.cs:12

  • Initialize the Messages list by default (e.g., = new List<Message>();) to satisfy non-nullable reference requirements and avoid potential null dereferences.
public List<Message> Messages { get; set; }

examples/DotNetCore/ChatApp/ChatApp/Message.cs:8

  • Add a default initializer (e.g., = string.Empty;) or use = default!; for non-nullable properties under Nullable enable to prevent warnings.
public string Role { get; set; }

examples/DotNetCore/ChatApp/ChatApp/Program.cs:10

  • [nitpick] Using an underscore for a local variable is unconventional; consider renaming to refresher without the underscore to follow standard C# naming conventions.
IConfigurationRefresher _refresher = null;

Comment thread examples/DotNetCore/ChatApp/ChatApp/ModelConfiguration.cs Outdated
Comment thread examples/DotNetCore/ChatApp/ChatApp/Program.cs
Comment thread examples/DotNetCore/ChatApp/ChatApp/Program.cs Outdated
Comment thread examples/DotNetCore/ChatApp/ChatApp/Program.cs Outdated
Comment thread examples/DotNetCore/ChatApp/ChatApp/Program.cs Outdated
@jimmyca15
Copy link
Copy Markdown
Member

So this one went with the approach where the user prompt is part of configuration right?

Comment thread examples/DotNetCore/ChatApp/ChatApp/Program.cs
Comment thread examples/DotNetCore/ChatApp/ChatApp/Program.cs
@zhenlan
Copy link
Copy Markdown
Member Author

zhenlan commented May 21, 2025

So this one went with the approach where the user prompt is part of configuration right?

Yes, the user prompt is also from the configuration. Do you prefer it input at runtime?

Comment thread examples/DotNetCore/ChatApp/ChatApp/Message.cs
@jimmyca15
Copy link
Copy Markdown
Member

So this one went with the approach where the user prompt is part of configuration right?

Yes, the user prompt is also from the configuration. Do you prefer it input at runtime?

No, the way you've done it is actually the way I prefer it.

@zhenlan
Copy link
Copy Markdown
Member Author

zhenlan commented May 21, 2025

@Muksvso, FYI

@zhenlan zhenlan merged commit 8f6b731 into main May 21, 2025
6 checks passed
@zhenlan zhenlan deleted the ChatApp branch May 21, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants