Dialogflow CX NLU
Manage intents and entity types in Google Dialogflow CX via REST API for natural language understanding.
Prerequisites
- - Google Cloud project with Dialogflow CX API enabled
- Service account or OAuth credentials with Dialogflow API access
- INLINECODE0 CLI authenticated OR bearer token
Authentication
Option 1: gcloud CLI (recommended)
CODEBLOCK0
Option 2: Service Account
CODEBLOCK1
API Base URL
CODEBLOCK2
Regional endpoints available:
- -
https://{region}-dialogflow.googleapis.com (e.g., us-central1, europe-west1)
Common Operations
List Intents
CODEBLOCK3
Create Intent
CODEBLOCK4
List Entity Types
CODEBLOCK5
Create Entity Type
CODEBLOCK6
Key Resources
| Resource | Description |
|---|
| Intents | Classify user utterances and extract parameters |
| Entity Types |
Define structured data extraction patterns |
Quick Reference
For detailed API reference:
Scripts
- -
scripts/nlu.py — CLI wrapper for intents and entity types operations
Usage
CODEBLOCK7
Tips
- - Use training phrases that cover various ways users might express the intent
- Entity types can be system (built-in) or custom
- Use KINDMAP for entities with synonyms, KINDLIST for simple lists
Dialogflow CX NLU
通过REST API管理Google Dialogflow CX中的意图和实体类型,实现自然语言理解。
前提条件
- - 已启用Dialogflow CX API的Google Cloud项目
- 具有Dialogflow API访问权限的服务账号或OAuth凭据
- 已认证的gcloud CLI或持有bearer令牌
身份认证
选项1:gcloud CLI(推荐)
bash
gcloud auth application-default login
TOKEN=$(gcloud auth print-access-token)
选项2:服务账号
bash
export GOOGLE
APPLICATIONCREDENTIALS=/path/to/service-account.json
TOKEN=$(gcloud auth application-default print-access-token)
API基础URL
https://dialogflow.googleapis.com/v3beta1
可用区域端点:
- - https://{region}-dialogflow.googleapis.com(例如:us-central1、europe-west1)
常见操作
列出意图
bash
curl -X GET \
https://dialogflow.googleapis.com/v3beta1/projects/${PROJECT
ID}/locations/${LOCATION}/agents/${AGENTID}/intents \
-H Authorization: Bearer ${TOKEN}
创建意图
bash
curl -X POST \
https://dialogflow.googleapis.com/v3beta1/projects/${PROJECT
ID}/locations/${LOCATION}/agents/${AGENTID}/intents \
-H Authorization: Bearer ${TOKEN} \
-H Content-Type: application/json \
-d {
displayName: 预订航班,
trainingPhrases: [
{
parts: [{text: 我想预订航班}],
repeatCount: 1
}
]
}
列出实体类型
bash
curl -X GET \
https://dialogflow.googleapis.com/v3beta1/projects/${PROJECT
ID}/locations/${LOCATION}/agents/${AGENTID}/entityTypes \
-H Authorization: Bearer ${TOKEN}
创建实体类型
bash
curl -X POST \
https://dialogflow.googleapis.com/v3beta1/projects/${PROJECT
ID}/locations/${LOCATION}/agents/${AGENTID}/entityTypes \
-H Authorization: Bearer ${TOKEN} \
-H Content-Type: application/json \
-d {
displayName: 城市,
kind: KIND_LIST,
entities: [
{value: 纽约},
{value: 洛杉矶}
]
}
关键资源
定义结构化数据提取模式 |
快速参考
有关详细的API参考:
脚本
- - scripts/nlu.py — 意图和实体类型操作的CLI封装
使用方法
bash
python scripts/nlu.py list-intents --agent AGENT_NAME
python scripts/nlu.py create-intent --agent AGENT_NAME --intent 预订航班 --phrases 预订航班,我想飞
python scripts/nlu.py list-entities --agent AGENT_NAME
python scripts/nlu.py create-entity --agent AGENT_NAME --name 城市 --values 纽约,洛杉矶
提示
- - 使用涵盖用户可能表达意图的各种方式的训练短语
- 实体类型可以是系统(内置)或自定义
- 对于带同义词的实体使用KINDMAP,对于简单列表使用KINDLIST