【发布时间】:2018-10-16 04:27:51
【问题描述】:
我有一个尝试使用 IBM Watson Assistant 的 Python Flask 应用程序。下面是调用消息 API 函数的代码 sn-p。如何打印返回的答案?
import json, _watson, requests, jsonify
import watson_developer_cloud
from flask import Flask, render_template
from flask_socketio import SocketIO, send
@app.route('/')
def index():
return render_template('index.html')
@socketio.on('message')
def handleMessage(msg):
print("Message: "+msg)
msg = _watson.conversacion(msg)
send(msg, broadcast=False)
def conversacion(mensaje):
response = assistant.message(workspace_id='1bef94fd-be51-4996-956c-73f9d0f08c41', input={'text': mensaje})
mens = (json.dumps(response, indent=2))
msj = json.loads(mens)
# print(json.dumps(response, indent=2))
print(msj["output"]["text"][0]) # mensaje de respuesta
rewa = (msj["output"]["text"][0])
return rewa
if __name__=='__main__':
socketio.run(app)
【问题讨论】:
标签: python flask ibm-cloud ibm-watson watson-conversation