Skip to content

Commit 88b1ee4

Browse files
author
Maryanne Gichohi
committed
Update AI configuration doc
1 parent c668d17 commit 88b1ee4

File tree

4 files changed

+79
-56
lines changed

4 files changed

+79
-56
lines changed

articles/azure-app-configuration/concept-ai-configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Chat completion is an AI capability that produces human-like dialogue responses
4646
| Anthropic | Claude 3.7 Sonnet |
4747
| Google | Gemini 2.5 Pro |
4848
| DeepSeek | DeepSeek-R1 |
49+
| xAI | Grok-3 |
50+
| xAI | Grok-3 Mini |
4951

5052
Azure OpenAI Service supports a diverse set of models from OpenAI. For more information, see [Azure OpenAI Service models](/azure/ai-services/openai/concepts/models). To learn more about models from Anthropic, refer to the [Claude models documentation](https://docs.anthropic.com/docs/about-claude/models/overview).
5153
For more details about models provided by Google, see the [Gemini models documentation](https://ai.google.dev/gemini-api/docs/models).

articles/azure-app-configuration/howto-chat-completion-config.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ In this section, you create a chat completion configuration in Azure portal usin
2626
1. In Azure portal, navigate to your App configuration store. From the **Operations** menu, select **Configuration explorer** > **Create**, and then select **AI configuration**.
2727

2828
1. Specify the following values:
29-
- **Key**: Type **ChatApp:Model**.
29+
- **Key**: Type **ChatApp:ChatCompletion**.
3030
- **Label**: Leave this value blank.
3131
- **Model**: Select **gpt-4o**.
32-
- **Message**: Add a new message.
33-
- **Role**: Select **user**
34-
- **Content**: Type "What is the capital of France?"
3532

3633
> [!div class="mx-imgBorder"]
3734
> ![Screenshot shows the create new AI configuration form.](./media/create-ai-chat-completion-config.png)
@@ -40,7 +37,7 @@ In this section, you create a chat completion configuration in Azure portal usin
4037

4138
## Add model connection configuration
4239

43-
You successfully added your chat completion configuration named **ChatApp:Model** in the previous section. In this section, you add the connection details for your model, including the endpoint and deployment name. If required by your authentication method, you can also specify an API key using a Key Vault reference.
40+
You successfully added your chat completion configuration named **ChatApp:ChatCompletion** in the previous section. In this section, you add the connection details for your model, including the endpoint and deployment name. If required by your authentication method, you can also specify an API key using a Key Vault reference.
4441

4542
> [!NOTE]
4643
> This tutorial demonstrates how to use chat completion configuration with an Azure OpenAI model. However, the chat completion configuration demonstrated in the tutorial can be applied to any AI model you choose to work with in your application.
577 Bytes
Loading

articles/azure-app-configuration/quickstart-chat-completion-dotnet.md

Lines changed: 75 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ In this guide, you build an AI chat application and iterate on the prompt using
112112
});
113113
```
114114
115-
1. Define the `ModelConfiguration` class in _Program.cs_ file:
115+
1. Define the `ChatCompletionConfiguration` class in _Program.cs_ file:
116116
117117
```csharp
118-
internal class ModelConfiguration
118+
internal class ChatCompletionConfiguration
119119
{
120120
[ConfigurationKeyName("model")]
121121
public string? Model { get; set; }
@@ -146,10 +146,10 @@ In this guide, you build an AI chat application and iterate on the prompt using
146146
1. Update the _Program.cs_ file to add a helper method `GetChatMessages` to process chat messages:
147147
148148
```csharp
149-
// Helper method to convert configuration messages to chat API format
150-
static IEnumerable<ChatMessage> GetChatMessages(ModelConfiguration modelConfiguration)
149+
// Helper method to convert configuration messages to ChatMessage objects
150+
static IEnumerable<ChatMessage> GetChatMessages(ChatCompletionConfiguration chatCompletionConfiguration)
151151
{
152-
return modelConfiguration.Messages.Select<Message, ChatMessage>(message => message.Role switch
152+
return chatCompletionConfiguration.Messages.Select<Message, ChatMessage>(message => message.Role switch
153153
{
154154
"system" => ChatMessage.CreateSystemMessage(message.Content),
155155
"user" => ChatMessage.CreateUserMessage(message.Content),
@@ -164,29 +164,44 @@ In this guide, you build an AI chat application and iterate on the prompt using
164164
```csharp
165165
while (true)
166166
{
167+
// Get user input
168+
Console.Write("You: ");
169+
string? userInput = Console.ReadLine();
170+
171+
// Exit if user input is empty
172+
if (string.IsNullOrEmpty(userInput))
173+
{
174+
Console.WriteLine("Exiting chat. Goodbye!");
175+
break;
176+
}
177+
167178
// Refresh the configuration from Azure App Configuration
168179
await refresher.RefreshAsync();
169180
170181
// Configure chat completion with AI configuration
171-
var modelConfiguration = configuration.GetSection("ChatApp:Model").Get<ModelConfiguration>();
182+
var chatCompletionConfiguration = configuration.GetSection("ChatApp:ChatCompletion").Get<ChatCompletionConfiguration>();
183+
172184
var requestOptions = new ChatCompletionOptions()
173185
{
174-
MaxOutputTokenCount = modelConfiguration.MaxTokens,
175-
Temperature = modelConfiguration.Temperature,
176-
TopP = modelConfiguration.TopP
186+
MaxOutputTokenCount = chatCompletionConfiguration.MaxTokens,
187+
Temperature = chatCompletionConfiguration.Temperature,
188+
TopP = chatCompletionConfiguration.TopP
177189
};
178190
179-
foreach (var message in modelConfiguration.Messages)
180-
{
181-
Console.WriteLine($"{message.Role}: {message.Content}");
182-
}
191+
chatConversation.Add(ChatMessage.CreateUserMessage(userInput));
183192
184-
// Get chat response from AI
185-
var response = await chatClient.CompleteChatAsync(GetChatMessages(modelConfiguration), requestOptions);
186-
Console.WriteLine($"AI response: {response.Value.Content[0].Text}");
193+
// Get latest system message from AI configuration
194+
var chatMessages = new List<ChatMessage>(GetChatMessages(chatCompletionConfiguration));
195+
chatMessages.AddRange(chatConversation);
187196
188-
Console.WriteLine("Press Enter to continue...");
189-
Console.ReadLine();
197+
// Get AI response and add it to chat conversation
198+
var response = await chatClient.CompleteChatAsync(chatMessages, requestOptions);
199+
string aiResponse = response.Value.Content[0].Text;
200+
201+
Console.WriteLine($"AI: {aiResponse}");
202+
chatConversation.Add(ChatMessage.CreateAssistantMessage(aiResponse));
203+
204+
Console.WriteLine();
190205
}
191206
```
192207
@@ -231,37 +246,55 @@ In this guide, you build an AI chat application and iterate on the prompt using
231246
AzureOpenAIClient azureClient = new(openaiEndpoint, credential);
232247
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
233248
249+
// Initialize chat conversation
250+
var chatConversation = new List<ChatMessage>();
251+
Console.WriteLine("Chat started! What's on your mind?");
252+
234253
while (true)
235254
{
255+
// Get user input
256+
Console.Write("You: ");
257+
string? userInput = Console.ReadLine();
258+
259+
// Exit if user input is empty
260+
if (string.IsNullOrEmpty(userInput))
261+
{
262+
Console.WriteLine("Exiting chat. Goodbye!");
263+
break;
264+
}
265+
236266
// Refresh the configuration from Azure App Configuration
237267
await refresher.RefreshAsync();
238268
239269
// Configure chat completion with AI configuration
240-
var modelConfiguration = configuration.GetSection("ChatApp:Model").Get<ModelConfiguration>();
270+
var chatCompletionConfiguration = configuration.GetSection("ChatApp:ChatCompletion").Get<ChatCompletionConfiguration>();
241271
var requestOptions = new ChatCompletionOptions()
242272
{
243-
MaxOutputTokenCount = modelConfiguration.MaxTokens,
244-
Temperature = modelConfiguration.Temperature,
245-
TopP = modelConfiguration.TopP
273+
MaxOutputTokenCount = chatCompletionConfiguration.MaxTokens,
274+
Temperature = chatCompletionConfiguration.Temperature,
275+
TopP = chatCompletionConfiguration.TopP
246276
};
247277
248-
foreach (var message in modelConfiguration.Messages)
249-
{
250-
Console.WriteLine($"{message.Role}: {message.Content}");
251-
}
278+
chatConversation.Add(ChatMessage.CreateUserMessage(userInput));
252279
253-
// Get chat response from AI
254-
var response = await chatClient.CompleteChatAsync(GetChatMessages(modelConfiguration), requestOptions);
255-
Console.WriteLine($"AI response: {response.Value.Content[0].Text}");
280+
// Get latest system message from AI configuration
281+
var chatMessages = new List<ChatMessage>(GetChatMessages(chatCompletionConfiguration));
282+
chatMessages.AddRange(chatConversation);
256283
257-
Console.WriteLine("Press Enter to continue...");
258-
Console.ReadLine();
259-
284+
// Get AI response and add it to chat conversation
285+
var response = await chatClient.CompleteChatAsync(chatMessages, requestOptions);
286+
string aiResponse = response.Value.Content[0].Text;
287+
288+
Console.WriteLine($"AI: {aiResponse}");
289+
chatConversation.Add(ChatMessage.CreateAssistantMessage(aiResponse));
290+
291+
Console.WriteLine();
260292
}
261293
262-
static IEnumerable<ChatMessage> GetChatMessages(ModelConfiguration modelConfiguration)
294+
// Helper method to convert configuration messages to ChatMessage objects
295+
static IEnumerable<ChatMessage> GetChatMessages(ChatCompletionConfiguration chatCompletionConfiguration)
263296
{
264-
return modelConfiguration.Messages.Select<Message, ChatMessage>(message => message.Role switch
297+
return chatCompletionConfiguration.Messages.Select<Message, ChatMessage>(message => message.Role switch
265298
{
266299
"system" => ChatMessage.CreateSystemMessage(message.Content),
267300
"user" => ChatMessage.CreateUserMessage(message.Content),
@@ -270,7 +303,7 @@ In this guide, you build an AI chat application and iterate on the prompt using
270303
});
271304
}
272305
273-
internal class ModelConfiguration
306+
internal class ChatCompletionConfiguration
274307
{
275308
[ConfigurationKeyName("model")]
276309
public string? Model { get; set; }
@@ -326,26 +359,17 @@ In this guide, you build an AI chat application and iterate on the prompt using
326359
You should see the following output:
327360
328361
```Output
329-
system: You are a helpful assistant.
330-
user: What is the capital of France ?
331-
AI response: The capital of France is **Paris**.
332-
Press Enter to continue...
333-
362+
Chat started! What's on your mind?
334363
```
335364
336-
1. In Azure portal, select the App Configuration store instance that you created. From the **Operations** menu, select **Configuration explorer** and select the **ChatApp:Model** key. Update the value of the Messages property:
365+
1. In Azure portal, select the App Configuration store instance that you created. From the **Operations** menu, select **Configuration explorer** and select the **ChatApp:ChatCompletion** key. Update the value of the Messages property:
337366
- Role: **system**
338-
- Content: "You are a cheerful tour guide".
367+
- Content: "You are a pirate and your name is Eddy."
339368
340-
1. Wait a few moments for the refresh interval to elapse, and then press the Enter key to see the updated AI response in the output.
369+
1. Type your message when prompted with "You:". Be sure to wait a few moments for the refresh interval to elapse, and then press the Enter key to see the updated AI response in the output
341370
342371
```Output
343-
system: You are a cheerful tour guide
344-
user: What is the capital of France ?
345-
AI response: Oh là là! The capital of France is the magnificent **Paris**!
346-
Known as the "City of Light" (*La Ville Lumière*), it's famous for its romantic ambiance,
347-
iconic landmarks like the Eiffel Tower, the Louvre Museum, and Notre-Dame Cathedral,
348-
as well as its delicious pastries and charming cafés.
349-
Have you ever been, or is it on your travel bucket list? 😊✨
350-
Press Enter to continue...
372+
Chat started! What's on your mind?
373+
You: Hello, what is your name ?
374+
AI: Ahoy, matey! Me name be Captain Eddy, the most fearsome pirate to ever sail the seven seas! What be yer name, landlubber?
351375
```

0 commit comments

Comments
 (0)