From c67f887aec3f1515a19306c1e95d1f76f89441ce Mon Sep 17 00:00:00 2001 From: Nguyen Xuan Nhan Date: Sun, 9 Jun 2024 17:34:49 +0700 Subject: [PATCH] style: init chat component --- .../Components/Chatbot/ChatState.cs | 4 ++- .../Components/Chatbot/Chatbot.razor | 28 +++++++++++++++++++ .../Chatbot/ShowChatbotButton.razor | 5 ++++ .../Views/Shared/_Layout.cshtml | 5 ++-- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/RookieShop.StoreFront/Components/Chatbot/Chatbot.razor create mode 100644 src/RookieShop.StoreFront/Components/Chatbot/ShowChatbotButton.razor diff --git a/src/RookieShop.StoreFront/Components/Chatbot/ChatState.cs b/src/RookieShop.StoreFront/Components/Chatbot/ChatState.cs index 0ec9bb1..e97e40a 100644 --- a/src/RookieShop.StoreFront/Components/Chatbot/ChatState.cs +++ b/src/RookieShop.StoreFront/Components/Chatbot/ChatState.cs @@ -20,7 +20,9 @@ public sealed class ChatState private readonly IHttpContextAccessor _httpContextAccessor; private readonly OpenAIPromptExecutionSettings _aiSettings = new() - { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions }; + { + ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions + }; public ChatState( IProductService productService, diff --git a/src/RookieShop.StoreFront/Components/Chatbot/Chatbot.razor b/src/RookieShop.StoreFront/Components/Chatbot/Chatbot.razor new file mode 100644 index 0000000..25c71d1 --- /dev/null +++ b/src/RookieShop.StoreFront/Components/Chatbot/Chatbot.razor @@ -0,0 +1,28 @@ +@using Microsoft.SemanticKernel +@using RookieShop.Storefront.Areas.Basket.Services +@using RookieShop.Storefront.Areas.Product.Services +@inject IProductService ProductService +@inject IBasketService BasketService +@inject IHttpContextAccessor HttpContextAccessor +@inject ILoggerFactory LoggerFactory +@inject IServiceProvider ServiceProvider + +

Chatbot

+ +@code { + ChatState? _chatState; + bool _missingConfiguration; + + protected override async Task OnInitializedAsync() + { + var kernel = ServiceProvider.GetService(); + if (kernel is not null) + { + _chatState = new(ProductService, BasketService, HttpContextAccessor, kernel, LoggerFactory); + } + else + { + _missingConfiguration = true; + } + } +} diff --git a/src/RookieShop.StoreFront/Components/Chatbot/ShowChatbotButton.razor b/src/RookieShop.StoreFront/Components/Chatbot/ShowChatbotButton.razor new file mode 100644 index 0000000..fef5eba --- /dev/null +++ b/src/RookieShop.StoreFront/Components/Chatbot/ShowChatbotButton.razor @@ -0,0 +1,5 @@ +
+ +
\ No newline at end of file diff --git a/src/RookieShop.StoreFront/Views/Shared/_Layout.cshtml b/src/RookieShop.StoreFront/Views/Shared/_Layout.cshtml index cf585e6..3c293a9 100644 --- a/src/RookieShop.StoreFront/Views/Shared/_Layout.cshtml +++ b/src/RookieShop.StoreFront/Views/Shared/_Layout.cshtml @@ -1,4 +1,5 @@ - +@using RookieShop.Storefront.Components.Chatbot + @@ -130,7 +131,7 @@ @RenderBody() - +