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