Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions samples/AzureAI/AzureAI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35108.284
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureAISample.AppHost", "AzureAISample.AppHost\AzureAISample.AppHost.csproj", "{586D5E1E-9845-48AE-A066-DE2FE7BB8DB9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureAISample.ServiceDefaults", "AzureAISample.ServiceDefaults\AzureAISample.ServiceDefaults.csproj", "{4B02F6F3-7878-4E62-8927-8ED12D77F3C6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureAISample.Web", "AzureAISample.Web\AzureAISample.Web.csproj", "{EEBB61C8-05EF-4962-BDBE-8DF274FF4225}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{586D5E1E-9845-48AE-A066-DE2FE7BB8DB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{586D5E1E-9845-48AE-A066-DE2FE7BB8DB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{586D5E1E-9845-48AE-A066-DE2FE7BB8DB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{586D5E1E-9845-48AE-A066-DE2FE7BB8DB9}.Release|Any CPU.Build.0 = Release|Any CPU
{4B02F6F3-7878-4E62-8927-8ED12D77F3C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B02F6F3-7878-4E62-8927-8ED12D77F3C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B02F6F3-7878-4E62-8927-8ED12D77F3C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B02F6F3-7878-4E62-8927-8ED12D77F3C6}.Release|Any CPU.Build.0 = Release|Any CPU
{EEBB61C8-05EF-4962-BDBE-8DF274FF4225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEBB61C8-05EF-4962-BDBE-8DF274FF4225}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEBB61C8-05EF-4962-BDBE-8DF274FF4225}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEBB61C8-05EF-4962-BDBE-8DF274FF4225}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CE218107-A75B-4AA6-B28C-232AEF3CEBCB}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions samples/AzureAI/AzureAISample.AppHost/AzureAISample.AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>e2081e2b-b18b-4e5a-84ce-87dd05d7ac47</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AzureAISample.Web\AzureAISample.Web.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.2.0" />
<PackageReference Include="Aspire.Hosting.Azure" Version="8.2.0" />
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices" Version="8.2.0" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions samples/AzureAI/AzureAISample.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var builder = DistributedApplication.CreateBuilder(args);

// Azure OpenAI creates deployments for each model version. This is the name of the deployment to use.
var deploymentName = "mygpt4";
var openai = builder.AddAzureOpenAI("openai")
.AddDeployment(
new(deploymentName, "gpt-4o", "2024-05-13")
);

builder.AddProject<Projects.AzureAISample_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(openai)
.WithEnvironment("AI_DeploymentName", deploymentName);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17002;http://localhost:15032",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21094",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22233"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15032",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19155",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20082"
}
}
}
}
14 changes: 14 additions & 0 deletions samples/AzureAI/AzureAISample.AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Azure": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to remove this from the committed file since it's specific to your environment/setup.

"SubscriptionId": "__sub__id__",
"AllowResourceGroupCreation": true,
"ResourceGroup": "__Name_of_rg__",
"Location": "__azure_region_such_as_WestUS__"
}
}
9 changes: 9 additions & 0 deletions samples/AzureAI/AzureAISample.AppHost/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.2.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
</ItemGroup>

</Project>
111 changes: 111 additions & 0 deletions samples/AzureAI/AzureAISample.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

namespace Microsoft.Extensions.Hosting;

// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
// This project should be referenced by each service project in your solution.
// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
public static class Extensions
{
public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
{
builder.ConfigureOpenTelemetry();

builder.AddDefaultHealthChecks();

builder.Services.AddServiceDiscovery();

builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.AddServiceDiscovery();
});

return builder;
}

public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
})
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});

builder.AddOpenTelemetryExporters();

return builder;
}

private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder)
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);

if (useOtlpExporter)
{
builder.Services.AddOpenTelemetry().UseOtlpExporter();
}

// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)
//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))
//{
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
//}

return builder;
}

public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder)
{
builder.Services.AddHealthChecks()
// Add a default liveness check to ensure app is responsive
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);

return builder;
}

public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health");

// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
}

return app;
}
}
17 changes: 17 additions & 0 deletions samples/AzureAI/AzureAISample.Web/AzureAISample.Web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AzureAISample.ServiceDefaults\AzureAISample.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Azure.AI.OpenAI" Version="8.2.0" />
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions samples/AzureAI/AzureAISample.Web/Components/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="AzureAISample.Web.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
</head>

<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
Loading