-
Notifications
You must be signed in to change notification settings - Fork 322
Simple AzureOpenAI sample #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
samsp-msft
wants to merge
3
commits into
dotnet:main
Choose a base branch
from
samsp-msft:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
22
samples/AzureAI/AzureAISample.AppHost/AzureAISample.AppHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
29 changes: 29 additions & 0 deletions
29
samples/AzureAI/AzureAISample.AppHost/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
14
samples/AzureAI/AzureAISample.AppHost/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "Azure": { | ||
| "SubscriptionId": "__sub__id__", | ||
| "AllowResourceGroupCreation": true, | ||
| "ResourceGroup": "__Name_of_rg__", | ||
| "Location": "__azure_region_such_as_WestUS__" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
samples/AzureAI/AzureAISample.ServiceDefaults/AzureAISample.ServiceDefaults.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
111
samples/AzureAI/AzureAISample.ServiceDefaults/Extensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
17
samples/AzureAI/AzureAISample.Web/AzureAISample.Web.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
23 changes: 23 additions & 0 deletions
23
samples/AzureAI/AzureAISample.Web/Components/Layout/MainLayout.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.