对于Watson Chatbot的持续对话,我该怎么办? [英] What do I have to do for the continuous conversation of watson chatbot?

查看:104
本文介绍了对于Watson Chatbot的持续对话,我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与Watson Chatbot进行持续的对话.

I want to have a continuous conversation with watson chatbot.

当前情况: 聊天框不会记住您之前发送的对话状态.

current situation : The chatbox does not remember the status of the conversation you previously sent.

我在服务器上安装了Django框架,并创建了一个watson.py文件来加载工作区并与韩国聊天应用程序KakaoTalk一起使用.

I installed the Django framework on the server and created a watson.py file to load the workspace and work with KakaoTalk, a Korean chat application.

我想要的聊天机器人的对话流程如下.

The chatbot's conversation flow that I want is as follows.

用户:我要预订

聊天机器人:会议时间是什么时候?

用户:明天

聊天机器人:您的会议时间如何?

用户:14:00

我们非常需要您的帮助.

We need your help very much.

import json
from watson_developer_cloud import ConversationV1
from .models import Test
from . import views
import simplejson

conversation = ConversationV1(
        username = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        password = "xxxxxxxxxxxxxxxxxxxxxx",
        version = '2017-05-26' )


workspace_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'           #workspace


def test(return_str):

        result = ''
      
        except Exception as err:
                pass

        response = conversation.message(
          workspace_id = workspace_id,
          message_input = {'text': return_str},
        )

        for i in range(len(response['output']['text'])):
                result += response['output']['text'][i] +'\n'

        return result


views.py

import json
from django.shortcuts import render
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .models import Jidum, Test
from . import watson


# Create your views here.

def keyboard(request):
        return JsonResponse({
                'type':'text',
                })

@csrf_exempt
def message(request):
        message = ((request.body).decode('utf-8'))
        return_json_str = json.loads(message)
        return_str = return_json_str['content']    

        return JsonResponse({
                        'message': {

                                'text': watson.test(return_str),
                        },
                        'keyboard': {
                                'type':'text',
                        },
                })

推荐答案

如您所见,它有很多 Watson对话.

As you can see, has a lot examples inside Watson Developer Cloud for use each API from IBM Developers. Take a look in one example using Watson Conversation.

当您想将同一对话用于多个请求(消息)时,您需要包括上一个响应中的上下文对象.

When you wanna use the same conversation for multiple requests (message), you need to include context object from the previous response.

但是请记住,您需要在工作区中创建对话流.

But remember, you need to create the conversation flow inside your workspace.

例如:

import json
from watson_developer_cloud import ConversationV1

#########################
# message
#########################

conversation = ConversationV1(
    username='YOUR SERVICE USERNAME',
    password='YOUR SERVICE PASSWORD',
    version='2017-04-21')

# replace with your own workspace_id
workspace_id = '0a0c06c1-8e31-4655-9067-58fcac5134fc'
# this example don't include
response = conversation.message(workspace_id=workspace_id, message_input={
    'text': 'What\'s the weather like?'})
print(json.dumps(response, indent=2))

# This example include the context object from the previous response.
# response = conversation.message(workspace_id=workspace_id, message_input={
# 'text': 'turn the wipers on'},
#                                context=response['context']) //example
# print(json.dumps(response, indent=2))

  • 使用Python参阅官方 API参考
    • See the Official API Reference using Python.
    • 这篇关于对于Watson Chatbot的持续对话,我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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