@page "/"
@using Frontend.Models
@using Katheryne.Services
@inject KatheryneChatRobotFactory ChatRobotFactory
@if (context.Selected)
{
}
else
{
}
@code {
private readonly Dictionary _chatDictionary = new();
private Guid _currentGuid;
protected override void OnInitialized()
{
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;
}
private void CreateChatClicked()
{
Chat chat = GetInitChat();
_chatDictionary.Add(chat.Guid, chat);
_chatDictionary[_currentGuid].Selected = false;
_currentGuid = chat.Guid;
_chatDictionary[_currentGuid].Selected = true;
}
private void ChangeChatClicked(Guid guid)
{
_chatDictionary[_currentGuid].Selected = false;
_currentGuid = guid;
_chatDictionary[_currentGuid].Selected = true;
}
private Chat GetInitChat()
{
var chat = new Chat
{
Title = $"对话:{_chatDictionary.Count + 1}",
Robot = ChatRobotFactory.GetRobot()
};
foreach (string answer in chat.Robot.OnChatStart())
{
chat.Messages.Add(new ChatMessage
{
Sender = chat.Robot.RobotName,
Left = true,
Text = answer
});
}
chat.Selected = true;
return chat;
}
}