Skip to main content
 首页 » 编程设计

python之对话流 : How to add parameter automatically when using the dialogflow python API

2024年12月31日7langtianya

我想知道如何获得训练短语和参数之间的自动映射。当你简单地在训练短语中输入“学校”并且你有一个具有相同值的实体时,你会得到一个自动映射(在我将学校添加为训练短语后参见此处,我得到了一个到实体@school https://i.imgur.com/uY8Mq0S.png 的自动映射) .

我想要这个,但我正在使用 python API 来插入新的意图。有什么办法可以做到这一点,还是我需要手动检查是否有任何单词与实体匹配,然后为该意图手动创建该参数?这是我使用的代码片段。

import dialogflow_v2beta1 
 
client = dialogflow_v2beta1.IntentsClient() 
parent = client.project_agent_path('[project]') 
 
intent = { 
    "display_name": "test", 
    "webhook_state": True, 
    "training_phrases": [{"parts": [{"text": "school", "entity_type": "@school"}], "type": "EXAMPLE"}], 
    "parameters": [{"display_name": "school", "entity_type_display_name": "@school", "value": "$school"}] 
} 
 
response = client.create_intent(parent, intent) 

感谢您的阅读:)

请您参考如下方法:

训练短语实体注释是 Dialogflow UI 的一项功能,在 API 中不可用。

您需要在训练短语中手动注释实体,因为您已在问题中详细说明。