Skip to content

Commit

Permalink
Addressing some more feedback, and fixing the app so that it can auto…
Browse files Browse the repository at this point in the history
…-provision the OpenAI dependency.
  • Loading branch information
jmatthiesen committed Oct 18, 2024
1 parent aacbb35 commit 41f73a9
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/AIChatApp.AppHost/AIChatApp.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.2.1" />
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices" Version="8.2.1" />
<PackageReference Include="Aspire.Hosting.Azure.CognitiveServices" Version="9.0.0-rc.1.24511.1" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 25 additions & 0 deletions src/AIChatApp.AppHost/AIChatApp.AppHost.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AIChatApp.AppHost", "AIChatApp.AppHost.csproj", "{4D6E0B13-F222-4E81-80FD-34524B2177B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4D6E0B13-F222-4E81-80FD-34524B2177B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D6E0B13-F222-4E81-80FD-34524B2177B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D6E0B13-F222-4E81-80FD-34524B2177B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D6E0B13-F222-4E81-80FD-34524B2177B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2CCDBEAC-A29C-4A0B-A9AB-43434E8BA146}
EndGlobalSection
EndGlobal
6 changes: 2 additions & 4 deletions src/AIChatApp.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

var builder = DistributedApplication.CreateBuilder(args);

// Add support for a local configuration file, which doesn't get committed to source control
builder.Configuration.Sources.Insert(0, new JsonConfigurationSource { Path = "appsettings.Local.json", Optional = true });

var chatDeploymentName = "chat";
var connectionString = builder.Configuration.GetConnectionString("openai");

var openai = String.IsNullOrEmpty(connectionString)
? builder.AddAzureOpenAI("openai")
.AddDeployment(new AzureOpenAIDeployment(chatDeploymentName, "gpt-4o", "2024-05-13", "GlobalStandard", 10))
: builder.AddConnectionString("openai", "OPENAI_CONNECTION_STRING");
: builder.AddConnectionString("openai");

builder.AddProject<AIChatApp_Web>("aichatapp-web")
.WithReference(openai)
Expand Down
3 changes: 1 addition & 2 deletions src/AIChatApp.Web/AIChatApp.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.Azure.AI.OpenAI" Version="8.2.1-preview.1.24473.4" />
<PackageReference Include="Aspire.Azure.AI.OpenAI" Version="9.0.0-preview.4.24511.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
<PackageReference Include="Microsoft.SemanticKernel" Version="1.24.0" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.AzureOpenAI" Version="1.24.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/AIChatApp.Web/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<base href="/" />
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="AIChatApp.styles.css" />
<link rel="stylesheet" href="AIChatApp.Web.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet @rendermode="@PageRenderMode" />
</head>
Expand Down
3 changes: 1 addition & 2 deletions src/AIChatApp.Web/Components/Chat/Chat.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
@inject IConfiguration Configuration
@inject IJSRuntime JS
@using AIChatApp.Model
@attribute [StreamRendering(true)]

<PageTitle>Chat</PageTitle>

<div class="chat">
<div class="messages-scroller">
<div class="messages">
<ChatMessage
State="@(new Message(){IsAssistant = true, Content = "Hi, I'm a helpful assistant, how may I assist you?"})" />
State="@(new Message(){IsAssistant = true, Content = "Hi, let's write a limerick! What's a topic we should use?"})" />
@foreach (var message in messages)
{
<ChatMessage @key="@message" State="@message" />
Expand Down
15 changes: 15 additions & 0 deletions src/AIChatApp.Web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /App

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /App
COPY --from=build-env /App/out .
ENTRYPOINT ["dotnet", "AIChatApp.dll"]
1 change: 1 addition & 0 deletions src/AIChatApp.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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();
}
Expand Down

0 comments on commit 41f73a9

Please sign in to comment.