-
Notifications
You must be signed in to change notification settings - Fork 80
Update the .NET ChatApp sample #1075
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
examples/DotNetCore/ChatApp/ChatApp/AzureOpenAIConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT license. | ||
| // | ||
|
|
||
| namespace ChatApp | ||
| { | ||
| internal class AzureOpenAIConfiguration | ||
| { | ||
| public required string Endpoint { get; set; } | ||
|
|
||
| public required string DeploymentName { get; set; } | ||
|
|
||
| public string? ApiKey { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # Azure App Configuration - .NET ChatApp Sample | ||
|
|
||
| An interactive console chat application that integrates with Azure OpenAI services using Azure App Configuration for dynamic AI Configuration management. | ||
|
|
||
| ## Overview | ||
|
|
||
| This .NET console application provides a seamless chat experience with Azure OpenAI, featuring: | ||
|
|
||
| - Integration with Azure OpenAI for chat completions | ||
| - Dynamic AI configuration refresh from Azure App Configuration | ||
| - Secure authentication options using API key or Microsoft Entra ID | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - .NET 8.0 SDK | ||
| - Azure subscription | ||
| - Azure OpenAI service instance | ||
| - Azure App Configuration service instance | ||
|
|
||
| ## Setup | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| Set the following environment variable: | ||
|
|
||
| - `AZURE_APPCONFIGURATION_ENDPOINT`: Endpoint URL of your Azure App Configuration instance | ||
|
|
||
| ### Azure App Configuration Keys | ||
|
|
||
| Configure the following keys in your Azure App Configuration: | ||
|
|
||
| #### Azure OpenAI Connection Settings | ||
|
|
||
| - `ChatApp:AzureOpenAI:Endpoint` - Your Azure OpenAI endpoint URL | ||
| - `ChatApp:AzureOpenAI:DeploymentName` - Your Azure OpenAI deployment name | ||
| - `ChatApp:AzureOpenAI:ApiKey` - Key Vault reference to the API key for Azure OpenAI (optional) | ||
|
|
||
| #### Chat Completion Configuration | ||
|
|
||
| - `ChatApp:ChatCompletion` - An AI Configuration for chat completion containing the following settings: | ||
| - `model` - Model name (e.g., "gpt-4o") | ||
| - `max_tokens` - Maximum tokens for completion (e.g., 1000) | ||
| - `temperature` - Temperature parameter (e.g., 0.7) | ||
| - `top_p` - Top p parameter (e.g., 0.95) | ||
| - `messages` - An array of messages with role and content for each message | ||
|
|
||
| ## Authentication | ||
|
|
||
| The application supports the following authentication methods: | ||
|
|
||
| - **Azure App Configuration**: Uses `DefaultAzureCredential` for authentication via Microsoft Entra ID. | ||
| - **Azure OpenAI**: Supports authentication using either an API key or `DefaultAzureCredential` via Microsoft Entra ID. | ||
| - **Azure Key Vault** *(optional, if using Key Vault references for API keys)*: Authenticates using `DefaultAzureCredential` via Microsoft Entra ID. | ||
|
|
||
| ## Usage | ||
|
|
||
| 1. **Start the Application**: Run the application using `dotnet run` | ||
| 2. **Begin Chatting**: Type your messages when prompted with "You: " | ||
| 3. **Continue Conversation**: The AI will respond and maintain conversation context | ||
| 4. **Exit**: Press Enter without typing a message to exit gracefully | ||
|
|
||
| ### Example Session | ||
| ``` | ||
| Chat started! What's on your mind? | ||
| You: Hello, how are you? | ||
| AI: Hello! I'm doing well, thank you for asking. How can I help you today? | ||
|
|
||
| You: What can you tell me about machine learning? | ||
| AI: Machine learning is a subset of artificial intelligence that focuses on... | ||
|
|
||
| You: [Press Enter to exit] | ||
| Exiting chat. Goodbye! | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **"AZURE_APPCONFIGURATION_ENDPOINT environment variable not set"** | ||
| - Ensure the environment variable is properly set | ||
| - Verify the endpoint URL is correct | ||
|
|
||
| **Authentication Failures** | ||
| - Ensure you have the `App Configuration Data Reader` role on the Azure App Configuration instance | ||
| - For Microsoft Entra ID authentication: Verify you have the `Cognitive Services OpenAI User` role on the Azure OpenAI instance | ||
| - For API key authentication: | ||
| - Confirm you have secret read access to the Key Vault storing the API key | ||
| - Verify that a Key Vault reference for the API key is properly configured in Azure App Configuration | ||
|
|
||
| **No AI Response** | ||
| - Verify deployment name matches your Azure OpenAI deployment | ||
| - Check token limits and quotas |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.