首页 > 解决方案 > 找不到 EntityType - SessionEntityType 名称由 Session 名称和 EntityType.display_name 组成

问题描述

即使我在 中提供了正确的信息,我仍然SessionEntityTypes收到以下错误。尝试了 REST 和 Python 选项,如果集成中缺少任何内容,请告诉我。

请求 HTTP 方法:POST

{
  "name": "projects/{projectId}/locations/asia-northeast1/agent/environments/draft/users/-/sessions/c973fe-e44-9b5-34e-b404439b7/entityTypes/speciality_types",
  "entities": [
    {
      "value": "APPLE_KEY",
      "synonyms": [
        "apple",
        "green apple",
        "crabapple"
      ]
    },
    {
      "value": "ORANGE_KEY",
      "synonyms": [
        "orange"
      ]
    }
  ],
  "entityOverrideMode": "ENTITY_OVERRIDE_MODE_SUPPLEMENT"
}

回复

{
  "error": {
    "code": 400,
    "message": "com.google.apps.framework.request.BadRequestException: Cannot find the EntityType of SessionEntityType 'projects/{projectId}/locations/asia-northeast1/agent/environments/draft/users/-/sessions/c973fe-e44-9b5-34e-b404439b7/entityTypes/speciality_types'. Please note that the SessionEntityType name is composed of Session name and EntityType.display_name.",
    "status": "INVALID_ARGUMENT"
  }
}

谷歌试试这个 API

在此处输入图像描述

标签: google-cloud-platformgoogle-apidialogflow-esgoogle-api-python-client

解决方案


我将在这里解释这个问题,以确保我不会遗漏任何细节:您正在尝试使用“Try this API”工具创建一个 sessionEntity ,它是 Create (POST) 版本 2。

问题是您在请求正文中传递的“名称”没有API v2的有效格式。

您使用的名称格式是:
projects/<ProjectID>/locations/<LocationID>/agent/environments/<EnvironmentID>/users/<UserID>/sessions/<SessionID>/entityTypes/<EntityTypeDisplayName>

下面我列出了 v2 的两种有效名称格式,您可以看到不需要位置/<Location ID> :

projects/<Project ID>/agent/sessions/<Session ID>/entityTypes/<Entity Type Display Name>

projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>/entityTypes/<Entity Type Display Name>

以下请求正文按预期工作,我在同一个“试用此 API”工具中对其进行了测试:

{
"name":"projects/{projectId}/agent/environments/draft/users/-/sessions/c973fe-e44-9b5-34e-b404439b7/entityTypes/speciality_types",
  "entities":[
     {
        "value":"APPLE_KEY",
        "synonyms":[
           "apple",
           "green apple",
           "crabapple"
        ]
     },
     {
        "value":"ORANGE_KEY",
        "synonyms":[
           "orange"
        ]
     }
  ],
  "entityOverrideMode":"ENTITY_OVERRIDE_MODE_SUPPLEMENT"
}

推荐阅读