Skip to content

Commit 85049ba

Browse files
committed
Initial toc refactor
1 parent d04c1eb commit 85049ba

16 files changed

+131
-821
lines changed

docs/ai/how-to/app-service-db-auth.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,19 @@ The following code samples require these additional libraries:
146146

147147
1. Initialize a `DefaultAzureCredential` object to pick up your app's managed identity:
148148

149-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="tokenCredential":::
149+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="tokenCredential":::
150150

151151
1. Initialize an `IMemoryStore` object for your vector database, then use it to build an `ISemanticTextMemory`:
152152

153-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="aiStore":::
153+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="aiStore":::
154154

155155
1. Build a `Kernel` object, then import the `ISemanticTextMemory` object using the `TextMemoryPlugin`:
156156

157-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="addMemory":::
157+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="addMemory":::
158158

159159
1. Use the `Kernel` object to invoke a prompt that includes memory recall:
160160

161-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="useMemory":::
161+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="useMemory":::
162162

163163
## Use Key Vault to store connection secrets
164164

@@ -227,23 +227,23 @@ These code samples use a Redis database, but you can apply them to any vector da
227227
228228
1. Initialize a `DefaultAzureCredential` object to pick up your app's managed identity:
229229
230-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="tokenCredential":::
230+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="tokenCredential":::
231231
232232
1. Add Key Vault when building your configuration, this will map your Key Vault secrets to the `IConfigurationRoot` object:
233233
234-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="vaultConfig":::
234+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="vaultConfig":::
235235
236236
1. Use your vector database connection string from Key Vault to initialize an `IMemoryStore` object, and then use it to build an `ISemanticTextMemory`:
237237
238-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="redisStore":::
238+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="redisStore":::
239239
240240
1. Build a `Kernel` object, then import the `ISemanticTextMemory` object using the `TextMemoryPlugin`:
241241
242-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="addMemory":::
242+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="addMemory":::
243243
244244
1. Use the `Kernel` object to invoke a prompt that includes memory recall:
245245
246-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="useMemory":::
246+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="useMemory":::
247247
248248
## Use application settings to store connection secrets
249249
@@ -294,19 +294,19 @@ These code samples use a Redis database, but you can apply them to any vector da
294294

295295
1. Add environment variables when building your configuration, this will map your connection strings to the `IConfigurationRoot` object:
296296

297-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="appSettingsConfig":::
297+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="appSettingsConfig":::
298298

299299
1. Use your vector database connection string from app settings to initialize an `IMemoryStore` object, and then use it to build an `ISemanticTextMemory`:
300300

301-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="redisStore":::
301+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="redisStore":::
302302

303303
1. Build a `Kernel` object, then import the `ISemanticTextMemory` object using the `TextMemoryPlugin`:
304304

305-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="addMemory":::
305+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="addMemory":::
306306

307307
1. Use the `Kernel` object to invoke a prompt that includes memory recall:
308308

309-
:::code language="csharp" source="./snippets/semantic-kernel/IdentityExamples.cs" id="useMemory":::
309+
:::code language="csharp" source="./snippets/hosted-app-db-auth/Program.cs.cs" id="useMemory":::
310310

311311
## Related content
312312

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Azure.AI.OpenAI;
2+
using Azure.Identity;
3+
using Microsoft.Extensions.AI;
4+
using Microsoft.Extensions.Azure;
5+
6+
var builder = WebApplication.CreateBuilder(args);
7+
8+
// Add services to the container
9+
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
10+
builder.Services.AddOpenApi();
11+
12+
// DefaultAzureCredential attempts several auth flows in order until one is available
13+
// For example, will discover Visual Studio or Azure CLI credentials
14+
// in local environments and managed identity credentials in production deployments
15+
var credential = new DefaultAzureCredential(
16+
new DefaultAzureCredentialOptions
17+
{
18+
// If necessary, specify the tenant ID,
19+
// user-assigned identity client or resource ID, or other options
20+
}
21+
);
22+
23+
// Retrieve the Azure OpenAI endpoint and deployment name
24+
string endpoint = builder.Configuration["AZURE_OPENAI_ENDPOINT"];
25+
string deployment = builder.Configuration["AZURE_OPENAI_GPT_NAME"];
26+
27+
builder.Services.AddChatClient(
28+
new AzureOpenAIClient(new Uri(endpoint), credential)
29+
.AsChatClient(deployment));
30+
31+
var app = builder.Build();
32+
33+
// Configure the HTTP request pipeline.
34+
if (app.Environment.IsDevelopment())
35+
{
36+
app.MapOpenApi();
37+
}
38+
39+
app.UseHttpsRedirection();
40+
41+
app.MapGet("/test-prompt", async (IChatClient chatClient) =>
42+
{
43+
return await chatClient.CompleteAsync("Test prompt", new ChatOptions());
44+
})
45+
.WithName("Test prompt");
46+
47+
app.Run();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AZURE_OPENAI_ENDPOINT": "your-azure-openai-endpoint",
9+
"AZURE_OPENAI_GPT_NAME": "your-azure-openai-deployment-name"
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>hosted_app_auth</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
12+
<PackageReference Include="Azure.Identity" Version="1.13.2" />
13+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
14+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.1.0-preview.1.25064.3" />
15+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.1.0-preview.1.25064.3" />
16+
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.9.0" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@hosted_app_auth_HostAddress = http://localhost:5140
2+
3+
GET {{hosted_app_auth_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###

docs/ai/how-to/snippets/semantic-kernel/IdentityExamples.cs

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)