You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/howto-chat-completion-config.md
+18-23Lines changed: 18 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,27 +18,32 @@ Chat completion is an AI capability that enables models to generate conversation
18
18
- An Azure account with an active subscription. [Create one for free](https://azure.microsoft.com/free)
19
19
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
20
20
21
-
> [!NOTE]
22
-
> 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.
23
-
>
24
-
25
21
## Create a chat completion configuration
26
22
27
23
In this section, you will create a chat completion configuration in Azure Portal using the GPT-4o model as an example.
28
24
29
25
1. In Azure portal, navigate to your App configuration store. From the **Operations** menu, select **Configuration explorer** > **Create**. Then select **AI configuration**.
30
26
31
27
1. Specify the following values:
32
-
-**Key**: Type **ChatLLM:Model**.
28
+
-**Key**: Type **ChatApp:Model**.
33
29
-**Label**: Leave this value blank.
34
30
-**Model**: Select **gpt-4o**.
31
+
-**Message**: Add a new message.
32
+
-**Role**: Select **user**
33
+
-**Content**: Type "What is the capial of France?"
35
34
36
35
> [!div class="mx-imgBorder"]
37
36
> 
38
37
39
38
1. Leave the rest of the values as default then select **Apply**.
40
39
41
-
## Create an Azure OpenAI resource
40
+
## Add model connection configuration
41
+
42
+
You've added your chat completion configuration named **ChatApp:Model** in the previous section. In this section, you'll add your model connection details such as the model's API key and endpoint to App configuration. You can store the model API key as a Key Vault reference.
43
+
44
+
> [!NOTE]
45
+
> 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.
46
+
>
42
47
43
48
1. Follow the [Get started with Azure OpenAI Service](/azure/ai-services/openai/overview#get-started-with-azure-openai-service) to create and deploy an Azure OpenAI service resource with following settings:
44
49
@@ -51,22 +56,12 @@ In this section, you will create a chat completion configuration in Azure Portal
51
56
52
57
1. Navigate to your App Configuration store and add the following key-value. Leave **Label** and **Content Type** with their default values. For more information about how to add key-values to a store using the Azure portal or the CLI, go to [Create a key-value](./quickstart-azure-app-configuration-create.md#create-a-key-value).
|_ChatLLM:Endpoint_|_Paste the resource endpoint you copied in the previous step_|
57
-
58
-
1. Continue to the following instructions to implement the chat completion configuration into your application for the language or platform you are using.
|_ChatApp:AzureOpenAI:Endpoint_|_Paste the resource endpoint you copied in the previous step_|
62
+
63
+
1. To store your Azure OpenAI resource API key as a Key Vault reference, refer to [Add a Key Vault reference to App Configuration](./use-key-vault-references-dotnet-core.md#add-a-key-vault-reference-to-app-configuration) guide to add a Key Vault reference with the key _ChatApp:AzureOpenAI:ApiKey_.
61
64
62
-
> [!TIP]
63
-
> To store your Azure OpenAI API key securely, consider storing it as a Key Vault reference.
64
-
> - In your Azure OpenAI resource, from the **Resource Management** menu, select **Keys and Endpoint** and copy your API key.
65
-
> - In your App Configuration store, add a new Key Vault reference with the **Key** set to `ChatLLM:ApiKey` and the **Value** set as a Key Vault reference.
66
-
> - For step-by-step guidance, see [Add a Key Vault reference to App Configuration](./use-key-vault-references-dotnet-core.md#add-a-key-vault-reference-to-app-configuration).
67
-
68
-
69
-
## Next steps
65
+
1. Continue to the following instructions to implement the chat completion configuration into your application for the language or platform you are using.
// Load all keys that start with `ChatLLM:` and have no label.
70
-
.Select("ChatLLM:*")
69
+
// Load all keys that start with `ChatApp:` and have no label.
70
+
.Select("ChatApp:*")
71
71
// Reload configuration if any selected key-values have changed.
72
72
// Use the default refresh interval of 30 seconds. It can be overridden via AzureAppConfigurationRefreshOptions.SetRefreshInterval.
73
73
.ConfigureRefresh(refresh =>
@@ -85,19 +85,19 @@ In this guide, you build an AI chat application and iterate on the prompt using
85
85
86
86
```csharp
87
87
// Initialize the AzureOpenAIClient
88
-
var openAIEndpoint = configuration["ChatLLM:Endpoint"];
88
+
var openAIEndpoint = configuration["ChatApp:AzureOpenAI:Endpoint"];
89
89
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(openAIEndpoint), credential);
90
90
```
91
91
92
92
To access your Azure OpenAI resource with an API key, add the following code:
93
93
94
94
```csharp
95
95
// Initialize the AzureOpenAIClient
96
-
var apiKey = configuration["ChatLLM:ApiKey"];
96
+
var apiKey = configuration["ChatApp:AzureOpenAI:ApiKey"];
97
97
AzureOpenAIClient client = new AzureOpenAIClient(new Uri(openAIEndpoint), new AzureKeyCredential(apiKey));
98
98
```
99
99
100
-
If the key _ChatLLM:ApiKey_ is a Key Vault reference in App Configuration, make sure to add the following code snippet to the `AddAzureAppConfiguration` call and [grant your app access to Key Vault](./use-key-vault-references-dotnet-core.md#grant-your-app-access-to-key-vault).
100
+
If the key _ChatApp:AzureOpenAI:ApiKey_ is a Key Vault reference in App Configuration, make sure to add the following code snippet to the `AddAzureAppConfiguration` call and [grant your app access to Key Vault](./use-key-vault-references-dotnet-core.md#grant-your-app-access-to-key-vault).
101
101
102
102
```cshrap
103
103
options.ConfigureKeyVault(keyVaultOptions =>
@@ -141,41 +141,36 @@ In this guide, you build an AI chat application and iterate on the prompt using
141
141
142
142
```csharp
143
143
...
144
-
var modelConfig = configuration.GetSection("ChatLLM:Model").Get<ModelConfiguration>();
1. In Azure portal, select the App Configuration store instance that you created. From the **Operations** menu, select **Configuration explorer** and select the **ChatLLM:Model** key. Update the value of the Messages property:
379
-
- For the first message:
380
367
- Role: **system**
381
-
- Content: "You are a historian who always speaks with a pirate accent".
382
-
- Add a second message:
383
-
- Role: **user**
384
-
- Content: "Tell me about the Roman empire in 20 words"
368
+
- Content: "You are a cheerful tour guide".
385
369
386
370
1. Press the Enter key to trigger a refresh and you should see the updated value in the Command Prompt or Powershell window:
0 commit comments