Skip to content

Commit

Permalink
Upgrade packages and fix API breaking changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Dec 4, 2023
1 parent a41d645 commit 182679c
Show file tree
Hide file tree
Showing 22 changed files with 587 additions and 243 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.Playwright" Version="1.32.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Azure.OpenAI\Server\Azure.OpenAI.Server.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -9,15 +10,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-preview.6.23329.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0-preview-23364-03" />
<PackageReference Include="Microsoft.Playwright" Version="1.36.0" />
<PackageReference Include="xunit" Version="2.5.1-pre.12" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1-pre.4">
<PackageReference Include="CliWrap" Version="3.6.5-test" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23531-01" />
<PackageReference Include="Microsoft.Playwright" Version="1.40.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
23 changes: 12 additions & 11 deletions Azure.OpenAI/Client/Azure.OpenAI.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-preview.6.23329.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-preview.6.23329.11" PrivateAssets="all" />
<PackageReference Include="Blazor.LocalStorage.WebAssembly" Version="7.0.3" />
<PackageReference Include="Blazor.SessionStorage.WebAssembly" Version="7.0.3" />
<PackageReference Include="Blazor.SpeechRecognition.WebAssembly" Version="7.0.3" />
<PackageReference Include="Blazor.SpeechSynthesis.WebAssembly" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.0-preview.6.23329.11" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0-preview.6.23329.7" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.0-preview.6.23329.11" />
<PackageReference Include="MudBlazor" Version="6.7.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Blazor.LocalStorage.WebAssembly" Version="8.0.0" />
<PackageReference Include="Blazor.SessionStorage.WebAssembly" Version="8.0.0" />
<PackageReference Include="Blazor.SpeechRecognition.WebAssembly" Version="8.0.0" />
<PackageReference Include="Blazor.SpeechSynthesis.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.0" />
<PackageReference Include="Markdig" Version="0.33.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="8.0.0" />
<PackageReference Include="MudBlazor" Version="6.11.1" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions Azure.OpenAI/Client/Components/Assistant.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<MudGrid Justify="Justify.Center" Spacing="2">
<MudItem lg="12">
<MudStack Class="pb-4">
<MudIcon Icon="@Icons.Material.Filled.AutoAwesome"
Class="icon-huge align-self-center" Color="Color.Primary" />
<MudText Typo="Typo.h2" Class="align-self-center">
@(Localizer["Interact_with"])
</MudText>
<MudText Typo="Typo.h1" Class="align-self-center"
Style="font-family: monospace;">
Blazor 📎 Clippy
</MudText>
<MudText Typo="Typo.h2" Class="align-self-center">
@(Localizer["using_voice_chat"])
</MudText>
</MudStack>
</MudItem>
</MudGrid>
9 changes: 9 additions & 0 deletions Azure.OpenAI/Client/Components/Assistant.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Azure.OpenAI.Client.Components;

public sealed partial class Assistant
{
[Inject] public required IStringLocalizer<Assistant> Localizer { get; set; }
}
126 changes: 126 additions & 0 deletions Azure.OpenAI/Client/Components/Assistant.razor.en.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Interact_with" xml:space="preserve">
<value>Interact with</value>
</data>
<data name="using_voice_chat" xml:space="preserve">
<value>using voice chat.</value>
</data>
</root>
52 changes: 52 additions & 0 deletions Azure.OpenAI/Client/Components/QuestionAndAnswerStream.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<MudStack Reverse="false" Spacing="12">
@foreach (var (askedOn, (question, answer)) in QuestionAndAnswerMap)
{
<MudStack Justify="Justify.Center" AlignItems="AlignItems.Start" Spacing="4">
<MudBadge Origin="Origin.TopLeft" Overlap="true" Color="Color.Secondary"
Icon="@Icons.Material.Filled.QuestionMark" Class="d-flex align-self-end">
<MudPaper Class="pa-6 d-flex flex-column" Elevation="3">
<MudText Typo="Typo.body1" Align="Align.End">
@((MarkupString)question.Question.ToHtml())
</MudText>
<MudText Typo="Typo.caption" Align="Align.End" Color="Color.Secondary">
@Localizer["AskedOnFormat", askedOn]
</MudText>
</MudPaper>
</MudBadge>
<div class="ten-twelves">
@if (answer is null)
{
<MudBadge Origin="Origin.TopLeft" Overlap="true" Color="Color.Secondary"
Icon="@Icons.Material.Filled.Lightbulb" Class="full-width">
<MudPaper Class="pa-6" Elevation="3">
<MudText Typo="Typo.h5" Color="Color.Secondary" Class="pb-2">
🤖 @Localizer["BusyMessage"]
</MudText>
<MudProgressCircular Color="Color.Secondary"
Indeterminate="true" Class="pb-4" />
</MudPaper>
</MudBadge>
}
else if (answer.Value.ContainsError)
{
<MudBadge Origin="Origin.TopLeft" Overlap="true" Color="Color.Error"
Icon="@Icons.Material.Filled.Error">
<AnswerError Error="@answer.Value.Error" Question="@question"
OnRetryClicked="@OnAskQuestionAsync" />
</MudBadge>
}
else
{
<MudBadge Origin="Origin.TopLeft" Overlap="true" Color="Color.Secondary"
Icon="@Icons.Material.Filled.AutoAwesome">
<MudPaper Class="pa-6" Elevation="3">
<MudText Typo="Typo.body1">
@((MarkupString)(answer.Value.Answer ?? "Unable to generate answer."))
</MudText>
</MudPaper>
</MudBadge>
}
</div>
</MudStack>
}
</MudStack>
24 changes: 24 additions & 0 deletions Azure.OpenAI/Client/Components/QuestionAndAnswerStream.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Azure.OpenAI.Client.Components;

