如何在Wit.ai机器人对话结束时删除context/session_id [英] How to delete context/session_id at end of conversation in Wit.ai bot

查看:113
本文介绍了如何在Wit.ai机器人对话结束时删除context/session_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Wit.ai上遇到问题,我的Python机器人在结束对话后将保留上下文.在Facebook客户端和pywit交互式客户端中,此行为相同.

I've been having issues with Wit.ai where my Python bot will retain the context after ending a conversation. This behaviour is the same in the Facebook client and the pywit interactive client.

如果用户在成功查询后点击谢谢,再见"快速回复,则对话以简单的嗨"开始,并且可以在不同分支中的不同点结束.

The conversation starts with a simple 'Hi' and can end at different points within different branches if a user taps a 'Thanks, bye' quick reply after a successful query.

如果对话再次以"Hi"开始,则会话状态从之前保存下来,从而导致错误的响应.用户说再见后删除上下文的最佳方法是什么?

If the conversation is then started with 'Hi' once again, the session state is saved from before which leads to wrong responses. What is the best way to delete the context after the user has said goodbye?

我尝试创建一个再见功能,该功能在机器人发送了最后一条消息后触发,但是它无法正常工作

I tried creating a goodbye function that triggers after the bot has sent its final message but it didn't work e.g.

def goodbye(request):
    del request['context']    # or request.clear()
    return request

文档( https://wit.ai/docs/http/20160526#post--converse-link )建议您清除session_id并生成一个新的session_id,但没有给出任何提示.

The documentation (https://wit.ai/docs/http/20160526#post--converse-link) suggests you clear the session_id and generate a new one but gives no hints as to how.

推荐答案

我遇到了相同的问题,并通过以下方式解决了该问题.

I was confronted with the same issue and I solved it in the following way.

我首先创建了一个简单的end_session操作,将在每个对话路径的末尾调用该操作:

I first created a simple end_session action, to be called at the end of each conversation path:

def end_session(request):    
    return {'end_session': True}

然后,我从run_actions返回后立即插入以下代码:

Then I inserted the following code just after returning from run_actions:

if 'end_session' in context:
    context = {}
    session_hash = uuid.uuid1().hex

如您所见,除了清除上下文,您还可以重新创建一个新的会话ID(按照 Swapnesh Khare 的建议.

As you see, in addition to clearing the context, as you do, I also recreate a new session id (as per Swapnesh Khare's suggestion).

我不确定这是否是最好的解决方案,但是它对我有用.

I'm not sure this is the best solution, but it works for me.

这篇关于如何在Wit.ai机器人对话结束时删除context/session_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