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
In this quickstart, you create an MSTest app to evaluate the chat response of an OpenAI model. The test app uses the [Microsoft.Extensions.AI.Evaluation](https://www.nuget.org/packages/Microsoft.Extensions.AI.Evaluation) libraries.
12
12
13
13
> [!NOTE]
14
-
> This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)
14
+
>
15
+
> - The `Microsoft.Extensions.AI.Evaluation` library is currently in Preview.
16
+
> - This quickstart demonstrates the simplest usage of the evaluation API. Notably, it doesn't demonstrate use of the [response caching](../conceptual/evaluation-libraries.md#cached-responses) and [reporting](../conceptual/evaluation-libraries.md#reporting) functionality, which are important if you're authoring unit tests that run as part of an "offline" evaluation pipeline. The scenario shown in this quickstart is suitable in use cases such as "online" evaluation of AI responses within production code and logging scores to telemetry, where caching and reporting aren't relevant. For a tutorial that demonstrates the caching and reporting functionality, see [Tutorial: Evaluate a model's response with response caching and reporting](../tutorials/evaluate-with-reporting.md)
Copy file name to clipboardExpand all lines: docs/ai/quickstarts/includes/clone-sample-repo.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.date: 07/03/2024
5
5
ms.topic: include
6
6
---
7
7
8
-
## Clone the sample repository
8
+
## (Optional) Clone the sample repository
9
9
10
10
You can create your own app using the steps in the sections ahead, or you can clone the GitHub repository that contains the completed sample apps for all of the quickstarts. If you plan to use Azure OpenAI, the sample repo is also structured as an Azure Developer CLI template that can provision an Azure OpenAI resource for you.
1. To provision an Azure OpenAI service and model using the Azure CLI, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=cli) article.
5
+
1. To provision an Azure OpenAI service and model, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource) article.
10
6
11
7
1. From a terminal or command prompt, navigate to the root of your project directory.
12
8
@@ -18,18 +14,8 @@
18
14
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
19
15
```
20
16
21
-
# [Azure Portal](#tab/azure-portal)
22
-
23
-
1. To provision an Azure OpenAI service and model using the Azure portal, complete the steps in the [Create and deploy an Azure OpenAI Service resource](/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) article.
24
-
25
-
1. From a terminal or command prompt, navigate to the root of your project directory.
26
-
27
-
1. Run the following commands to configure your Azure OpenAI endpoint and model name for the sample app:
17
+
# [Azure Developer CLI](#tab/azd)
28
18
29
-
```bash
30
-
dotnet user-secrets init
31
-
dotnet user-secrets set AZURE_OPENAI_ENDPOINT <your-openai-key>
32
-
dotnet user-secrets set AZURE_OPENAI_GPT_NAME <your-azure-openai-model-name>
# CustomerIntent: As a .NET developer new to OpenAI, I want deploy and use sample code to interact to learn from the sample code to summarize text.
11
11
---
12
12
13
-
# Connect to and prompt an AI model using .NET
13
+
# Connect to and prompt an AI model
14
14
15
15
In this quickstart, you learn how to create a .NET console chat app to connect to and prompt an OpenAI or Azure OpenAI model. The app uses the <xref:Microsoft.Extensions.AI> library so you can write code using AI abstractions rather than a specific SDK. AI abstractions enable you to change the underlying AI model with minimal code changes.
16
16
17
17
> [!NOTE]
18
-
> The [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) library is currently in Preview.
18
+
> The <xref:Microsoft.Extensions.AI> library is currently in Preview.
19
19
20
20
:::zone target="docs" pivot="openai"
21
21
@@ -54,9 +54,9 @@ Complete the following steps to create a .NET console app to connect to an AI mo
1. Open the app in Visual Studio code or your editor of choice
78
-
79
-
```bash
80
-
code .
81
-
```
77
+
1. Open the app in Visual Studio Code or your editor of choice.
82
78
83
79
:::zone target="docs" pivot="azure-openai"
84
80
@@ -94,50 +90,52 @@ Complete the following steps to create a .NET console app to connect to an AI mo
94
90
95
91
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
96
92
97
-
```bash
98
-
dotnet user-secrets init
99
-
dotnet user-secrets set OpenAIKey <your-openai-key>
100
-
dotnet user-secrets set ModelName <your-openai-model-name>
101
-
```
93
+
```bash
94
+
dotnet user-secrets init
95
+
dotnet user-secrets set OpenAIKey <your-openai-key>
96
+
dotnet user-secrets set ModelName <your-openai-model-name>
97
+
```
102
98
103
99
:::zone-end
104
100
105
101
## Add the app code
106
102
107
103
The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI/) package to send and receive requests to the AI model.
108
104
109
-
1. In the **Program.cs** file, add the following code to connect and authenticate to the AI model.
105
+
1.Copy the [benefits.md](https://raw.githubusercontent.com/dotnet/docs/refs/heads/main/docs/ai/quickstarts/snippets/prompt-completion/azure-openai/benefits.md) file to your project directory. Configure the project to copy this file to the output directory. If you're using Visual Studio, right-click on the file in Solution Explorer, select **Properties**, and then set **Copy to Output Directory** to **Copy if newer**.
110
106
111
-
:::zone target="docs" pivot="azure-openai"
107
+
1. In the `Program.cs` file, add the following code to connect and authenticate to the AI model.
> <xref:Azure.Identity.DefaultAzureCredential> searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign-in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md).
> <xref:Azure.Identity.DefaultAzureCredential> searches for authentication credentials from your local tooling. If you aren't using the `azd` template to provision the Azure OpenAI resource, you'll need to assign the `Azure AI Developer` role to the account you used to sign-in to Visual Studio or the Azure CLI. For more information, see [Authenticate to Azure AI services with .NET](../azure-ai-services-authentication.md).
1. Add code to read the `benefits.md` file content and then create a prompt for the model. The prompt instructs the model to summarize the file's text content in 20 words or less.
129
125
130
-
1. Call the `InvokePromptAsync` function to send the prompt to the model to generate a response.
The app prints out the completion response from the AI model. Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
138
+
The app prints out the completion response from the AI model. Customize the text content of the `benefits.md` file or the length of the summary to see the differences in the responses.
0 commit comments