Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
style: init chat component
Browse files Browse the repository at this point in the history
  • Loading branch information
foxminchan committed Jun 9, 2024
1 parent 1551bfe commit c67f887
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/RookieShop.StoreFront/Components/Chatbot/ChatState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions src/RookieShop.StoreFront/Components/Chatbot/Chatbot.razor
Original file line number Diff line number Diff line change
@@ -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

<h3>Chatbot</h3>

@code {
ChatState? _chatState;
bool _missingConfiguration;

protected override async Task OnInitializedAsync()
{
var kernel = ServiceProvider.GetService<Kernel>();
if (kernel is not null)
{
_chatState = new(ProductService, BasketService, HttpContextAccessor, kernel, LoggerFactory);
}
else
{
_missingConfiguration = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="fixed bottom-0 right-0 mb-4 mr-4">
<button id="open-chat" class="text-white bg-blue-700 hover:bg-blue-800 rounded-lg focus:ring-4 py-2 px-4 transition duration-300 flex items-center">
Chat with Bot
</button>
</div>
5 changes: 3 additions & 2 deletions src/RookieShop.StoreFront/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>
@using RookieShop.Storefront.Components.Chatbot
<!DOCTYPE html>
<html lang="en">
<head>
<base href="~/"/>
Expand Down Expand Up @@ -130,7 +131,7 @@
@RenderBody()
</main>
</div>

<component type="typeof(ShowChatbotButton)" render-mode="ServerPrerendered"/>
<cache expires-after="@TimeSpan.FromSeconds(300)">
<script src="~/js/site.js" asp-append-version="true"></script>
<environment names="Development,Docker">
Expand Down

0 comments on commit c67f887

Please sign in to comment.