使用DialogFlow detectintent无法正常工作

时间:2019-11-06 00:49:38

标签: nlp dialogflow agent

i使用DialogFlow v2(并尝试使用v2Beta1),使用python中的SDK,但问题是detectIntent方法无法识别查询输入中的参数。

因此,在寻找解决方案时,我使用简单的cUrl调用重新创建了问题。

接下来是创建EntityType的cUrl:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/entityTypes?languageCode=es" \
--data "{
    'displayName': 'customer',
    'kind': 'KIND_MAP',
    'autoExpansionMode': 'AUTO_EXPANSION_MODE_DEFAULT',
    'entities': [
        {
            'value': 'one',
            'synonyms': [
                'one', 'uno'
            ]
        },
        {
            'value': 'two',
            'synonyms': [
                'two', 'dos'
            ]
        }
    ],
    'enableFuzzyExtraction': true
}"

那很好,并且创建了EntityType。

现在,创建意图:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/intents" \
--data "{
    'displayName': 'ExampleIntent',
    'priority': 500000,
    'mlDisabled': false,
    'trainingPhrases': [
        {
            'type': 'EXAMPLE',
            'parts': [
                {
                    'text': 'start '
                },
                {
                    'text': 'one',
                    'alias': 'customer',
                    'entityType': '@customer',
                    'userDefined': true
                }
            ]
        },
        {
            'type': 'EXAMPLE',
            'parts': [
                {
                    'text': 'begin '
                },
                {
                    'text': 'one',
                    'alias': 'customer',
                    'entityType': '@customer',
                    'userDefined': true
                }
            ]
        },
        {
            'type': 'EXAMPLE',
            'parts': [
                {
                    'text': 'do '
                },
                {
                    'text': 'one',
                    'alias': 'customer',
                    'entityType': '@customer',
                    'userDefined': true
                }
            ]
        }
    ],
    'action': 'start',
    'messages': [
        {
            'text': {
                'text': [
                    'Hi'
                ]
            }
        }
    ],
}"

也可以。

现在,我尝试检测意图:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/sessions/0:detectIntent" \
    --data "{
        'queryInput': {
            'text': {
                'text': 'do one',
                'languageCode': 'es'
            }
        }
    }"

响应不带参数:

{
"responseId": "de68c5f5-6aa9-4716-ac22-626a22fc5d43-b81332aa",
"queryResult": {
    "queryText": "do one",
    "action": "start",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Hi",
    "fulfillmentMessages": [
    {
        "text": {
        "text": [
            "Hi"
        ]
        }
    }
    ],
    "intent": {
    "name": "projects/myproject_id/agent/intents/20ab36d6-e8c8-40d6-87dc-78a61e2de600",
    "displayName": "ExampleIntent"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "es"
}
}

我试图训练:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent:train"

结果是一样的。

但是,如果我转到Web控制台,请输入意图并单击“保存”按钮... detectIntent开始起作用。

{
"responseId": "45c919dc-677d-4ae4-8572-588955cd5414-b81332aa",
"queryResult": {
    "queryText": "do one",
    "action": "start",
    "parameters": {
    "customer": [
        "one"
    ]
    },
    "allRequiredParamsPresent": true,
    "fulfillmentText": "Hi",
    "fulfillmentMessages": [
    {
        "text": {
        "text": [
            "Hi"
        ]
        }
    }
    ],
    "intent": {
    "name": "projects/myproject_id/agent/intents/20ab36d6-e8c8-40d6-87dc-78a61e2de600",
    "displayName": "ExampleIntent"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "es"
}
}

我想念什么?

感谢任何线索使这项工作有效。

1 个答案:

答案 0 :(得分:0)

嗯...经过一些研究,我发现了问题,我在createIntent中缺少了 parameters 参数:

curl -X POST -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
"https://dialogflow.googleapis.com/v2beta1/projects/myproject_id/agent/intents" \
--data "{
    'displayName': 'ExampleIntent',
    'priority': 500000,
    'mlDisabled': false,
    'parameters': [
        {
            'displayName': 'customer',
            'entityTypeDisplayName': '@customer',
            'value': '$customer'
        }
    ],
    'trainingPhrases': [
        {