我正在使用带有简单PHP / Curl代码的Watson Conversation API。我问问题,我可以告诉Watson正确的问题,因为“意图”会改变。但是输出消息总是一样的。
$input = array("text"=>$_GET["msg"]);
$return["input"] = (object)$input;
if(strlen($_GET["context"])>0){
$context = array("conversation_id"=>$_GET["context"]);
$return["context"] = (object) $context;
}
$return = (object) $return;
$json = json_encode($return);
echo $json;
echo "<br><hr><br>";
$ch = curl_init("https://gateway.watsonplatform.net/conversation/api/v1/workspaces/d5ee17e9-9e19-bca5-765870f31816/message?version=2018-02-16");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json))
);
$output = curl_exec($ch);
echo "<pre>".$output."</pre>";
这是我得到的答案:
{
"intents": [
{
"intent": "capabilities",
"confidence": 1
}
],
"entities": [],
"input": {
"text": "what can you do"
},
"output": {
"text": [
"Hi. It looks like a nice drive today. What would you like me to do? "
],
"nodes_visited": [
"Start And Initialize Context"
],
"log_messages": []
},
"context": {
"conversation_id": "cbb41b48-addb-4d42-a146-39a4550caaaf",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_turn_counter": 1,
"dialog_request_counter": 1,
"_node_output_map": {
"Start And Initialize Context": [
0,
0
]
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"AConoff": "off",
"lightonoff": "off",
"musiconoff": "off",
"appl_action": "",
"heateronoff": "off",
"volumeonoff": "off",
"wipersonoff": "off",
"default_counter": 0
}
}
如您所见,message_output是随机问候语。无论我提出什么问题,我都会得到相同的文字。