简体   繁体   English

Dialogflow API - 类型错误:BatchUpdateIntentsRequest 的构造函数输入无效:意图

[英]Dialogflow API - TypeError: Invalid constructor input for BatchUpdateIntentsRequest: intents

I am trying to train Dialogflow using its API to pass some of the limitations of training with the UI when you have a preexisting training dataset.我正在尝试使用其 API 训练 Dialogflow,以在您拥有预先存在的训练数据集时通过 UI 训练的一些限制。 The upload dataset feature seems to be quite limited.上传数据集功能似乎非常有限。

With the minimum setup, trying to make create intents from the API, I am getting the following error:使用最小设置,尝试从 API 创建意图,我收到以下错误:

Traceback (most recent call last):
  File "main.py", line 102, in <module>
    update_agent()
  File "main.py", line 87, in update_agent
    response = client.batch_update_intents(
  File "env/lib/python3.8/site-packages/google/cloud/dialogflow_v2/services/intents/client.py", line 1114, in batch_update_intents
    request = intent.BatchUpdateIntentsRequest(request)
  File "env/lib/python3.8/site-packages/proto/message.py", line 520, in __init__
    raise TypeError(
TypeError: Invalid constructor input for BatchUpdateIntentsRequest: intents {
  name: "projects/project-name/agent/intents/welcome"
  display_name: "Welcome"
  training_phrases {
    parts {
      text: "Training phrase 1"
    }
  }
  messages {
    text {
      text: "B"
      text: "o"
      text: "t"
      text: " "
      text: "R"
      text: "e"
      text: "s"
      text: "p"
      text: "o"
      text: "n"
      text: "s"
      text: "e"
    }
  }
}

This is the python code I used: emphasized text这是我使用的 python 代码:强调文本

def update_agent():

    intentBatch = dialogflow.types.intent.IntentBatch()

    training_phrases = [
        dialogflow.types.intent.Intent.TrainingPhrase(
            parts=[
                dialogflow.types.intent.Intent.TrainingPhrase.Part(
                    text="Training phrase 1"
                )
            ]
        )
    ]

    intent = dialogflow.types.intent.Intent(
        name="projects/{}/agent/intents/{}".format(PROJECT_ID, "welcome"),
        display_name="Welcome",
        webhook_state="WEBHOOK_STATE_ENABLED",
        training_phrases=training_phrases,
        messages=[
            dialogflow.types.intent.Intent.Message(
                text=dialogflow.types.intent.Intent.Message.Text(text="Bot Response"))
        ]
    )

    intentBatch.intents.append(intent)

    client = dialogflow.IntentsClient()
    response = client.batch_update_intents(
        request=intentBatch
    )

    print("Intent updated")

    print(response)

I followed this documentation to check the expected schema, I left out some of the optional fields and included all the required fields, but it doesn't seem to solve the problem.我按照此文档检查了预期的架构,我省略了一些可选字段并包含了所有必填字段,但它似乎并没有解决问题。

Also, is the "messages" from the API response being split into a dictionary of its characters expected?此外,来自 API 响应的“消息”是否被拆分成预期的字符字典?

You should nest intentBatch in BatchUpdateIntentsRequest object. Then the new BatchUpdateIntentsRequest object could now be passed to batch_update_intents() .您应该将intentBatch嵌套在BatchUpdateIntentsRequest object 中。然后新的BatchUpdateIntentsRequest object 现在可以传递给batch_update_intents() Also, intent is sequence type so it should be inside [] , this is the same case with messages that is why it was split into a dictionary of characters.另外, intent序列类型,所以它应该在[]里面,这与消息的情况相同,这就是为什么它被分成字符字典的原因。

See modified code below:请参阅下面的修改代码:

from google.cloud import dialogflow_v2 as dialogflow

def update_agent():

    intentBatch = dialogflow.types.IntentBatch()


    training_phrases = [
        dialogflow.types.intent.Intent.TrainingPhrase(
            parts=[
                dialogflow.types.intent.Intent.TrainingPhrase.Part(
                    text="Training phrase 1"
                )
            ]
        )
    ]

    intent = [dialogflow.types.intent.Intent(
        name="projects/<your-project>/agent/intents/<>",
        display_name="welcome",
        webhook_state="WEBHOOK_STATE_ENABLED",
        training_phrases=training_phrases,
        messages=[
            dialogflow.types.intent.Intent.Message(
                text=dialogflow.types.intent.Intent.Message.Text(text=["Bot Response"]))
        ]

    )]


    #intentBatch.intents.append(intent)
    intentBatch = dialogflow.types.intent.IntentBatch(intents=intent)


    client = dialogflow.IntentsClient()
    response = client.batch_update_intents(

        request=dialogflow.types.BatchUpdateIntentsRequest(intent_batch_inline=intentBatch, parent="projects/<your-project>/agent")
    )

    print("Intent updated")

    print(response)

update_agent()

Result:结果: 在此处输入图像描述

Intent update in UI: UI 中的意图更新: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Dialogflow - 通过 API 检测意图不适用于知识库意图 - Dialogflow - Detect intents via API is not working for knowledge base intents python API 无法在 Dialogflow v2 中显示非英语列表意图 API - python API cant show non English language of list intents API in Dialogflow v2 如何使用 DialogFlow 处理大量意图? - How to deal with a huge number of intents using DialogFlow? Dialogflow - 通过 v2 API 创建带有输入上下文的 Intent - Dialogflow - creating an Intent with an input context, via v2 API Dialogflow 使用外部 API 和 Axios - Dialogflow using external API with Axios 类型错误:日志记录不是构造函数 - TypeError: Logging is not a constructor 有什么方法可以在 Dialogflow 代理之间进行合并吗? 或者至少将意图从一个代理人导出到另一个代理人? - Is there any way to merge between Dialogflow agents? Or at least export intents from one agent to another? 403 IAM 对“projects/None/agent”的权限“dialogflow.intents.list”被拒绝 - 403 IAM permission 'dialogflow.intents.list' on 'projects/None/agent' denied 从 Dialogflow 中的文本输入获取坐标 - Getting coordinates from text input in Dialogflow Dall E API 错误:“无效的输入图像 - 格式必须在 [‘RGBA’、‘LA’、‘L’] 中,得到 RGB。” - Dall E API error: "Invalid input image - format must be in ['RGBA', 'LA', 'L'], got RGB."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM