使用 DialogFlow detectintent 无法正常工作

Using DialogFlow detectintent doesn't work properly

我使用 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"
}
}

我错过了什么?

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

嗯...经过一些研究,我发现了问题,我在 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': [
        {