Skip to content

Commit 1552868

Browse files
author
unknown
committed
Fix indentation
1 parent cb57d37 commit 1552868

File tree

3 files changed

+110
-106
lines changed

3 files changed

+110
-106
lines changed

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

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ In this quickstart you will create a .NET console app that retrieves chat comple
1919

2020
## Prerequisites
2121

22-
- Complete the tutorial to [Create a chat completion configuration](./howto-chat-completion-config#create-a-chat-completion-configuration).
22+
- Complete the tutorial to [Create a chat completion configuration](./howto-chat-completion-config.md#create-a-chat-completion-configuration).
2323
- [.NET SDK 6.0 or later](https://dotnet.microsoft.com/download)
2424

2525
## Create a console app
@@ -58,160 +58,159 @@ In this quickstart you will create a .NET console app that retrieves chat comple
5858
1. Open the _Program.cs_, and add the following namespaces at the top of the file:
5959

6060
```csharp
61-
using Microsoft.Extensions.Configuration;
62-
using Azure.Identity;
63-
using Azure.AI.OpenAI;
64-
using OpenAI.Chat;
61+
using Microsoft.Extensions.Configuration;
62+
using Azure.Identity;
63+
using Azure.AI.OpenAI;
64+
using OpenAI.Chat;
6565
```
6666

6767
1. Connect to your App Configuration store by calling the `AddAzureAppConfiguration` method in the _Program.cs_ file.
6868

6969
You can connect to App Configuration using **Microsoft Entra ID (recommended)**, or a connection string. In this example, you use Microsoft Entra ID, the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
7070

7171
```csharp
72-
var credential = new DefaultAzureCredential();
72+
var credential = new DefaultAzureCredential();
7373

74-
IConfiguration configuration = new ConfigurationBuilder()
75-
.AddAzureAppConfiguration(options =>
76-
{
77-
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIG_ENDPOINT");
74+
IConfiguration configuration = new ConfigurationBuilder()
75+
.AddAzureAppConfiguration(options =>
76+
{
77+
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIG_ENDPOINT");
7878

79-
options.Connect(new Uri(endpoint), credential);
80-
}).Build();
79+
options.Connect(new Uri(endpoint), credential);
80+
}).Build();
8181

82-
var model = configuration.GetSection("ChatLLM:Model")["model"];
83-
string modelEndpoint = configuration.GetSection("ChatLLM:Endpoint").Value;
82+
var model = configuration.GetSection("ChatLLM:Model")["model"];
83+
string modelEndpoint = configuration.GetSection("ChatLLM:Endpoint").Value;
8484

85-
Console.WriteLine($"Hello, I am your AI assistant powered by Azure App Configuration ({model})");
85+
Console.WriteLine($"Hello, I am your AI assistant powered by Azure App Configuration ({model})");
8686
```
8787

8888
1. Create an instance of the `AzureOpenAIClient`. Use the existing instance of `DefaultAzureCredential` we created in the previous step to authenticate to your Azure OpenAI resource. Assign your credential the [Cognitive Services OpenAI User](../role-based-access-control/built-in-roles/ai-machine-learning.md#cognitive-services-openai-user) or [Cognitive Services OpenAI Contributor](../role-based-access-control/built-in-roles/ai-machine-learning.md#cognitive-services-openai-contributor). For detailed steps, see [Role-based access control for Azure OpenAI service](/azure/ai-services/openai/how-to/role-based-access-control). Be sure to allow sufficient time for the permission to propagate before running your application.
8989

9090
```csharp
91-
// Existing code to connect to your App configuration store
92-
// ...
91+
// Existing code to connect to your App configuration store
92+
// ...
9393

94-
// Initialize the AzureOpenAIClient
95-
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(modelEndpoint), credential);
96-
ChatClient chatClient = client.GetChatClient(model);
94+
// Initialize the AzureOpenAIClient
95+
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(modelEndpoint), credential);
96+
ChatClient chatClient = client.GetChatClient(model);
9797

9898
```
9999

100100
1. Next will update the existing code in _Program.cs_ file to configure the chat completion options:
101101
```csharp
102-
...
103-
// Existing code to initialize the AzureOpenAIClient
104-
105-
// Configure chat completion options
106-
ChatCompletionOptions options = new ChatCompletionOptions
107-
{
108-
Temperature = float.Parse(configuration.GetSection("ChatLLM:Model")["temperature"]),
109-
MaxOutputTokenCount = int.Parse(configuration.GetSection("ChatLLM:Model")["max_tokens"]),
110-
TopP = float.Parse(configuration.GetSection("ChatLLM:Model")["top_p"])
111-
};
112-
102+
...
103+
// Existing code to initialize the AzureOpenAIClient
104+
105+
// Configure chat completion options
106+
ChatCompletionOptions options = new ChatCompletionOptions
107+
{
108+
Temperature = float.Parse(configuration.GetSection("ChatLLM:Model")["temperature"]),
109+
MaxOutputTokenCount = int.Parse(configuration.GetSection("ChatLLM:Model")["max_tokens"]),
110+
TopP = float.Parse(configuration.GetSection("ChatLLM:Model")["top_p"])
111+
};
113112
```
114113

115114
1. Update the _Program.cs_ file to add a helper method `GetChatMessages` to process chat messages:
116115
```csharp
117-
// Helper method to convert configuration messages to chat API format
118-
IEnumerable<ChatMessage> GetChatMessages()
119-
{
120-
var chatMessages = new List<ChatMessage>();
116+
// Helper method to convert configuration messages to chat API format
117+
IEnumerable<ChatMessage> GetChatMessages()
118+
{
119+
var chatMessages = new List<ChatMessage>();
121120

122-
foreach (IConfiguration configuration in configuration.GetSection("ChatLLM:Model:messages").GetChildren())
121+
foreach (IConfiguration configuration in configuration.GetSection("ChatLLM:Model:messages").GetChildren())
122+
{
123+
switch (configuration["role"])
123124
{
124-
switch (configuration["role"])
125-
{
126-
case "system":
127-
chatMessages.Add(ChatMessage.CreateSystemMessage(configuration["content"]));
128-
break;
129-
case "user":
130-
chatMessages.Add(ChatMessage.CreateUserMessage(configuration["content"]));
131-
break;
132-
}
125+
case "system":
126+
chatMessages.Add(ChatMessage.CreateSystemMessage(configuration["content"]));
127+
break;
128+
case "user":
129+
chatMessages.Add(ChatMessage.CreateUserMessage(configuration["content"]));
130+
break;
133131
}
134-
return chatMessages;
135132
}
133+
return chatMessages;
134+
}
136135
```
137136

138137
1. Update the code in the _Program.cs_ file to call the helper method `GetChatMessages` and pass the ChatMessages to the `CompleteChatAsync` method:
139138
```csharp
140-
...
141-
// Existing code to configure chat completion options
142-
//
143-
IEnumerable<ChatMessage> messages = GetChatMessages();
144-
145-
// CompleteChatAsync method generates a completion for the given chat
146-
ChatCompletion completion = await chatClient.CompleteChatAsync(messages, options);
147-
148-
Console.WriteLine("-------------------Model response--------------------------");
149-
Console.WriteLine(completion.Content[0].Text);
150-
Console.WriteLine("-----------------------------------------------------------");
151-
...
139+
...
140+
// Existing code to configure chat completion options
141+
//
142+
IEnumerable<ChatMessage> messages = GetChatMessages();
143+
144+
// CompleteChatAsync method generates a completion for the given chat
145+
ChatCompletion completion = await chatClient.CompleteChatAsync(messages, options);
146+
147+
Console.WriteLine("-------------------Model response--------------------------");
148+
Console.WriteLine(completion.Content[0].Text);
149+
Console.WriteLine("-----------------------------------------------------------");
150+
...
152151
```
153152

154153
1. After completing the previous steps, your _Program.cs_ file should now contain the complete implementation as shown below:
155154
```c#
156-
using Microsoft.Extensions.Configuration;
157-
using Azure.Identity;
158-
using Azure.AI.OpenAI;
159-
using OpenAI.Chat;
155+
using Microsoft.Extensions.Configuration;
156+
using Azure.Identity;
157+
using Azure.AI.OpenAI;
158+
using OpenAI.Chat;
160159

161-
var credential = new DefaultAzureCredential();
160+
var credential = new DefaultAzureCredential();
162161

163-
IConfiguration configuration = new ConfigurationBuilder()
164-
.AddAzureAppConfiguration(options =>
165-
{
166-
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIG_ENDPOINT");
162+
IConfiguration configuration = new ConfigurationBuilder()
163+
.AddAzureAppConfiguration(options =>
164+
{
165+
string endpoint = Environment.GetEnvironmentVariable("AZURE_APPCONFIG_ENDPOINT");
167166

168-
options.Connect(new Uri(endpoint), credential);
167+
options.Connect(new Uri(endpoint), credential);
169168

170-
}).Build();
169+
}).Build();
171170

172-
var model = configuration.GetSection("ChatLLM:Model")["model"];
173-
string modelEndpoint = configuration.GetSection("ChatLLM:Endpoint").Value;
171+
var model = configuration.GetSection("ChatLLM:Model")["model"];
172+
string modelEndpoint = configuration.GetSection("ChatLLM:Endpoint").Value;
174173

175-
// Initialize the AzureOpenAIClient
176-
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(modelEndpoint), credential);
177-
ChatClient chatClient = client.GetChatClient(model);
174+
// Initialize the AzureOpenAIClient
175+
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(modelEndpoint), credential);
176+
ChatClient chatClient = client.GetChatClient(model);
178177

179-
// Configure chat completion options
180-
ChatCompletionOptions options = new ChatCompletionOptions
181-
{
182-
Temperature = float.Parse(configuration.GetSection("ChatLLM:Model")["temperature"]),
183-
MaxOutputTokenCount = int.Parse(configuration.GetSection("ChatLLM:Model")["max_tokens"]),
184-
TopP = float.Parse(configuration.GetSection("ChatLLM:Model")["top_p"])
185-
};
186-
187-
IEnumerable<ChatMessage> messages = GetChatMessages();
178+
// Configure chat completion options
179+
ChatCompletionOptions options = new ChatCompletionOptions
180+
{
181+
Temperature = float.Parse(configuration.GetSection("ChatLLM:Model")["temperature"]),
182+
MaxOutputTokenCount = int.Parse(configuration.GetSection("ChatLLM:Model")["max_tokens"]),
183+
TopP = float.Parse(configuration.GetSection("ChatLLM:Model")["top_p"])
184+
};
185+
186+
IEnumerable<ChatMessage> messages = GetChatMessages();
188187

189-
ChatCompletion completion = await chatClient.CompleteChatAsync(messages, options);
190-
Console.WriteLine($"Hello, I am your AI assistant powered by Azure App Configuration ({model})");
188+
ChatCompletion completion = await chatClient.CompleteChatAsync(messages, options);
189+
Console.WriteLine($"Hello, I am your AI assistant powered by Azure App Configuration ({model})");
191190

192-
Console.WriteLine("-------------------Model response--------------------------");
193-
Console.WriteLine(completion.Content[0].Text);
194-
Console.WriteLine("-----------------------------------------------------------");
191+
Console.WriteLine("-------------------Model response--------------------------");
192+
Console.WriteLine(completion.Content[0].Text);
193+
Console.WriteLine("-----------------------------------------------------------");
195194

196-
IEnumerable<ChatMessage> GetChatMessages()
197-
{
198-
var chatMessages = new List<ChatMessage>();
195+
IEnumerable<ChatMessage> GetChatMessages()
196+
{
197+
var chatMessages = new List<ChatMessage>();
199198

200-
foreach (IConfiguration configuration in configuration.GetSection("ChatLLM:Model:messages").GetChildren())
199+
foreach (IConfiguration configuration in configuration.GetSection("ChatLLM:Model:messages").GetChildren())
200+
{
201+
switch (configuration["role"])
201202
{
202-
switch (configuration["role"])
203-
{
204-
case "system":
205-
chatMessages.Add(ChatMessage.CreateSystemMessage(configuration["content"]));
206-
break;
207-
case "user":
208-
chatMessages.Add(ChatMessage.CreateUserMessage(configuration["content"]));
209-
break;
210-
}
203+
case "system":
204+
chatMessages.Add(ChatMessage.CreateSystemMessage(configuration["content"]));
205+
break;
206+
case "user":
207+
chatMessages.Add(ChatMessage.CreateUserMessage(configuration["content"]));
208+
break;
211209
}
212-
213-
return chatMessages;
214210
}
211+
212+
return chatMessages;
213+
}
215214
```
216215

217216
## Build and run the app locally
@@ -244,6 +243,7 @@ In this quickstart you will create a .NET console app that retrieves chat comple
244243

245244
```Output
246245
Hello, I am your AI assistant powered by Azure App Configuration (gpt-4o)
246+
247247
-------------------Model response--------------------------
248248
Good heavens! A pocket-sized contraption combining telegraph, camera, library, and more—instant communication and knowledge at one’s fingertips! Astonishing!
249249
-----------------------------------------------------------

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ In this quickstart you will create a Node js console app that retrieves chat com
1919

2020
## Prerequisites
2121

22-
- Complete the tutorial to [Create a chat completion configuration](./howto-chat-completion-config#create-a-chat-completion-configuration).
22+
- Complete the tutorial to [Create a chat completion configuration](./howto-chat-completion-config.md#create-a-chat-completion-configuration).
2323
- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule). For information about installing Node.js either directly on Windows or using the Windows Subsystem for Linux (WSL), see [Get started with Node.js](/windows/dev-environment/javascript/nodejs-overview)
2424

2525

@@ -46,6 +46,7 @@ In this quickstart you will create a Node js console app that retrieves chat com
4646
```
4747

4848
1. Create a file named app.js in the *app-config-chat-completion* directory and import the required packages:
49+
4950
```javascript
5051
const { load } = require("@azure/app-configuration-provider");
5152
const { DefaultAzureCredential, getBearerTokenProvider } = require("@azure/identity");
@@ -99,6 +100,7 @@ In this quickstart you will create a Node js console app that retrieves chat com
99100
```
100101

101102
1. Next will update the existing code in _app.js_ file to configure the chat completion options:
103+
102104
```javascript
103105
// Existing code to initialize the AzureOpenAIClient
104106
const client = new AzureOpenAI({
@@ -191,14 +193,15 @@ In this quickstart you will create a Node js console app that retrieves chat com
191193
```
192194
193195
1. After the environment variable is properly set, run the following command to run the app locally:
194-
``` bash
196+
```bash
195197
node app.js
196198
```
197199

198200
You should see the following output:
199201

200202
```Output
201203
Hello, I am your AI assistant powered by Azure App Configuration (gpt-4o)
204+
202205
-------------------Model response--------------------------
203206
Good heavens! A pocket-sized contraption combining telegraph, camera, library, and more—instant communication and knowledge at one’s fingertips! Astonishing!
204207
-----------------------------------------------------------

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ In this quickstart you will create a python app that retrieves chat completion c
1919

2020
## Prerequisites
2121

22-
- Complete the tutorial to [Create a chat completion configuration](./howto-chat-completion-config#create-a-chat-completion-configuration).
22+
- Complete the tutorial to [Create a chat completion configuration](./howto-chat-completion-config.md#create-a-chat-completion-configuration).
2323
- Python 3.8 or later - for information on setting up Python on Windows, see the [Python on Windows documentation](/windows/python/)
2424

2525
## Create a python app
@@ -205,6 +205,7 @@ In this quickstart you will create a python app that retrieves chat completion c
205205

206206
```Output
207207
Hello, I am your AI assistant powered by Azure App Configuration (gpt-4o)
208+
208209
-------------------Model response--------------------------
209210
Good heavens! A pocket-sized contraption combining telegraph, camera, library, and more—instant communication and knowledge at one’s fingertips! Astonishing!
210211
-----------------------------------------------------------

0 commit comments

Comments
 (0)