From f5f5bd36f08935284039d1473bad7ad881936422 Mon Sep 17 00:00:00 2001 From: Mitch Denny Date: Wed, 7 Feb 2024 23:20:15 +1100 Subject: [PATCH] Clean-up Open AI resource. --- Aspire.sln | 17 +++++++ .../Directory.Build.props | 8 ++++ .../Directory.Build.targets | 9 ++++ .../OpenAIEndToEnd.AppHost.csproj | 22 +++++++++ .../OpenAIEndToEnd.AppHost/Program.cs | 11 +++++ .../Properties/launchSettings.json | 16 +++++++ .../appsettings.Development.json | 8 ++++ .../OpenAIEndToEnd.AppHost/appsettings.json | 9 ++++ .../Components/App.razor | 18 ++++++++ .../Components/Layout/MainLayout.razor | 9 ++++ .../Components/Layout/MainLayout.razor.css | 18 ++++++++ .../Components/Pages/Error.razor | 36 +++++++++++++++ .../Components/Pages/Home.razor | 46 +++++++++++++++++++ .../Components/Routes.razor | 6 +++ .../Components/_Imports.razor | 10 ++++ .../OpenAIEndToEnd.WebStory.csproj | 14 ++++++ .../OpenAIEndToEnd.WebStory/Program.cs | 34 ++++++++++++++ .../Properties/launchSettings.json | 38 +++++++++++++++ .../appsettings.Development.json | 8 ++++ .../OpenAIEndToEnd.WebStory/appsettings.json | 9 ++++ .../OpenAIEndToEnd.WebStory/wwwroot/app.css | 3 ++ .../OpenAI/OpenAIBuilderExtensions.cs | 31 ------------- src/Aspire.Hosting/OpenAI/OpenAIResource.cs | 22 --------- .../ManifestGenerationTests.cs | 19 -------- 24 files changed, 349 insertions(+), 72 deletions(-) create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.props create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.targets create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/OpenAIEndToEnd.AppHost.csproj create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Program.cs create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Properties/launchSettings.json create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.Development.json create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.json create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/App.razor create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor.css create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Error.razor create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Home.razor create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Routes.razor create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/_Imports.razor create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/OpenAIEndToEnd.WebStory.csproj create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Program.cs create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Properties/launchSettings.json create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.Development.json create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.json create mode 100644 playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/wwwroot/app.css delete mode 100644 src/Aspire.Hosting/OpenAI/OpenAIBuilderExtensions.cs delete mode 100644 src/Aspire.Hosting/OpenAI/OpenAIResource.cs diff --git a/Aspire.sln b/Aspire.sln index 9c781a2bf4..f794cee567 100644 --- a/Aspire.sln +++ b/Aspire.sln @@ -245,6 +245,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BicepSample.AppHost", "play EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BicepSample.ApiService", "playground\bicep\BicepSample.ApiService\BicepSample.ApiService.csproj", "{54FE1759-A648-4805-94FD-08F0F4B147CF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAIEndToEnd.AppHost", "playground\OpenAIEndToEnd\OpenAIEndToEnd.AppHost\OpenAIEndToEnd.AppHost.csproj", "{13A785BC-A884-44CF-A8BA-BCF676294ED8}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenAIEndToEnd", "OpenAIEndToEnd", "{80F5BEF8-A3D0-4F30-8C15-92001DF93539}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAIEndToEnd.WebStory", "playground\OpenAIEndToEnd\OpenAIEndToEnd.WebStory\OpenAIEndToEnd.WebStory.csproj", "{621BE1D9-D9D5-4D5E-8404-3F5CC492B555}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -647,6 +653,14 @@ Global {54FE1759-A648-4805-94FD-08F0F4B147CF}.Debug|Any CPU.Build.0 = Debug|Any CPU {54FE1759-A648-4805-94FD-08F0F4B147CF}.Release|Any CPU.ActiveCfg = Release|Any CPU {54FE1759-A648-4805-94FD-08F0F4B147CF}.Release|Any CPU.Build.0 = Release|Any CPU + {13A785BC-A884-44CF-A8BA-BCF676294ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13A785BC-A884-44CF-A8BA-BCF676294ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13A785BC-A884-44CF-A8BA-BCF676294ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13A785BC-A884-44CF-A8BA-BCF676294ED8}.Release|Any CPU.Build.0 = Release|Any CPU + {621BE1D9-D9D5-4D5E-8404-3F5CC492B555}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {621BE1D9-D9D5-4D5E-8404-3F5CC492B555}.Debug|Any CPU.Build.0 = Debug|Any CPU + {621BE1D9-D9D5-4D5E-8404-3F5CC492B555}.Release|Any CPU.ActiveCfg = Release|Any CPU + {621BE1D9-D9D5-4D5E-8404-3F5CC492B555}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -763,6 +777,9 @@ Global {4E1F1835-7006-412D-83A1-740709A54A26} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0} {7E67B5F3-ADAC-48E2-83CE-1E1BFF1F8505} = {4E1F1835-7006-412D-83A1-740709A54A26} {54FE1759-A648-4805-94FD-08F0F4B147CF} = {4E1F1835-7006-412D-83A1-740709A54A26} + {13A785BC-A884-44CF-A8BA-BCF676294ED8} = {80F5BEF8-A3D0-4F30-8C15-92001DF93539} + {80F5BEF8-A3D0-4F30-8C15-92001DF93539} = {4E1F1835-7006-412D-83A1-740709A54A26} + {621BE1D9-D9D5-4D5E-8404-3F5CC492B555} = {80F5BEF8-A3D0-4F30-8C15-92001DF93539} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.props b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.props new file mode 100644 index 0000000000..b9b39c05e8 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.targets b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.targets new file mode 100644 index 0000000000..b7ba77268f --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Directory.Build.targets @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/OpenAIEndToEnd.AppHost.csproj b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/OpenAIEndToEnd.AppHost.csproj new file mode 100644 index 0000000000..e8811b68fa --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/OpenAIEndToEnd.AppHost.csproj @@ -0,0 +1,22 @@ + + + + Exe + net8.0 + enable + enable + true + b757dbc4-6942-448f-9f26-d15de0f2e760 + + + + + + + + + + + + + diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Program.cs b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Program.cs new file mode 100644 index 0000000000..859cdc49b5 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Program.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +var builder = DistributedApplication.CreateBuilder(args); + +var openai = builder.AddConnectionString("openai"); + +builder.AddProject("webstory") + .WithReference(openai); + +builder.Build().Run(); diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Properties/launchSettings.json b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Properties/launchSettings.json new file mode 100644 index 0000000000..1b2de78f9d --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/Properties/launchSettings.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:15216", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16195" + } + } + } +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.Development.json b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.Development.json new file mode 100644 index 0000000000..0c208ae918 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.json b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.json new file mode 100644 index 0000000000..31c092aa45 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Aspire.Hosting.Dcp": "Warning" + } + } +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/App.razor b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/App.razor new file mode 100644 index 0000000000..0f9b81fecd --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/App.razor @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor new file mode 100644 index 0000000000..0fd1b20ecf --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor @@ -0,0 +1,9 @@ +@inherits LayoutComponentBase + +@Body + +
+ An unhandled error has occurred. + Reload + 🗙 +
diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor.css b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor.css new file mode 100644 index 0000000000..df8c10ff29 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Layout/MainLayout.razor.css @@ -0,0 +1,18 @@ +#blazor-error-ui { + background: lightyellow; + bottom: 0; + box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); + display: none; + left: 0; + padding: 0.6rem 1.25rem 0.7rem 1.25rem; + position: fixed; + width: 100%; + z-index: 1000; +} + + #blazor-error-ui .dismiss { + cursor: pointer; + position: absolute; + right: 0.75rem; + top: 0.5rem; + } diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Error.razor b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Error.razor new file mode 100644 index 0000000000..576cc2d2f4 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Error.razor @@ -0,0 +1,36 @@ +@page "/Error" +@using System.Diagnostics + +Error + +

