9 | Swapping to Development environment will display more detailed information about the error that occurred. 10 |
11 |12 | The Development environment shouldn't be enabled for deployed applications. 13 | It can result in displaying sensitive information from exceptions to end users. 14 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 15 | and restarting the app. 16 |
17 | -------------------------------------------------------------------------------- /Dotnet/src/BlazorAI/Components/Pages/Extensions/ChatExtensions.cs: -------------------------------------------------------------------------------- 1 | using BlazorAI.Components.Models; 2 | using Markdig; 3 | using Microsoft.AspNetCore.Components; 4 | using Microsoft.FluentUI.AspNetCore.Components; 5 | using Microsoft.JSInterop; 6 | 7 | namespace BlazorAI.Components.Pages; 8 | 9 | #pragma warning disable SKEXP0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. 10 | #pragma warning disable SKEXP0050 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. 11 | #pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. 12 | #pragma warning disable SKEXP0040 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. 13 | #pragma warning disable SKEXP0020 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. 14 | 15 | public partial class Chat 16 | { 17 | private const int MIN_ROWS = 2; 18 | private const int MAX_ROWS = 6; 19 | private string newMessage = string.Empty; 20 | private int textRows = 0; 21 | bool loading = false; 22 | private FluentButton submitButton; 23 | private FluentTextArea inputTextArea; 24 | private int messagesLastScroll = 0; 25 | private bool displayToolMessages = false; 26 | 27 | [Inject] 28 | private IKeyCodeService KeyCodeService { get; set; } 29 | 30 | [Inject] 31 | IJSRuntime JsRuntime { get; set; } = null!; 32 | 33 | [Inject] 34 | public AppState AppState { get; set; } = null!; 35 | 36 | 37 | private MarkdownPipeline pipeline = new MarkdownPipelineBuilder() 38 | .UseAdvancedExtensions() 39 | .UseBootstrap() 40 | .UseEmojiAndSmiley() 41 | .Build(); 42 | 43 | protected override async Task OnInitializedAsync() 44 | { 45 | // This is used by Blazor to capture the user input for shortcut keys. 46 | KeyCodeService.Clear(); 47 | KeyCodeService.RegisterListener(OnKeyDownAsync); 48 | // Initialize the chat history here 49 | await InitializeSemanticKernel(); 50 | } 51 | 52 | protected override async Task OnAfterRenderAsync(bool firstRender) 53 | { 54 | await base.OnAfterRenderAsync(firstRender); 55 | await JsRuntime.InvokeVoidAsync("highlightCode"); 56 | 57 | if (!firstRender && chatHistory != null && chatHistory.Any() && messagesLastScroll != chatHistory.Count) 58 | { 59 | messagesLastScroll = chatHistory.Count; 60 | await JsRuntime.InvokeVoidAsync("scrollToBottom"); 61 | } 62 | } 63 | 64 | protected string MessageInput 65 | { 66 | get => newMessage; 67 | set 68 | { 69 | newMessage = value; 70 | CalculateTextRows(value); 71 | } 72 | } 73 | 74 | private void ClearChat() 75 | { 76 | chatHistory?.Clear(); 77 | } 78 | 79 | private void CalculateTextRows(string value) 80 | { 81 | textRows = Math.Max(value.Split('\n').Length, value.Split('\r').Length); 82 | textRows = Math.Max(textRows, MIN_ROWS); 83 | textRows = Math.Min(textRows, MAX_ROWS); 84 | } 85 | 86 | private async Task OnKeyDownAsync(FluentKeyCodeEventArgs args) 87 | { 88 | if (args.CtrlKey && args.Value == "Enter") 89 | { 90 | Console.WriteLine("Ctrl+Enter Pressed"); 91 | await InvokeAsync(async () => 92 | { 93 | StateHasChanged(); 94 | await Task.Delay(180); 95 | Console.WriteLine("Value in TextArea: {0}", MessageInput); 96 | await submitButton.OnClick.InvokeAsync(); 97 | }); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Dotnet/src/BlazorAI/Components/Pages/MultiAgent.razor: -------------------------------------------------------------------------------- 1 | @page "/multiagent" 2 | 3 |Here are some of our amazing outdoor products that you can purchase.
13 | 14 | @if (products == null) 15 | { 16 |Loading...
17 | } 18 | else 19 | { 20 |Image | 24 |Name | 25 |Description | 26 |Price | 27 |
---|---|---|---|
@product.Name | 36 |@product.Description | 37 |@product.Price | 38 |
Search our amazing outdoor products that you can purchase.
13 | 14 |@aiResponse
22 | 23 | @* Uncomment this to show elapsed time *@ 24 | @*Elapsed Time: [@elapsedTime]
*@ 25 |Loading...
31 | } 32 | else 33 | { 34 |Image | 38 |Name | 39 |Description | 40 |Price | 41 |
---|---|---|---|
@product.Name | 50 |@product.Description | 51 |@product.Price | 52 |