使用Dialogflow的标准版本
从以下示例向Dialogflow V2 API发送请求。
使用其他NLP服务时,他们将返回包含多个意图及其置信度得分的详细响应
def detect_intent_texts(project_id, session_id, texts, language_code):
"""Returns the result of detect intent with texts as inputs. Using the same `session_id` between requests allows continuation
of the conversation."""
import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
print('Session path: {}\n'.format(session))
for text in texts:
text_input = dialogflow.types.TextInput(
text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
print('=' * 20)
print('Query text: {}'.format(response.query_result.query_text))
print('Detected intent: {} (confidence: {})\n'.format(
response.query_result.intent.display_name,
response.query_result.intent_detection_confidence))
print('Fulfillment text: {}\n'.format(
response.query_result.fulfillment_text))
希望返回多个意图,但是Dialogflow仅返回得分最高的意图
{
"responseId": "",
"queryResult": {
"queryText": "This i my utterance!",
"parameters": {},
"allRequiredParamsPresent": true,
"intent": {
"name": "projects/project/agent/intents/22",
"displayName": "Intent1"
},
"intentDetectionConfidence": 0.8798916,
"languageCode": "en"
},
"alternativeQueryResults": [
{
"queryText": "This is my utterance!",
"languageCode": "en"
}
]
}
LUIS响应
{
"query": "This i my utterance!",
"topScoringIntent": {
"intent": "Intent1",
"score": 0.532636642
},
"intents": [
{
"intent": "Intent1",
"score": 0.532636642
},
{
"intent": "Intent2",
"score": 0.09986155
},
{
"intent": "Intent3",
"score": 0.0533027425
}
]
}
答案 0 :(得分:0)
对话流不会返回多个意图。它只会返回具有最高置信度得分的意图。