是否可以使 wit.ai 机器人 remember/reuse 成为跨故事的上下文?
Is it possible to make a wit.ai bot remember/reuse a context across stories?
我正在使用 Wit.ai 创建一个聊天机器人,并试图实现更具对话性的交互方式。目前我有几个故事都需要一个位置才能发挥作用,但有些相关。这是我现在如何与我的机器人交互的示例:
What is the weather in Los Angeles, CA?
Bot response
How many people live in Los Angeles, CA?
Bot response
但我希望我的聊天机器人记住我说的是洛杉矶,所以互动看起来像这样:
What is the weather in Los Angeles, CA?
Bot Response
How many people live there?
Bot Response
尽管正在执行 2 个不同的故事。目前我可以通过添加一个额外的函数(我使用它的方式与使用合并的方式相同)和一个单例到我的代码来实现这一点,它从实体中提取值并存储它们以供以后根据会话信息使用,如下所示:
session_info = {}
def _init_store(session_id):
global session_info
print "session info", session_info
if session_id in session_info:
pass
else:
s_info = {}
session_info[session_id] = s_info
def get_stored_info(session_id, key):
global session_info
try:
return session_info[session_id][key]
except:
return None
def add_stored_info(session_id, key, data):
_init_store(session_id)
global session_info
try:
session_info[session_id][key] = data
return True
except:
return False
我通读了所有文档,对他们所说的有些困惑。文档对上下文这样说:
Converse allows you to build conversational app. It allows you to
predict what your app should do at any given state in the conversation
based on the current context and the user query.
The context is an object you manage to tell Wit.ai about the current
state of the conversation. Wit.ai is able to predict the next action
your bot should take by comparing — among other things — the context
described in your Stories with the one you send to the the /converse
endpoint. Wit will never update the context by itself, you have to
manage the context object on your side. There is usually one context
object per session. In addition to helping Wit.ai predict the next
action, the context is used to create dynamic answers in templates.
我读这意味着机智将传递我管理的上下文对象而不对其进行任何更改,这意味着我负责添加和删除密钥。但是我还发现 this 指出 "Conversation-aware entity extraction" 尚未实施,所以我很困惑这是否可行。
我还发现,当我查看传递给每个故事执行函数的 request['context']
的值时,上下文的值只是一个空字典,无论之前添加或删除了什么即使它上面说你的上下文从未被机智触及。
这是否可能通过机智本身来实现,或者是否有机智认可的方法来实现这一点,或者我现在正在做的是我能做的最好的吗?如果我不得不猜测它似乎还不受支持,但它似乎是一个基本的聊天机器人功能,而且文档非常模糊,我也可能只是忽略了执行此操作的正确方法。任何帮助将不胜感激。我正在使用 python 以防与任何人相关。
它应该按照您描述的方式工作。是的,Wit 不会更新上下文,因此如果您想 keep/remember 稍后使用,您将不得不使用客户端操作将其存储在上下文中。在您的示例中,您将实体 wit/location 的值存储在上下文键中,比方说 loc
在你的“有多少人住在那里?”故事中,你将有一个客户端操作来检查 context.loc 是否存在,如果不存在,将通过 [=11] 的分支机构请求它=] 食谱
我正在使用 Wit.ai 创建一个聊天机器人,并试图实现更具对话性的交互方式。目前我有几个故事都需要一个位置才能发挥作用,但有些相关。这是我现在如何与我的机器人交互的示例:
What is the weather in Los Angeles, CA?
Bot response
How many people live in Los Angeles, CA?
Bot response
但我希望我的聊天机器人记住我说的是洛杉矶,所以互动看起来像这样:
What is the weather in Los Angeles, CA?
Bot Response
How many people live there?
Bot Response
尽管正在执行 2 个不同的故事。目前我可以通过添加一个额外的函数(我使用它的方式与使用合并的方式相同)和一个单例到我的代码来实现这一点,它从实体中提取值并存储它们以供以后根据会话信息使用,如下所示:
session_info = {}
def _init_store(session_id):
global session_info
print "session info", session_info
if session_id in session_info:
pass
else:
s_info = {}
session_info[session_id] = s_info
def get_stored_info(session_id, key):
global session_info
try:
return session_info[session_id][key]
except:
return None
def add_stored_info(session_id, key, data):
_init_store(session_id)
global session_info
try:
session_info[session_id][key] = data
return True
except:
return False
我通读了所有文档,对他们所说的有些困惑。文档对上下文这样说:
Converse allows you to build conversational app. It allows you to predict what your app should do at any given state in the conversation based on the current context and the user query.
The context is an object you manage to tell Wit.ai about the current state of the conversation. Wit.ai is able to predict the next action your bot should take by comparing — among other things — the context described in your Stories with the one you send to the the /converse endpoint. Wit will never update the context by itself, you have to manage the context object on your side. There is usually one context object per session. In addition to helping Wit.ai predict the next action, the context is used to create dynamic answers in templates.
我读这意味着机智将传递我管理的上下文对象而不对其进行任何更改,这意味着我负责添加和删除密钥。但是我还发现 this 指出 "Conversation-aware entity extraction" 尚未实施,所以我很困惑这是否可行。
我还发现,当我查看传递给每个故事执行函数的 request['context']
的值时,上下文的值只是一个空字典,无论之前添加或删除了什么即使它上面说你的上下文从未被机智触及。
这是否可能通过机智本身来实现,或者是否有机智认可的方法来实现这一点,或者我现在正在做的是我能做的最好的吗?如果我不得不猜测它似乎还不受支持,但它似乎是一个基本的聊天机器人功能,而且文档非常模糊,我也可能只是忽略了执行此操作的正确方法。任何帮助将不胜感激。我正在使用 python 以防与任何人相关。
它应该按照您描述的方式工作。是的,Wit 不会更新上下文,因此如果您想 keep/remember 稍后使用,您将不得不使用客户端操作将其存储在上下文中。在您的示例中,您将实体 wit/location 的值存储在上下文键中,比方说 loc
在你的“有多少人住在那里?”故事中,你将有一个客户端操作来检查 context.loc 是否存在,如果不存在,将通过 [=11] 的分支机构请求它=] 食谱