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
The sample project includes completed apps you can run to connect to your AI model of choice:
38
-
39
-
# [OpenAI](#tab/openai)
40
-
41
-
1. From a terminal or command prompt, navigate to the `src\quickstarts\microsoft-extensions-ai\openai\01-HikeBenefitsSummary` directory.
42
-
43
-
1. Run the following commands to configure your OpenAI API key as a secret for the sample app:
33
+
1. In an empty directory on your computer, use the `dotnet new` command to create a new console app:
44
34
45
-
```bash
46
-
dotnet user-secrets init
47
-
dotnet user-secrets set OpenAIKey <your-openai-key>
35
+
```dotnetcli
36
+
dotnet new console -o ExtensionsAI
48
37
```
49
38
50
-
1. Use the `dotnet run`command to run the app:
39
+
1. Change directory into the app folder:
51
40
52
41
```dotnetcli
53
-
dotnet run
42
+
cd ExtensionsAI
54
43
```
55
44
56
-
# [Azure OpenAI](#tab/azure-openai)
57
-
58
-
1. From a terminal or command prompt, navigate to the `src\quickstarts\microsoft-extensions-ai\azure-openai\01-HikeBenefitsSummary` directory.
59
-
60
-
> [!NOTE]
61
-
> The Azure OpenAI scenario assumes the use of `azd` to provision an Azure OpenAI resource and configure essential permissions. Your can also [provision an Azure OpenAI resource](/azure/ai-services/openai/how-to/create-resource) using another tool such as the Azure portal or Azure CLI.
62
-
63
-
1. Run the `azd up`command to provision the Azure OpenAI resource and configure the necessary permissions. The command may take a few minutes to finish.
1. Open the app in Visual Studio code or your editor of choice
74
55
75
-
---
56
+
```bash
57
+
code.
58
+
```
76
59
77
-
## Explore the code
60
+
## Add the code
78
61
79
62
The app uses the [`Microsoft.Extensions.AI`](https://www.nuget.org/packages/Microsoft.Extensions.AI) package to send and receive requests to the OpenAI service.
80
63
81
-
The **Program.cs** file contains all of the app code. The first several lines of code set configuration values to connect and authenticate to the AI model.
64
+
1. In the **Program.cs** file, add the following codeto connect and authenticate to the AI model:
>`DefaultAzureCredential` searches for credentials from your local environment and tooling. If you are not using the `azd` template to provision the Azure OpenAI resource, assign the `Azure AI Developer` role manually to the account you used to sign-in to Visual Studio or the Azure CLI.
72
+
> [!NOTE]
73
+
> `DefaultAzureCredential` searches for credentials from your local environment and tooling. If you are not using the `azd` template to provision the Azure OpenAI resource, assign the `Azure AI Developer` role manually to the account you used to sign-in to Visual Studio or the Azure CLI.
The following code obtains an `IChatClient` service configured to connect to the AI Model. The `OpenAI` and `Azure.AI.OpenAI` libraries implement types defined in the `Microsoft.Extensions.AI` library, which enables you to code using the `IChatClient` interface abstraction. This abstraction allows you to change the underlying AI provider to other services by updating only a few lines of code, such as Ollama or Azure Inference models.
79
+
1. Add the following code to create an `IChatClient` service configured to connect to the AI Model:
The `OpenAI` and `Azure.AI.OpenAI` libraries implement types defined in the `Microsoft.Extensions.AI` library, which enables you to code using the `IChatClient` interface abstraction. This abstraction allows you to change the underlying AI provider to other services by updating only a few lines of code, such as Ollama or Azure Inference models.
107
92
108
-
The `CompleteAsync`functionsends the `prompt` to the model to generate a response. The `Microsoft.Extensions.AI` library enables this code to be agnostic towards a specific AI service because it uses an `IChatClient` abstraction rather than a platform-specific SDK implementation.
93
+
1. Use the `CompleteAsync` function to send a `prompt` to the model to generate a response.
0 commit comments