Error.

+

An error occurred while processing your request.

+ +@if (ShowRequestId) +{ +

+ Request ID: @RequestId +

+} + +

Development Mode

+

+ Swapping to Development environment will display more detailed information about the error that occurred. +

+

+ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +

+ +@code{ + [CascadingParameter] + private HttpContext? HttpContext { get; set; } + + private string? RequestId { get; set; } + private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + protected override void OnInitialized() => + RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Home.razor b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Home.razor new file mode 100644 index 0000000000..b3c8f5d959 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Pages/Home.razor @@ -0,0 +1,46 @@ +@page "/" +@using Azure.AI.OpenAI +@inject OpenAIClient aiClient +@inject ILogger logger + +
+ @foreach (var message in chatCompletionOptions.Messages.OfType()) + { +

@message.Content

+ } + + +
+ +@code { + private ChatCompletionsOptions chatCompletionOptions = new ChatCompletionsOptions() + { + DeploymentName = "gpt-3.5-turbo", + Messages = + { + new ChatRequestSystemMessage("Pick a random topic and write a sentence of a fictional story about it.") + } + }; + + private async Task GenerateNextParagraph() + { + if (chatCompletionOptions.Messages.Count > 1) + { + chatCompletionOptions.Messages.Add( + new ChatRequestUserMessage("Write the next sentence in the story.") + ); + } + + var response = await aiClient.GetChatCompletionsAsync(chatCompletionOptions); + var x = new ChatRequestAssistantMessage(response.Value.Choices[0].Message); + chatCompletionOptions.Messages.Add(x); + + this.StateHasChanged(); + } + + protected override async Task OnInitializedAsync() + { + await GenerateNextParagraph(); + await base.OnInitializedAsync(); + } +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Routes.razor b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Routes.razor new file mode 100644 index 0000000000..f756e19dfb --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/Routes.razor @@ -0,0 +1,6 @@ + + + + + + diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/_Imports.razor b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/_Imports.razor new file mode 100644 index 0000000000..a1b20c23ac --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Components/_Imports.razor @@ -0,0 +1,10 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Forms +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using static Microsoft.AspNetCore.Components.Web.RenderMode +@using Microsoft.AspNetCore.Components.Web.Virtualization +@using Microsoft.JSInterop +@using OpenAIEndToEnd.WebStory +@using OpenAIEndToEnd.WebStory.Components diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/OpenAIEndToEnd.WebStory.csproj b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/OpenAIEndToEnd.WebStory.csproj new file mode 100644 index 0000000000..a5e45f8c32 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/OpenAIEndToEnd.WebStory.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Program.cs b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Program.cs new file mode 100644 index 0000000000..571c21d136 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Program.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using OpenAIEndToEnd.WebStory.Components; + +var builder = WebApplication.CreateBuilder(args); + +builder.AddServiceDefaults(); + +builder.AddAzureOpenAI("openai"); + +// Add services to the container. +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); + +app.UseStaticFiles(); +app.UseAntiforgery(); + +app.MapRazorComponents() + .AddInteractiveServerRenderMode(); + +app.Run(); diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Properties/launchSettings.json b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Properties/launchSettings.json new file mode 100644 index 0000000000..910b81ebbf --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:54244", + "sslPort": 44362 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5292", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "https://localhost:7024;http://localhost:5292", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } + } diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.Development.json b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.Development.json new file mode 100644 index 0000000000..0c208ae918 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.json b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.json new file mode 100644 index 0000000000..10f68b8c8b --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/wwwroot/app.css b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/wwwroot/app.css new file mode 100644 index 0000000000..36c7520442 --- /dev/null +++ b/playground/OpenAIEndToEnd/OpenAIEndToEnd.WebStory/wwwroot/app.css @@ -0,0 +1,3 @@ +p { + font-size: 6em; +} diff --git a/src/Aspire.Hosting/OpenAI/OpenAIBuilderExtensions.cs b/src/Aspire.Hosting/OpenAI/OpenAIBuilderExtensions.cs deleted file mode 100644 index dda0137d7d..0000000000 --- a/src/Aspire.Hosting/OpenAI/OpenAIBuilderExtensions.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Aspire.Hosting.ApplicationModel; -using Aspire.Hosting.Publishing; - -namespace Aspire.Hosting; - -/// -/// Provides extension methods for adding OpenAI resources to the application model. -/// -public static class OpenAIBuilderExtensions -{ - /// - /// Adds an OpenAI service to the application model. - /// - /// The . - /// The name of the resource. This name will be used as the connection string name when referenced in a dependency. - /// A reference to the . - public static IResourceBuilder AddOpenAI(this IDistributedApplicationBuilder builder, string name) - { - var openAi = new OpenAIResource(name); - return builder.AddResource(openAi) - .WithManifestPublishingCallback(WriteOpenAIResourceToManifest); - } - - private static void WriteOpenAIResourceToManifest(ManifestPublishingContext context) - { - context.Writer.WriteString("type", "openai.v0"); - } -} diff --git a/src/Aspire.Hosting/OpenAI/OpenAIResource.cs b/src/Aspire.Hosting/OpenAI/OpenAIResource.cs deleted file mode 100644 index bf21373c7c..0000000000 --- a/src/Aspire.Hosting/OpenAI/OpenAIResource.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Aspire.Hosting.ApplicationModel; - -/// -/// A resource that represents an OpenAI resource independent of the hosting model. -/// -/// The name of the resource. -public class OpenAIResource(string name) : Resource(name), IResourceWithConnectionString -{ - /// - /// Gets or sets the connection string for the OpenAI resource. - /// - public string? ConnectionString { get; set; } - - /// - /// Gets the connection string for the OpenAI service. - /// - /// The connection string for the OpenAI service. - string? IResourceWithConnectionString.GetConnectionString() => ConnectionString; -} diff --git a/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs b/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs index b9bdeb63a1..2ee638f467 100644 --- a/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs +++ b/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs @@ -454,25 +454,6 @@ public void EnsureAllAzureOpenAIManifestTypesHaveVersion0Suffix() Assert.Equal("azure.openai.deployment.v0", deployment.GetProperty("type").GetString()); } - [Fact] - public void EnsureAllOpenAIManifestTypesHaveVersion0Suffix() - { - var program = CreateTestProgramJsonDocumentManifestPublisher(); - - program.AppBuilder.AddOpenAI("openai"); - - // Build AppHost so that publisher can be resolved. - program.Build(); - var publisher = program.GetManifestPublisher(); - - program.Run(); - - var resources = publisher.ManifestDocument.RootElement.GetProperty("resources"); - - var openai = resources.GetProperty("openai"); - Assert.Equal("openai.v0", openai.GetProperty("type").GetString()); - } - [Fact] public void EnsureAllAzureAppConfigurationManifestTypesHaveVersion0Suffix() {