From d102b47da82033907c3007bc0522234ae2e2827f Mon Sep 17 00:00:00 2001 From: jackfiled Date: Fri, 13 Oct 2023 16:24:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9C=BA=E5=99=A8=E4=BA=BA=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frontend/Pages/Index.razor | 24 ++++++++++++++++++++---- Frontend/Program.cs | 3 +-- Frontend/appsettings.Development.json | 3 ++- Katheryne/ServiceCollectionExtensions.cs | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Frontend/Pages/Index.razor b/Frontend/Pages/Index.razor index e2ee1b5..6c398df 100644 --- a/Frontend/Pages/Index.razor +++ b/Frontend/Pages/Index.razor @@ -1,7 +1,7 @@ @page "/" @using Frontend.Models -@using Katheryne.Abstractions -@inject IServiceProvider ServiceProvider +@using Katheryne.Services +@inject KatheryneChatRobotFactory ChatRobotFactory @@ -51,8 +51,24 @@ protected override void OnInitialized() { - Chat chat = GetInitChat(); + ChatRobotFactory.SetGrammar(@" + robotName: 凯瑟琳 + stages: + - name: start + answer: 向着星辰和深渊!欢迎来到冒险家协会。 + transformers: + - pattern: .*? + nextStageName: running + + - name: running + answer: 对不起,做不到。 + transformers: + - pattern: .*? + nextStageName: running + beginStageName: start + "); + Chat chat = GetInitChat(); _chatDictionary.Add(chat.Guid, chat); _currentGuid = chat.Guid; } @@ -79,7 +95,7 @@ var chat = new Chat { Title = $"对话:{_chatDictionary.Count + 1}", - Robot = ServiceProvider.GetRequiredService() + Robot = ChatRobotFactory.GetRobot() }; foreach (string answer in chat.Robot.OnChatStart()) diff --git a/Frontend/Program.cs b/Frontend/Program.cs index e2391ad..be620f2 100644 --- a/Frontend/Program.cs +++ b/Frontend/Program.cs @@ -1,12 +1,11 @@ using Katheryne; -using Katheryne.Abstractions; WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddAntDesign(); -builder.Services.AddTransient(); +builder.Services.AddKatheryne(); WebApplication app = builder.Build(); diff --git a/Frontend/appsettings.Development.json b/Frontend/appsettings.Development.json index 770d3e9..e246f63 100644 --- a/Frontend/appsettings.Development.json +++ b/Frontend/appsettings.Development.json @@ -3,7 +3,8 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Katheryne": "Debug" } } } diff --git a/Katheryne/ServiceCollectionExtensions.cs b/Katheryne/ServiceCollectionExtensions.cs index 5ad2dd0..d97bbe8 100644 --- a/Katheryne/ServiceCollectionExtensions.cs +++ b/Katheryne/ServiceCollectionExtensions.cs @@ -5,7 +5,7 @@ namespace Katheryne; public static class ServiceCollectionExtensions { - public static void AddYamlDeserializerFactory(this IServiceCollection collection) + public static void AddKatheryne(this IServiceCollection collection) { collection.AddSingleton(); collection.AddSingleton();