fix: 机器人对接成功

This commit is contained in:
jackfiled 2023-10-13 16:24:03 +08:00
parent ccaefdc6cc
commit d102b47da8
4 changed files with 24 additions and 8 deletions

View File

@ -1,7 +1,7 @@
@page "/"
@using Frontend.Models
@using Katheryne.Abstractions
@inject IServiceProvider ServiceProvider
@using Katheryne.Services
@inject KatheryneChatRobotFactory ChatRobotFactory
<Layout>
@ -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<IChatRobot>()
Robot = ChatRobotFactory.GetRobot()
};
foreach (string answer in chat.Robot.OnChatStart())

View File

@ -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<IChatRobot, DefaultChatRobot>();
builder.Services.AddKatheryne();
WebApplication app = builder.Build();

View File

@ -3,7 +3,8 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"Katheryne": "Debug"
}
}
}

View File

@ -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<YamlDeserializerFactory>();
collection.AddSingleton<DefaultChatRobot>();