public sealed partial class QuestionAndAnswerStream
{
[Parameter, EditorRequired]
public required Dictionary<DateTime, QuestionAndAnswer> QuestionAndAnswerMap { get; set; } = new();

[Parameter, EditorRequired]
public required EventCallback<PromptQuestion> OnAskQuestion { get; set; }

[Inject]
public required IStringLocalizer<QuestionAndAnswerStream> Localizer { get; set; }

private async Task OnAskQuestionAsync(UserQuestion userQuestion)
{
if (OnAskQuestion is { HasDelegate: true } handler)
{
await handler.InvokeAsync((userQuestion.Question, true));
}
}
}
42 changes: 42 additions & 0 deletions Azure.OpenAI/Client/Components/UserPrompt.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<MudGrid>
<MudItem xs="12" lg="10">
<MudTextField @bind-Value="_userQuestion" Label=@Localizer["Prompt"]
Variant="Variant.Outlined" Adornment="Adornment.End"
AdornmentIcon="@Icons.Material.Filled.VoiceChat"
AdornmentColor="Color.Secondary" AutoFocus="true"
Placeholder=@Localizer["ChatPrompt"] Lines="3" Immediate="true"
HelperText=@Localizer["InputHelperText"]
OnKeyUp="@OnKeyUp" Clearable="true" Counter="1_000" MaxLength="1_000"
Disabled=@(_isRecognizingSpeech || _isReceivingResponse) IconSize="Size.Large"
autocomplete="off" title=@Localizer["ChatPrompt"] />
</MudItem>
<MudItem xs="0" lg="2" Class="d-flex align-self-center">
<MudGrid Justify="Justify.Center">
<MudItem xs="9" Class="pa-2">
<MudFab Label=@Localizer[_isRecognizingSpeech ? "Stop" : "Speak"]
Color="Color.Primary" Size="Size.Large"
StartIcon=@(_isRecognizingSpeech ? @Icons.Material.Filled.MicOff : Icons.Material.Filled.Mic)
OnClick="@OnRecognizeSpeechClick" Disabled=@_isReceivingResponse Class="full-width"
mic="@(_isRecognizingSpeech ? "on" : "off")" />
</MudItem>
@* <MudItem xs="3" Class="pa-2">
<MudTooltip Text=@Localizer["OpenTTSDialog"] Placement="Placement.Top">
<MudFab Color="Color.Tertiary" Size="Size.Medium"
StartIcon="@Icons.Material.Filled.SettingsVoice"
OnClick="@ShowVoiceDialogAsync" />
</MudTooltip>
</MudItem>
<MudItem xs="9" Class="pa-2">
<MudFab Color="Color.Secondary" Label=@Localizer["Ask"] Size="Size.Large"
StartIcon=@Icons.Material.Filled.Send Class="full-width"
OnClick="@(_ => OnSendPrompt())"
Disabled=@(_isRecognizingSpeech || _isReceivingResponse || string.IsNullOrWhiteSpace(_userQuestion)) />
</MudItem>
<MudItem xs="3" Class="pa-2">
<MudFab Color="Color.Warning" Size="Size.Medium"
StartIcon="@Icons.Material.Filled.Stop"
OnClick="@StopTalking" Disabled=@(_isReadingResponse is false) />
</MudItem> *@
</MudGrid>
</MudItem>
</MudGrid>
Loading

0 comments on commit 182679c

Please sign in to comment.