gpt4 book ai didi

c# - 使用触发词将对话数据永久存储在 Azure 聊天机器人中

转载 作者:行者123 更新时间:2023-11-30 18:13:59 25 4
gpt4 key购买 nike

我一直在对 azure 聊天机器人进行一些开发,特别是 C# 中的 QnA 机器人,现在正在考虑将对话历史记录存储到表或数据库存储中。

但与网络上的大多数教程和文档不同,我不想存储从开始到结束的整个对话,我只想存储用户发送给机器人的第一条消息。我希望暂时存储此消息,直到用户输入“否”。当用户输入“否”时,我希望临时存储中保存的内容永久存储。

这在聊天机器人中可能吗?

如果您有任何帮助或见解,我们将不胜感激!

最佳答案

使用字典等临时存储可以很容易地实现这一点。有多种方法可以实现这一目标。我要研究的一件事是scorables用于捕获“否”文本。在此示例中,我没有使用 scorables 但它具有您正在寻找的基本功能。这个想法是,当消息传入时,您检查是否已经保存了来自该 userId 的消息并保存了它,如果没有保存它。如果用户发送文本“否”,则将文本保存到永久存储并从字典中删除该条目。我只是在基本的 RootDialog.cs 中执行此操作:

    private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var activity = await result as Activity;

var userId = activity.From.Id;
var message = activity.Text;
if (!Utils.FirstMessageDictionary.ContainsKey(userId))
{

Utils.FirstMessageDictionary.Add(userId, message);
await context.PostAsync($"Message saved {userId} - {Utils.FirstMessageDictionary[userId]}");
}

if (message.ToLower() == "no")
{

//save to permanent storage here

Utils.FirstMessageDictionary.Remove(userId);
await context.PostAsync($"Entry Removed for {userId}");

try
{
await context.PostAsync($"{userId} - {Utils.FirstMessageDictionary[userId]}");
}
catch (Exception e)
{
await context.PostAsync($"No entry found for {userId}");
}
}
context.Wait(MessageReceivedAsync);
}

我还为字典制作了这个简单的类:

public static class Utils
{
public static Dictionary<string, string> FirstMessageDictionary = new Dictionary<string, string>();
}

关于c# - 使用触发词将对话数据永久存储在 Azure 聊天机器人中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51607582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com