I have a Python Flask app that tries to use IBM Watson Assistant. Below is a code snippet that invokes the message API function. How do I print the returned answer?
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)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…