上云无忧 > 文档中心 > 百度智能云智能对话平台UNIT - 会话机器人对接
智能对话平台UNIT
百度智能云智能对话平台UNIT - 会话机器人对接

文档简介:
说明: 会话机器人支持个性化的开场欢迎语、热点问题推荐、会话中控、NLU分析, 具体如下: 特别说明,会话相关v2接口相关协议V6.4开已经不维护,建议对接v3协议。
*此产品及展示信息均由百度智能云官方提供。免费试用 咨询热线:400-826-7010,为您提供专业的售前咨询,让您快速了解云产品,助您轻松上云! 微信咨询
  免费试用、价格特惠

说明

会话机器人支持个性化的开场欢迎语、热点问题推荐、会话中控、NLU分析, 具体如下:

特别说明,会话相关v2接口相关协议V6.4开已经不维护,建议对接v3协议

  • 会话开始接口(可选):

    • /core/v3/start
    • /api/v2/core/start
  • 会话中控接口:

    • /core/v3/query
    • /api/v2/core/query
  • NLU分析 /api/v2/nlu/recognize

说明:

  • 在数据传输上,需保证入参sessionId(见接口说明)统一:

    • 若业务侧调用接口时不传sessionId,会话机器人会自动生成一个sessionId,业务侧需捕获第1个接口返回的sessionId,并作为后续接口调用的入参。
    • 若业务侧调用接口传入自定义的sessionId,则保证调用会话开始接口和会话中控接口使用同一个sessionId即可。
    • 整个session周期内请求的channel必须要一致,否则会导致统计数据有误。

请求header说明:

key value 说明
Authorization token_info NGD access_token: access_token是bot的属性,通过bot管理列表获取;
NGD develop_token: develop_token是agent的属性, 通过agent列表获取
Content-Type application/json;charset=UTF-8 post请求必须

上述方法使用的token对应关系如下表所示:

方法名 token配置
/core/v3/start bot_access_token
/api/v2/core/start bot_access_token
/api/v2/core/query bot_access_token
/core/v3/query bot_access_token
/api/v2/nlu/recognize develop_token

会话开始接口

接口说明

会话开始接口,用于获取欢迎语,热点推荐问题,支持只返回欢迎语, 只返回推荐问题或两者都返回。

接口地址

https://api-ngd.baidu.com/api/v2/core/start
https://api-ngd.baidu.com/core/v3/start

请求方法

GET/POST

请求参数说明(GET)

参数名 类型 必选 说明
type String 请求类别,不传或空返回欢迎语和推荐问,welcome:只返回欢迎语;recommend:只返回推荐问
sessionId String 会话id。
可不传值,由会话机器人生成;
若传值,使用业务方传入的sessionId,用户传入的sessionId必须保证唯一,如UUID.
channel String 渠道名称,保持整个会话周期一致
ext Map 调用方回传参数,格式为json,数据不做处理用来后期分析使用; 示例:调用会话时传入{ "uid",123 } 会话日志中ext将会存储该信息;用于后期分析

请求体(POST)

参数名 类型 必选 说明
type String 请求类别,不传或空返回欢迎语和推荐问,welcome:只返回欢迎语;recommend:只返回推荐问
sessionId String 会话id。
可不传值,由会话机器人生成;
若传值,使用业务方传入的sessionId,用户传入的sessionId必须保证唯一,如UUID.
channel String 渠道名称,保持整个会话周期一致
ext Map 调用方回传参数,格式为json,数据不做处理用来后期分析使用; 示例:调用会话时传入{ "uid",123 } 会话日志中ext将会存储该信息;用于后期分析
context Map 上下文信息

返回参数说明

参数名 类型 说明
code int 错误码
msg String 错误信息
data Map<String, Object> 返回欢迎语和推荐问信息

data

参数名 类型 说明
qaRecommend List<String> 推荐问题列表
qaRecommendTitle String 推荐问题列表引导话术
sessionId String 会话id
welcome String 欢迎语(旧字段,6.5开始废弃)
queryId String 请求id
queryTime String 请求时间
answerTime String 响应时间
source String 来源类型,默认system
richWelcome Map 欢迎语富文本类型,兼容welcome字段,(内容格式与answer → answerContents格式一致)

请求示例

curl -X POST http://api-ngd.baidu.com/api/v2/core/start -H 'authorization: NGD 142c8d88-cd69-4b1e-a4d5-443da096c3c6' \
-d '{
    "sessionId": "5cb6e7b8-e3da-45bb-ac07-98265ac54a01",
    "ext":{"uid":"0000001", "username":"ngd"}
}'

响应结果示例

{
    "time": 1574308601082,
    "data": {
        "qaRecommend": [
            "推荐问1?",
            "推荐问2?",
            "推荐问3?"
        ],
        "welcome": "您好,很高兴为您服务!这是demo哦",
        "sessionId": "5cb6e7b8-e3da-45bb-ac07-98265ac54a01",
        "botName": "租车bot",
        "botDesc": null,
        "botVersion": null,
        "queryId": "6cc36192-593e-498e-a0af-ae312eb88c47",
        "queryTime": null,
        "answerTime": null,
        "source": "system",
        "agentType": 1,
        "queryTime":"2019-11-21 11:11:11",
        "answerTime":"2019-11-21 11:11:12"
    },
    "code": 200,
    "msg": "OK"
}

会话中控接口

/core/v3/query

接口说明

  1. 接口返回值答案anser字段解析:

    • 若answerText存在值(下述两种方式任选其一): - 直接使用answer::answerText - 解析answer::answerContents列表,列表中答案类型根据具体type进行解析
    • 若answerText不存在值: - 解析clarify字段
  2. 外呼/呼出类型agent对接:

    • 会话开始时发起一次queryText为空的core/query接口请求,接口返回开场白节点欢迎语。
    • 如果上层所有话术使用TTS播放,只需关注: answerText, 若answerText为空,则解析clarify。
  3. 会话中控接口请求状态为400情况下,错误说明如下:
code msg 说明
4000019 用户请求过于频繁,请稍后再试 qps大于阈值
4000647 当前agent不存在可用的会话引擎 无可用会话引擎
4002409 bot token错误 非法bot token
4002413 该bot已停用,请启用后再试 bot已停用
4002010 包含敏感词,请检查 敏感词
4001104 webhook接口返回答案类型不合法 webhook服务错误
4000319 对话树配置的跳转存在死循环 对话树配置错误
4000346 会话引导异常,没有可以回退的场景,请检查开场白片段弱引导配置 引导配置错误

接口地址

https://api-ngd.baidu.com/core/v3/query

请求方法

POST

请求参数说明

参数名 类型 必选 说明
nlu Boolean 是否返回nlu识别信息(意图,实体,情感,态度)
debug Boolean 是否打开调试模式,返回调试信息
queryId String 请求id,用于出现问题时快速定位排查,不传则系统生成uuid;建议用户设置,语音场景可能因为超时,丢失answer信息,通过请求query指定queryId,方便问题排查

POST body参数说明

参数名 类型 必选 说明
queryText String 请求文本
sessionId String 会话id。
可不传值,由会话机器人生成;
若传值,使用业务方传入的sessionId,用户传入的sessionId必须保证唯一,如UUID.
sources List 对话模式:
1. task_based:多轮
2. kg:知识图谱
3. faq:问答
4. chitchat:闲聊
5. 空或无该字段为智能对话
channel String 渠道信息,整个session周期固定
context Map 上下文信息。与当前的会话session中的上下文进行合并,若存在key冲突,以传入的key为准
collect Boolean 是否收集会话数据,用于用户标注。默认为false
vad String 系统指令:
silent:静默
interrupt:打断
ext Map 调用方回传参数,格式为json,数据不做处理用来后期分析使用; 示例:调用会话时传入{ "uid",001 } 会话日志中ext将会存储该信息用于后期分析。

返回参数说明

参数名 类型 说明
code int 错误码
msg String 错误信息
data Map<String, Object> 返回答案的详细信息

data:

参数名 类型 说明
sessionId String 会话id
queryId String 请求id
source String 会话模式(faq,task_based,chitchat,kg,clarify(澄清),none(澄清失败、系统默认回复等),auto_fill(实体自动填充),system(bot系统事件)、botEvent(bot自定义事件)第三方引擎ID、技能ID)
solved Boolean 指定会话模式是否有答案.(多轮会话中,命中顶层节点且节点条件为anything_else,solved为false)
confidence Double 相似度
nlu Map 当前query的nlu识别信息
answer Map 回复答案
queryTime String 请求时间,格式:yyyy-MM-dd HH:mm:ss:SSS
responseTime String 响应时间,格式:yyyy-MM-dd HH:mm:ss:SS
context Map 会话上下文信息
associateData Map 随路数据收集
actions List 透传的指令
webhook Boolean 是否使用webhook
topAnythingElse Boolean 多轮是否命中顶层anythingElse节点
anythingElse Boolean 多轮是否命中anythingElse节点
debug Map 调试信息(开启debug模式后才会有值)

nlu:

参数名 类型 说明
intents List 识别的意图列表(格式同:debug → intents)
entities Map 识别的实体列表(格式同:debug → entities)
attitude Map 态度详情(格式同:debug → attitude)
sentiment Map 情感详情(格式同:debug → sentiment)
action Map 动作详情(格式同:debug → action)

answer:

参数名 类型 说明
clarify Map 澄清答案
clarifyType String 意图澄清:INTENT_CLARIFY
问答澄清:FAQ_CLARIFY
意图问答澄清:INTENT_FAQ_CLARIFY
faq高置信度澄清:FAQ_HIGH_CLARIFY
问答核心词澄清:FAQ_CORE_CLARIFY
意图模版澄清:TEMPLATE_INTENT_CLARIFY
问答模版澄清:TEMPLATE_FAQ_CLARIFY
意图问答模版澄清:TEMPLATE_INTENT_FAQ_CLARIFY
KG澄清:KG_CLARIFY
实体澄清:ENTITY_CLARIFY
第三方引擎澄清:THIRD_CLARIFY
技能澄清:SKILL_CLARIFY
answerContents List 答案列表,元素类型有:1: 纯文本类型,2: link类型,3: 富文本类型,4: 图片类型,6: 录音类型,7: 录音拼变量类型,8: 列表类型
answerText String 根据answerContents列表拼接的文本推荐答案)
recommendContents List 推荐答案列表,元素类型:8: 列表类型

clarify:

参数名 类型 说明
voice Map 语音回复
text Map 文字回复

voice:

参数名 类型 说明
content String 澄清语句

text:

参数名 类型 说明
title String 澄清标题
list List 澄清问题列表

answerContents:

type: 1,纯文本类型

参数名 类型 说明
type int 回复内容类型 1:纯文本
text String 回复内容

type: 2,link类型

参数名 类型 说明
type int 回复内容类型 2:link
text String 回复内容
url String url

type: 3,富文本类型

参数名 类型 说明
type int 回复内容类型 3:富文本
text String 富文本回复内容

type: 4,图片类型

参数名 类型 说明
type int 回复内容类型 4:图片
url String 图片url

type: 6,录音类型

参数名 类型 说明
type int 回复内容类型 6:录音
audio Map 录音内容

audio:

参数名 类型 说明
duration int 录音时长
name String 录音文件名称
id String 录音文件id
text String 录音内容文本
url String 录音url
textModify String 修改后的录音内容

type: 7,录音拼变量

参数名 类型 说明
type int 回复内容类型 7:录音拼变量
values List 回复内容列表,列表中元素由类型6与类型1组成,即录音类型与文本类型组成

type: 8,列表类型

参数名 类型 说明
type int 回复内容类型 8:列表类型
title String 回复标题
list List< String> 回复列表

debug:

参数名 类型 说明
botId String 会话bot的id
queryId String 请求id
nlu Map nlu分析当前query的详细结果
detail Map debug信息详情

nlu:

参数名 类型 说明
rawQuery String 原始query
nluQuery String nlu识别的query
nluChangedQuery String nlu上下文改写后的query
nluCorrectedQuery String nlu纠错后的query
intents List 识别的意图列表
clarifyIntents List 识别的澄清意图
clarifyTemplates List 识别的澄清模版意图
entities Map 识别的实体列表
clarifyEntities Map 识别的实体澄清列表
attitude Map 态度详情
sentiment Map 情感详情
action Map 动作详情
entityAutoFillVoMap Map 复合实体填充信息
sensitiveWordsList List<SensitiveVo> 敏感词详情

intents/clarifyIntents/clarifyTemplates:

参数名 类型 说明
id String 意图id
name String 意图标识
nameZh String 意图中文名称
description String 意图描述
system String 是否系统意图
source String 算法名称
alias String 意图别名
templateStr String 模版字符串

attitude:

参数名 类型 说明
prob String 置信度
source String 识别模型
name String 态度标识
nameZh String 态度中文名

sentiment:

参数名 类型 说明
prob String 置信度
source String 识别模型
name String 情感标识
nameZh String 情感中文名

action:

参数名 类型 说明
prob String 置信度
source String 识别模型
name String 动作标识
nameZh String 动作中文名

SensitiveVo:

参数名 类型 说明
sensitiveWord String 敏感词
repositoryName String 所属词库

detail:

多轮 task_based模式:

参数名 类型 说明
dialogs List 触发会话树节点详情
confidence Double 置信度
nlu Map 答案对应的nlu结果(结构同 debug-->nlu)
lastNodeId String 最近一次触发的会话树节点id

dialogs:

参数名 类型 说明
dialogNodeId String 会话树节点id
dialogNodeName String 会话树节点名
processId String 流程片段id
processName String 流程片段名
outputIndex int 执行模块下标
values List 当前会话树节点回复内容的格式配置
jumpBackValues String 外呼当前会话树节点跳回话术格式配置(字段格式和values⼀致)
webhook Boolean 是否使用webhook
action String 指令
webhookInfo Map webhook接口调用结果
tags List 节点标签

知识图谱 kg模式:

参数名 类型 说明
nlpSessionId String KG_DM的会话id
confidence Double 置信度
type String 答案类型。
SATISFY("satisfy", "答上来了")
CLARIFY("clarify", "需要澄清")
FAILURE("failure", "没答上来")
sayText String 答案话术
kgPatternType String 句式类型
kgClassName String 类目名称
kgPropertyName String 属性名称
kgPropertyArray String 属性名称多值
kgModQueryText String 改写后的Query
kgQueryPattern String 句式pattern
values List 回复内容(格式与answer → answerContents格式一致)

问答 faq模式:

参数名 类型 说明
id String 标准问ID
standardQuestion String 标准问问题
confidence double 相似度
extendQuestion String 扩展问问题
suggest List< String> 关联问题列表
answer Map 答案详情

answer 答案详情

参数名 类型 说明
type int 答案类别:
1:纯文本
3:富文本(html tag)
4:pic url link
6:audio
text String type为1或3时使用,回复内容
url String type为4时使用,图片url
audio Map type为6时使用,录音回复内容,(格式与suggestionAnswers → answerValues中的录音类型格式一致)

闲聊 chitchat模式:

参数名 类型 说明
id String 标准问ID
standardQuestion String 标准问问题
extendQuestion String 扩展问问题
confidence double 相似度
answer Map 答案详情

answer 答案详情:

参数名 类型 说明
type int 答案类别 1:纯文本
text String 回复内容

自动填充 auto_fill模式:

参数名 类型 说明
entityAutoFill Map 复合实体自动填充

entityAutoFill:

参数名 类型 说明
entityAutoFillVo Map 复合实体自动填充
entityAutoFillName String 自动填充实体
fillText String 自动填充文本

entityAutoFillVo:

参数名 类型 说明
entity Map 复合实体自动填充
entityFillType int 实体填充类型
propertyVoMap Map 属性详情列表
propertyNames List 属性名称列表
currentFillVo Map 当前填充话术

entity:

参数名 类型 说明
entityId String 实体id
entryId String 实体值id
value String 实体值
original String 实体原始值
name String 实体名称
nameZh String 实体中文名称
subName String 实体子名称
offset int 偏移量
system Boolean 是否系统实体
display String 实体显示值
type int 实体类型
combineValue String 复合实体组合值
extra Map 扩展属性

currentFillVo:

参数名 类型 说明
propertyName String 属性名称
fillText String 填充话术

澄清 clarify模式:

参数名 类型 说明
clarifyType String 澄清类型
clarifyQuestions Map 澄清
entityClarify Map 实体澄清
keywordConfirmQuestions List 模版澄清
highConfirmQuestions List 高置信度澄清

keywordConfirmQuestions/highConfirmQuestions:

参数名 类型 说明
sore String 分值
clickable Map 是否可点击
source Map 来源
question List 澄清内容

bot系统事件模式:

参数名 类型 说明
name String 策略名称
index int 策略序号
count int 当前计数次数
reply Map 策略配置

reply 策略配置:

参数名 类型 说明
count int 当前计数次数
symbol String 策略符号,例如:>,<等
isWebhook boolean 是否启用webhook
action String 指令
type int 返回答案类型
text String 文本返回答案内容,type为1时使用
audio Map 录音返回答案内容,type为6时使用,格式同:faq-→ answer→ audio

bot自定义事件模式: | 参数名 | 类型 | 说明 | | --- | --- | --- | | name | String | 事件名称 | | values | Map| 当前会话节点回复内容格式配置 | | webhook | Boolean| 是否使用webhook | | action | String| 指令 | | interrupted | Boolean| 打断标识 | | outputIndex | int| 执行策略序号 | | nlu | Map| nlu信息 |

技能模式: | 参数名 | 类型 | 说明 | | --- | --- | --- | | skillInfo | SkillInfo| 技能信息 | | engineInfo | Map| 技能命中的某个引擎调试信息(task_based、faq等),详见上述相关字段 | SkillInfo: | 参数名 | 类型 | 说明 | | --- | --- | --- | | skill | boolean | 是否是技能 | | skillName | String| 技能名 | | skillId | String| 技能Id | | sourceAgentId | String| 共享agentId | | shareAgentId | String| 当前使用agentId | | originSource | String| 对应资源命中的引擎名(task_based、faq等) |

answerInterventionRules:

参数名 类型 说明
name String 干预规则名称
type int 干预规则类型:
1:全部替换
2:增加前后缀
valueMaps Map 规则内容

valueMaps(type=1):

参数名 类型 说明
values Map 全文,见上文values答案描述介绍

valueMaps(type=2):

参数名 类型 说明
prefixValues Map 前缀,见上文values答案描述介绍
suffixValues Map 后缀,见上文values答案描述介绍

appendAnswers:

参数名 类型 说明
type int 回复类型:
1:文本
6:语音
7:录音拼变量
(更多type详见answer:dialogs:values参数描述)
text/audio/values String/Map/List 外呼类型机器人跳回话术回复内容

请求示例

curl -X POST 'https://api-ngd.baidu.com/core/v3/query?debug=true&nlu=true' 
-H 'Authorization:NGD 4f7f3cb9-4d1b-42e3-b03e-19771d8e7b07' 
-H 'Content-Type: application/json' 
-d '{"queryText":"租车","sessionId":"5cb6e7b8-e3da-45bb-ac07-98265ac54a01"}'

响应结果示例

任务式会话

{
  "time": 1586486514896,
  "data": {
    "sessionId": "11c8cddd-3d0c-493e-a33f-9a02ae5f99e5",
    "source": "task_based",
    "solved": true,
    "confidence": 1,
    "nlu": {
      "sentiment": {
        "query": "租车",
        "label": 0,
        "prob": 0.97234964,
        "source": "model",
        "name": "neutral",
        "nameZh": "中立"
      },
      "intents": [
        {
          "id": "e5304670-6841-40f6-ba49-11bbca32c6a8",
          "name": "rental",
          "description": "",
          "agentId": null,
          "created": null,
          "updated": null,
          "confidence": 1,
          "source": "knn",
          "threshold": 0,
          "system": false,
          "alias": "",
          "nameZh": "租车",
          "examples": null,
          "hasActiveCopy": false,
          "templateStr": null,
          "createdUserName": null,
          "createdUserId": null,
          "lastEditUserName": null,
          "lastEditUserId": null,
          "version": 0,
          "industryIntent": false
        }
      ],
      "entities": {},
      "attitude": {
        "query": "租车",
        "label": 0,
        "prob": 1,
        "source": "model",
        "name": "unknown",
        "nameZh": "无态度"
      }
    },
    "answer": {
      "answerText": "指令级别的兜底话术请输入车型",
      "answerContents": [
        {
          "original": "指令级别的兜底话术",
          "text": "指令级别的兜底话术",
          "type": 1
        },
        {
          "type": 1,
          "text": "请输入车型",
          "original": "请输入车型"
        }
      ]
    },
    "context": {
      "sys_counter": {
        "租车": 1,
        "检查车型实体节点_qwpg1bhv": 1
      },
      "api_response_status": false,
      "sys_webhook_eval_success": false
    },
    "associateData": {},
    "actions": [
      "aciton"
    ],
    "webhook": true,
    "debug": {
      "responseTime": "2020-04-10 10:41:54:896",
      "nlu": {
        "clarifyEntities": {},
        "sentiment": {
          "query": "租车",
          "label": 0,
          "prob": 0.97234964,
          "source": "model",
          "name": "neutral",
          "nameZh": "中立"
        },
        "intents": [
          {
            "id": "e5304670-6841-40f6-ba49-11bbca32c6a8",
            "name": "rental",
            "description": "",
            "agentId": null,
            "created": null,
            "updated": null,
            "confidence": 1,
            "source": "knn",
            "threshold": 0,
            "system": false,
            "alias": "",
            "nameZh": "租车",
            "examples": null,
            "hasActiveCopy": false,
            "templateStr": null,
            "createdUserName": null,
            "createdUserId": null,
            "lastEditUserName": null,
            "lastEditUserId": null,
            "version": 0,
            "industryIntent": false
          }
        ],
        "nluQuery": "租车",
        "entities": {},
        "clarifyIntents": [],
        "clarifyTemplates": [],
        "attitude": {
          "query": "租车",
          "label": 0,
          "prob": 1,
          "source": "model",
          "name": "unknown",
          "nameZh": "无态度"
        },
        "rawQuery": "租车"
      },
      "queryTime": "2020-04-10 10:41:49:860",
      "botId": "b4762b99-d0df-4d51-bb70-38000b5b3f79",
      "detail": {
        "nlu": {
          "clarifyEntities": {},
          "sentiment": {
            "query": "租车",
            "label": 0,
            "prob": 0.97234964,
            "source": "model",
            "name": "neutral",
            "nameZh": "中立"
          },
          "intents": {
            "id": "e5304670-6841-40f6-ba49-11bbca32c6a8",
            "name": "rental",
            "description": "",
            "agentId": null,
            "created": null,
            "updated": null,
            "confidence": 1,
            "source": "knn",
            "threshold": 0,
            "system": false,
            "alias": "",
            "nameZh": "租车",
            "examples": null,
            "hasActiveCopy": false,
            "templateStr": null,
            "createdUserName": null,
            "createdUserId": null,
            "lastEditUserName": null,
            "lastEditUserId": null,
            "version": 0,
            "industryIntent": false
          },
          "nluQuery": "租车",
          "entities": {},
          "clarifyIntents": [],
          "clarifyTemplates": [],
          "source": "knn",
          "attitude": {
            "query": "租车",
            "label": 0,
            "prob": 1,
            "source": "model",
            "name": "unknown",
            "nameZh": "无态度"
          },
          "rawQuery": "租车"
        },
        "confidence": 1,
        "lastNodeId": "",
        "dialogs": [
          {
            "dialogNodeName": "租车",
            "webhook": true,
            "values": {
              "original": "指令级别的兜底话术",
              "text": "指令级别的兜底话术",
              "type": 1
            },
            "description": null,
            "dialogNodeId": "3d2cdfb3-9158-4980-b78d-bb77586b1937",
            "processVersion": 4,
            "isBackTrack": false,
            "endNode": false,
            "outputIndex": 1,
            "processId": "b229f5ec-5fe8-4401-8df3-9d329a69c329",
            "processName": "fanlh",
            "action": "aciton",
            "processType": 0,
            "isResult": false,
            "value": "指令级别的兜底话术"
          },
          {
            "dialogNodeName": "检查车型实体节点_qwpg1bhv",
            "webhook": false,
            "values": {
              "type": 1,
              "text": "请输入车型",
              "original": "请输入车型"
            },
            "description": "检查车型实体节点",
            "dialogNodeId": "b017e30c-3550-4fce-be32-f09d84d1dce1",
            "processVersion": 4,
            "isBackTrack": false,
            "endNode": false,
            "outputIndex": 1,
            "processId": "b229f5ec-5fe8-4401-8df3-9d329a69c329",
            "processName": "fanlh",
            "processType": 0,
            "isResult": false,
            "value": "请输入车型"
          }
        ]
      },
      "queryId": "05903c5c-54b6-4565-8a27-c6d19fce01b2"
    },
    "code": 200,
    "msg": "OK"
  }
}

Faq:

{
  "time": 1586499361098,
  "data": {
    "sessionId": "11c8cddd-3d0c-493e-a33f-9a02ae5f99e5",
    "source": "faq",
    "solved": true,
    "confidence": 1,
    "nlu": {
      "sentiment": {
        "query": "问答吗",
        "label": 0,
        "prob": 0.9999976,
        "source": "model",
        "name": "neutral",
        "nameZh": "中立"
      },
      "intents": [],
      "entities": {},
      "attitude": {
        "query": "问答吗",
        "label": 0,
        "prob": 0.9965682,
        "source": "model",
        "name": "unknown",
        "nameZh": "无态度"
      }
    },
    "answer": {
      "answerText": "是的 这里是问答",
      "answerContents": [
        {
          "original": "是的 这里是问答",
          "text": "是的 这里是问答",
          "type": 1
        }
      ]
    },
    "context": {},
    "webhook": false,
    "debug": {
      "responseTime": "2020-04-10 14:16:01:098",
      "nlu": {
        "clarifyEntities": {},
        "sentiment": {
          "query": "问答吗",
          "label": 0,
          "prob": 0.9999976,
          "source": "model",
          "name": "neutral",
          "nameZh": "中立"
        },
        "intents": [],
        "nluQuery": "问答吗",
        "entities": {},
        "clarifyIntents": [],
        "clarifyTemplates": [],
        "attitude": {
          "query": "问答吗",
          "label": 0,
          "prob": 0.9965682,
          "source": "model",
          "name": "unknown",
          "nameZh": "无态度"
        },
        "rawQuery": "问答吗"
      },
      "queryTime": "2020-04-10 14:15:58:132",
      "botId": "b4762b99-d0df-4d51-bb70-38000b5b3f79",
      "detail": {
        "standardQuestion": "这里是问答吗?",
        "extentQuestion": "问答吗?",
        "answer": {
          "original": "是的 这里是问答",
          "text": "是的 这里是问答",
          "type": 1
        },
        "confidence": 1,
        "id": "12837cac-215b-4d41-81cb-16636ab5a21d",
        "suggest": []
      },
      "queryId": "49d7f755-7c92-4489-be9c-42924ca25083"
    }
  },
  "code": 200,
  "msg": "OK"
}

澄清:

{
    "queryId": "87aff1df-9517-499a-a09d-c0208187473e",
    "sessionId": "6cd8cd6a-ceff-4714-b39f-90313d0ee8bb",
    "source": "clarify",
    "solved": true,
    "confidence": 0,
    "answer": {
        "clarify": {
            "voice": "请问您想问的是租个车吗?",
            "text": {
                "title": "请问您想咨询的是?",
                "list": [
                    "租个车"
                ]
            }
        },
        "clarifyType": "INTENT_CLARIFY"
    },
    "queryTime": "2021-08-16 16:14:12:787",
    "answerTime": "2021-08-16 16:14:13:241",
    "actions": [],
    "webhook": false,
    "topAnythingElse": false,
    "anythingElse": false,
    "debug": {
        "botName": "call_in_bot",
        "nlu": {
            "clarifyEntities": {},
            "sentiment": {
                "query": "车",
                "label": 0,
                "prob": 0.9802588,
                "source": "model",
                "name": "neutral",
                "nameZh": "中立"
            },
            "intents": [],
            "nluQuery": "车",
            "clarifyIntents": [
                {
                    "_effect": 0,
                    "id": "23bba558-79a6-4507-82c2-33d66a310f12",
                    "name": "car_rental",
                    "description": "",
                    "agentId": null,
                    "created": null,
                    "updated": null,
                    "confidence": 0.717866837978363,
                    "source": "knn",
                    "threshold": 0,
                    "system": false,
                    "needClarify": false,
                    "alias": "租个车",
                    "nameZh": "租车",
                    "examples": null,
                    "hasActiveCopy": false,
                    "templateStr": null,
                    "createdUserName": null,
                    "createdUserId": null,
                    "lastEditUserName": null,
                    "lastEditUserId": null,
                    "version": 0,
                    "industryIntent": false,
                    "knnExampleStr": "租车",
                    "noResponse": false
                }
            ],
            "clarifyTemplates": [],
            "nluCorrectedQuery": null,
            "entities": {},
            "nluChangedQuery": null,
            "action": null,
            "sensitiveWordsList": [],
            "entityAutoFillVoMap": null,
            "attitude": {
                "query": "车",
                "label": 0,
                "prob": 1,
                "source": "model",
                "name": "unknown",
                "nameZh": "无态度"
            },
            "rawQuery": "车"
        },
        "botId": "c46e1b75-bf24-4562-aa88-834243aecf86",
        "detail": {
            "clarifyType": "INTENT_CLARIFY",
            "answerInterventionRules": null,
            "appendAnswers": null,
            "confirmQuestions": [
                {
                    "score": 0.717866837978363,
                    "clickable": true,
                    "source": "task_based",
                    "question": "租个车",
                    "faqId": null
                }
            ],
            "clarifyTypeDesc": "意图澄清",
            "highConfirmQuestions": null,
            "clarifyQuestions": {
                "voice": "请问您想问的是租个车吗?",
                "text": {
                    "title": "请问您想咨询的是?",
                    "list": [
                        "租个车"
                    ]
                }
            },
            "keywordConfirmQuestions": null,
            "entityClarify": null
        },
        "queryId": "87aff1df-9517-499a-a09d-c0208187473e"
    }
}

闲聊:

{
  "time": 1586502732524,
  "data": {
    "sessionId": "11c8cddd-3d0c-493e-a33f-9a02ae5f99e5",
    "source": "chitchat",
    "solved": true,
    "confidence": 1,
    "nlu": {
      "sentiment": {
        "query": "闲聊吗",
        "label": 0,
        "prob": 0.9999223,
        "source": "model",
        "name": "neutral",
        "nameZh": "中立"
      },
      "intents": [],
      "entities": {},
      "attitude": {
        "query": "闲聊吗",
        "label": 0,
        "prob": 0.9947141,
        "source": "model",
        "name": "unknown",
        "nameZh": "无态度"
      }
    },
    "answer": {
      "answerText": "这是闲聊",
      "answerContents": [
        {
          "type": 1,
          "text": "这是闲聊"
        }
      ]
    },
    "debug": {
      "responseTime": "2020-04-10 15:12:12:524",
      "nlu": {
        "clarifyEntities": {},
        "sentiment": {
          "query": "闲聊吗",
          "label": 0,
          "prob": 0.9999223,
          "source": "model",
          "name": "neutral",
          "nameZh": "中立"
        },
        "intents": [],
        "nluQuery": "闲聊吗",
        "entities": {},
        "clarifyIntents": [],
        "clarifyTemplates": [],
        "attitude": {
          "query": "闲聊吗",
          "label": 0,
          "prob": 0.9947141,
          "source": "model",
          "name": "unknown",
          "nameZh": "无态度"
        },
        "rawQuery": "闲聊吗"
      },
      "queryTime": "2020-04-10 15:12:09:114",
      "botId": "b4762b99-d0df-4d51-bb70-38000b5b3f79",
      "detail": {
        "standardQuestion": "闲聊吗",
        "extentQuestion": null,
        "answer": {
          "type": 1,
          "text": "这是闲聊"
        },
        "confidence": 1,
        "id": "0ea8b370-f0b4-44fe-a0b7-bf25ffa20365"
      },
      "queryId": "cb204ea7-f6ec-4a3a-a72f-9cf58647485f"
    }
  },
  "code": 200,
  "msg": "OK"
}

bot系统事件:

{
  "queryId": "ffd58556-2cd8-4c63-a6d1-d79e3c2cc424",
  "sessionId": "2375914d-ab78-4035-81dd-ede33297b0a0",
  "source": "system",
  "solved": true,
  "confidence": 0,
  "answer": {
    "answerText": "silent",
    "answerContents": [
      {
        "text": "silent",
        "type": 1
      }
    ],
    "recommendContents": []
  },
  "queryTime": "2021-08-16 16:39:25:445",
  "answerTime": "2021-08-16 16:39:25:535",
  "actions": [],
  "webhook": false,
  "topAnythingElse": false,
  "anythingElse": false,
  "debug": {
    "botName": "call_in_bot",
    "nlu": {
      "clarifyEntities": null,
      "sentiment": null,
      "intents": null,
      "nluQuery": "",
      "clarifyIntents": null,
      "clarifyTemplates": null,
      "nluCorrectedQuery": null,
      "entities": null,
      "nluChangedQuery": null,
      "action": null,
      "sensitiveWordsList": [],
      "entityAutoFillVoMap": null,
      "attitude": null,
      "rawQuery": ""
    },
    "botId": "c46e1b75-bf24-4562-aa88-834243aecf86",
    "detail": {
      "answerInterventionRules": null,
      "appendAnswers": null,
      "name": "silent",
      "count": 1,
      "index": 1,
      "reply": {
        "symbol": "=",
        "count": 1,
        "type": 1,
        "text": "silent",
        "audio": null,
        "isWebhook": false,
        "action": "",
        "actionName": ""
      }
    },
    "queryId": "ffd58556-2cd8-4c63-a6d1-d79e3c2cc424"
  }
}

/api/v2/core/query

接口说明 (V6.X系列开始不再维护v2协议,建议对接V3协议)

  1. 答案解析,按不同的source解析答案对应字段里的回复类型:

    • source=task_based 按序挨个解析拼接answer:dialogs节点列表里对应的不同values
    • source=faq 解析answer:answer
    • source=chitchat 解析answer:answer
    • source=clarify 解析clarifyQuestions:voice:content
    • source=system 解析answer:reply
    • source=none 解析suggestAnswer
  2. 呼出/外呼类型agent对接:

    • 会话开始时发起一次queryText为空的core/query接口请求,接口返回开场白节点欢迎语。
    • 如果上层所有话术使用TTS播放,只需关注: suggestAnswer, 若suggestAnswer为空,则检查clarifyQuestions
    • 否则参照第一点进行答案解析
特别说明: 若appendAnswers存在值,也需要在答案最后按照对应的方式解析拼接,若answerInterventionRules存在值,也需要在答案生成的最后按照其干预格式字段说明解析处理答案
  1. 会话中控接口请求状态为400情况下,错误说明如下:
code msg 说明
4000019 用户请求过于频繁,请稍后再试 qps大于阈值
4000647 当前agent不存在可用的会话引擎 无可用会话引擎
4002409 bot token错误 非法bot token
4002413 该bot已停用,请启用后再试 bot已停用
4002010 包含敏感词,请检查 敏感词
4001104 webhook接口返回答案类型不合法 webhook服务错误
4000319 对话树配置的跳转存在死循环 对话树配置错误
4000346 会话引导异常,没有可以回退的场景,请检查开场白片段弱引导配置 引导配置错误

接口地址

https://api-ngd.baidu.com/api/v2/core/query

请求方法

POST

POST body参数说明

参数名 类型 必选 说明
sessionId String 会话id。
可不传值,由会话机器人生成;
若传值,使用业务方传入的sessionId,用户传入的sessionId必须保证唯一,如UUID.
queryText String 请求文本
context Map 上下文信息。与当前的会话session中的上下文进行合并,若存在key冲突,以传入的key为准
sources List 对话模式:
1. task_based:多轮
2. kg:知识图谱
3. faq:问答
4. 空或无该字段为智能对话
collectConversation Boolean 是否收集会话数据,用于标注
channel String 渠道信息,整个session周期固定
ext Map 调用方回传参数,格式为json,数据不做处理用来后期分析使用; 示例:调用会话时传入{ "uid",123 } 会话日志中ext将会存储该信息;用于后期分析, 兼容5.1版本静默、挂机、打断配置
vad String silent:静默
interrupt:打断

返回参数说明

参数名 类型 说明
code int 错误码
msg String 错误信息
data Map<String, Object> 返回答案的详细信息

data

参数名 类型 说明
suggestAnswer String 回复文本
appendAnswers List 外呼拼接话术
answerInterventionRules Map 答案干预规则信息
source String 会话模式(faq,task_based,chitchat,clarify,auto_fill,system,none);
当source为clarify时,suggessAnswer及answer字段的值为空,回复内容取clarifyQuestions字段的值.
其余source对应答案的详细信息见下文
solved Boolean 指定会话模式是否有答案.(多轮会话中,命中顶层节点且节点条件为anything_else,solved为false)
confidence Double 相似度
clarifyQuestions Map 问题澄清,suggestAnswer存在时,该字段一定不存在
clarifyType String 澄清类型
queryId String 请求id
queryTime String 请求时间,格式:yyyy-MM-dd HH:mm:ss:SSS
answerTime String 响应时间,格式:yyyy-MM-dd HH:mm:ss:SS
sessionId String 会话id,使用uuid
actions List 透传的指令
answer Map 详细的回复信息
context Map 会话上下文信息和answer里context一致
botName String bot名称
webhook Boolean 是否使用webhook

appendAnswers:

参数名 类型 说明
type int 回复类型:
1:文本
6:语音
7:录音拼变量
(更多type详见answer:dialogs:values参数描述)
text/audio/values String/Map/List 外呼类型机器人跳回话术回复内容

answerInterventionRules:

参数名 类型 说明
name String 干预规则名称
type int 干预规则类型:
1:全部替换
2:增加前后缀
valueMaps Map 规则内容

valueMaps(type=1):

参数名 类型 说明
values Map 全文,见上文values答案描述介绍

valueMaps(type=2):

参数名 类型 说明
prefixValues Map 前缀,见上文values答案描述介绍
suffixValues Map 后缀,见上文values答案描述介绍

clarifyQuestions:

参数名 类型 说明
voice Map 语音回复
text Map 文字回复

voice:

参数名 类型 说明
content String 澄清语句

text:

参数名 类型 说明
questions List 问题
title String 标题

answer:

source为task_based:

参数名 类型 说明
dialogs List 触发会话树节点详情
context Map 会话上下文信息,(兼容旧版本,保留)
collectInfo Map 外呼信息收集
intent String 意图名称
intentMap Map 意图详情
entity Map 实体详情
lastNodeId String 最近一次触发的会话树节点id
lastEnterTopNodeName String 上个场景名
enterTopNodeIndex int 进入场景次数
enterTopNodeName String 场景名

dialogs:

参数名 类型 说明
dialogNodeId String 会话树节点id
dialogNodeName String 会话树节点名
processId String 流程片段id
processName String 流程片段名
value String 当前会话节点回复内容
values Map 当前会话节点回复内容格式配置
jumpBackValue String 外呼当前会话节点跳回话术
jumpBackValues Map 外呼当前会话节点跳回话术格式配置(字段格式和values⼀致)
webhook Boolean 是否使用webhook
action String 指令
outputIndex int 执行模块下标

values 详情:

type: 1,纯文本类型

参数名 类型 说明
type int 回复内容类型 1:纯文本
text String 回复内容

type: 2,link类型

参数名 类型 说明
type int 回复内容类型 2:link
text String 回复内容
url String url

type: 3,富文本类型

参数名 类型 说明
type int 回复内容类型 3:富文本
text String 富文本回复内容

type: 4,图片类型

参数名 类型 说明
type int 回复内容类型 4:图片
url String 图片url

type: 6,录音类型

参数名 类型 说明
type int 回复内容类型 6:录音
audio Map 录音内容

audio:

参数名 类型 说明
duration int 录音时长
name String 录音文件名称
id String 录音文件id
text String 录音内容文本
url String 录音url
textModify String 修改后的录音内容

type: 7,录音拼变量

参数名 类型 说明
type int 回复内容类型 7:录音拼变量
values List 回复内容列表, 列表中元素由类型6与类型1组成,即录音类型与文本类型组成

type: 8,列表类型

参数名 类型 说明
type int 回复内容类型 8:列表类型
title String 回复标题
list List< String> 回复列表

type: 9,多语义答案类型

参数名 类型 说明
type int 回复内容类型 9:多语义答案类型
list List< Object> 多语义答案列表,对应上述不同的type类型对象

answer:

source 为 faq:

参数名 类型 说明
standardQuestion String 标准问问题
extendQuestion String 扩展问问题
id String 标准问ID
suggest List< String> 关联问题列表
confidence double 相似度
answer Map 答案详情

answer 答案详情

参数名 类型 说明
type int 答案类别:
1:纯文本
3:富文本(html tag)
4:pic url link
6:audio
text String type为1或3时使用,回复内容
url String type为4时使用,图片url
audio Map type为6时使用,录音回复内容

audio:

参数名 类型 说明
duration int 录音时长
name String 录音文件名称
id String 录音文件id
text String 录音内容文本
url String 录音url
textModify String 修改后的录音内容

source 为 chitchat:

参数名 类型 说明
id String 标准问ID
standardQuestion String 标准问问题
extendQuestion String 扩展问问题
confidence double 相似度
answer Map 答案详情

answer 答案详情

参数名 类型 说明
type int 答案类别 1:纯文本
text String 回复内容

source 为 auto_fill(复合实体):

参数名 类型 说明
entityAutoFill Map 复合实体自动填充

entityAutoFill:

参数名 类型 说明
entityAutoFillVo Map 复合实体自动填充
entityAutoFillName String 自动填充实体名称
fillText String 自动填充文本

entityAutoFillVo:

参数名 类型 说明
entity Map 自动填充的复合实体
entityFillType int 实体填充类型
propertyNames Map 属性名称列表
propertyVoMap Map 属性详情列表
currentFillVo Map 当前填充话术

entity:

参数名 类型 说明
entityId String 实体id
entryId String 实体值id
value String 实体值
original String 实体原始值
name String 实体名称
nameZh String 实体中文名称
subName String 实体子名称
offset int 偏移量
system Boolean 是否为系统实体
display String 实体特殊显示值
type int 实体类型
extra Map 扩展属性
combineValue String 复合实体组合值

currentFillVo:

参数名 类型 说明
propertyName String 属性名称
fillText String 填充话术

source为system(系统指令,静默、打断、挂机)

参数名 类型 说明
name String 策略名称
index int 策略序号
count int 当前计数次数
reply Map 策略配置

reply 策略配置

参数名 类型 说明
count int 当前计数次数
symbol String 策略符号,例如:>,<等
isWebhook boolean 是否启用webhook
action String 指令
type int 答案类别:
1:纯文本
3:富文本(html tag)
4:pic url link
6:audio
text String type为1或3时使用,回复内容
url String type为4时使用,图片url
audio Map type为6时使用,录音回复内容

audio:

参数名 类型 说明
duration int 录音时长
name String 录音文件名称
id String 录音文件id
text String 录音内容文本
url String 录音url
textModify String 修改后的录音内容

请求示例

curl -X POST https://api-ngd.baidu.com/api/v2/core/query -H 'Authorization:
NGD 4f7f3cb9-4d1b-42e3-b03e-19771d8e7b07' -H 'Content-Type: application/json' -d 
'{"queryText":"","sessionId":"5cb6e7b8-e3da-45bb-ac07-98265ac54a01"}'

响应结果示例

任务式会话

{
    "time": 1574309239335,
    "data": {
        "suggestAnswer": "请问您要在什么时间租车?[外呼拼接跳回话术]",
        "appendAnswers": [
               {
                   "type": 1,
                   "text": "[外呼拼接跳回话术]"
               }
           ],
        "source": "task_based",
        "solved": true,
        "confidence": 1,
        "queryId": "37a4a7a0-16b0-4be2-85da-dea4f86f2454",
        "queryTime": "2019-11-21 12:07:19:197",
        "answerTime": "2019-11-21 12:07:19:335",
        "sessionId": "5cb6e7b8-e3da-45bb-ac07-98265ac54a01",
        "actions": [],
        "answer": {
            "intentMap": {
                "id": "a7603c96-e007-401c-8891-5f12a2e192c7",
                "name": "car_rental",
                "description": "",
                "agentId": null,
                "created": null,
                "updated": null,
                "confidence": 1,
                "source": "knn",
                "threshold": 0,
                "system": false,
                "alias": "",
                "nameZh": "租车意图",
                "examples": null,
                "hasActiveCopy": false,
                "templateStr": null,
                "createdUserName": null,
                "createdUserId": null,
                "lastEditUserName": null,
                "lastEditUserId": null
            },
            "intent":"car_rental",
            "enterTopNodeName": "租车意图",
            "lastEnterTopNodeName": null,
            "context": {
                "sys_counter": {
                    "check_租车意图_sys_date": 1,
                    "租车意图": 1
                }
            },
            "collectInfo": {},
            "enterTopNodeIndex": 1,
            "lastNodeId": null,
            "intent": "car_rental",
            "entity": {},
            "dialogs": [
                {
                    "dialogNodeName": "租车意图",
                    "webhook": false,
                    "description": null,
                    "dialogNodeId": "f106cbfc-ef9f-40e4-bb2c-8002561a543f",
                    "processVersion": 2,
                    "isBackTrack": false,
                    "endNode": false,
                    "jumpBackValue": null,
                    "outputIndex": 1,
                    "processId": "fb077db8-bcba-4740-b7e3-2ae9eba2ab75",
                    "processName": "租车场景",
                    "action": "",
                    "processType": 0,
                    "isResult": false,
                    "value": null
                },
                {
                    "dialogNodeName": "check_租车意图_sys_date",
                    "webhook": false,
                    "description": "检查sys_dateaa",
                    "dialogNodeId": "827db511-3982-4e48-b1ef-d6e89097485d",
                    "processVersion": 2,
                    "isBackTrack": false,
                    "endNode": false,
                    "jumpBackValue": null,
                    "outputIndex": 1,
                    "processId": "fb077db8-bcba-4740-b7e3-2ae9eba2ab75",
                    "processName": "租车场景",
                    "action": "",
                    "processType": 0,
                    "isResult": false,
                    "value": "请问您要在什么时间租车?"
                }
            ]
        },
        "context": {
            "sys_counter": {
                "check_租车意图_sys_date": 1,
                "租车意图": 1
            }
        },
        "botName": "租车bot",
        "botDesc": null,
        "botVersion": 1,
        "agentType": 1,
        "webhook": false
    },
    "code": 200,
    "msg": "OK"
}

Faq:

{
    "time": 1574309920227,
    "data": {
        "suggestAnswer": "是的。",
        "appendAnswers": null,
        "source": "faq",
        "solved": true,
        "confidence": 1,
        "queryId": "b01da250-8d68-417b-ad34-73ea81080ef6",
        "queryTime": "2019-11-21 12:18:40:104",
        "answerTime": "2019-11-21 12:18:40:227",
        "sessionId": "1a9a18a1-3b46-4b90-b71a-76e4e5f53ff9",
        "answer": {
            "standardQuestion": "这是问答库",
            "answer": {
                "text": "是的。",
                "type": 1
            },
            "faq": {
                "id": "774502fb-b971-41cd-bfdc-f4a2d680a755",
                "standardQuestion": "这是问答库",
                "extendQuestion": null,
                "faqId": "774502fb-b971-41cd-bfdc-f4a2d680a755",
                "template": null,
                "answerText": "是的。",
                "answerType": 1,
                "answer": {
                    "text": "是的。",
                    "type": 1
                },
                "confidence": 1,
                "suggest": [],
                "context": {},
                "isActiveHook": 0,
                "instruction": "",
                "confirmSimilarity": 0.6,
                "minSimilarity": 0.8,
                "similaritySource": "unit",
                "channelAnswer": false
            },
            "confidence": 1,
            "id": "774502fb-b971-41cd-bfdc-f4a2d680a755",
            "extendQuestion": null,
            "suggest": [],
            "isChannelAnswer": false
        },
        "context": {},
        "botName": "租车bot",
        "botDesc": null,
        "botVersion": 1,
        "agentType": 1,
        "webhook": false
    },
    "code": 200,
    "msg": "OK"
}

澄清:

{
  "time": 1581653248305,
  "data": {
    "suggestAnswer": null,
    "appendAnswers": null,
    "source": "clarify",
    "solved": true,
    "confidence": 0,
    "clarifyQuestions": {
      "voice": {
        "questions": [
          "请问您想问的是你是谁吗?"
        ],
        "content": "请问您想问的是你是谁吗?"
      },
      "text": {
        "questions": [
          "你是谁"
        ],
        "title": "请问您想咨询的是?"
      }
    },
    "confirmQuestions": [
      {
        "score": 1,
        "clickable": true,
        "source": "faq",
        "question": "你是谁"
      }
    ],
    "queryId": "3393911b-bc1c-4964-b9f3-dae2efd7c6c2",
    "queryTime": "2020-02-14 12:07:27:866",
    "answerTime": "2020-02-14 12:07:28:305",
    "sessionId": "1c55f8a3-3a74-49ab-b583-415304ecff70",
    "answer": null,
    "context": null,
    "botName": "bot16jj3r",
    "botDesc": null,
    "botPublishVersion": 1,
    "agentType": 3,
    "webhook": null
  },
  "code": 200,
  "msg": "OK"
}

闲聊:

{
    "time": 1574310130987,
    "data": {
        "suggestAnswer": "在呢在呢",
        "appendAnswers": null,
        "source": "chitchat",
        "solved": true,
        "confidence": 1,
        "queryId": "166c859c-6db1-4f46-aad8-4ac4fd19b04a",
        "queryTime": "2019-11-21 12:22:10:913",
        "answerTime": "2019-11-21 12:22:10:987",
        "sessionId": "e718f46a-89d6-4415-b804-c2b14240d679",
        "answer": {
            "chitchat": {
                "id": "e2cb06ca-caca-4cf5-898a-c00ad8261caa",
                "standardQuestion": "小度小度",
                "extendQuestion": null,
                "chitchatId": "e2cb06ca-caca-4cf5-898a-c00ad8261caa",
                "answerText": "在呢在呢",
                "confidence": 1
            },
            "standardQuestion": "小度小度",
            "answer": {
                "type": 1,
                "text": "在呢在呢"
            },
            "confidence": 1,
            "id": "e2cb06ca-caca-4cf5-898a-c00ad8261caa",
            "extendQuestion": null
        },
        "context": null,
        "botName": "租车bot",
        "botDesc": null,
        "botVersion": 1,
        "agentType": 1,
        "webhook": null
    },
    "code": 200,
    "msg": "OK"
}

系统设置:

{
    "time": 1574318085952,
    "data": {
        "suggestAnswer": "这是重述哦",
        "appendAnswers": null,
        "source": "system",
        "solved": true,
        "confidence": 1,
        "queryId": "afdbf45b-0a68-4017-a0ed-32fc9b74e1ed",
        "queryTime": "2019-11-21 14:34:45:884",
        "answerTime": "2019-11-21 14:34:45:952",
        "sessionId": "3cdd81e2-edbc-4d26-87a1-c6ce9ebaa0da",
        "answer": {
            "count": 2,
            "index": 1,
            "symbol": null,
            "reply": {
                "symbol": "=",
                "count": 2,
                "isWebhook": false,
                "type": 1,
                "text": "这是重述哦",
                "action": "",
                "url": "",
                "audio": null,
                "hangup": 1
            }
        },
        "context": null,
        "botName": "租车bot",
        "botDesc": null,
        "botVersion": 1,
        "agentType": 1,
        "webhook": null
    },
    "code": 200,
    "msg": "OK"
}

未匹配回复:

{
  "time": 1581654593238,
  "data": {
    "suggestAnswer": "抱歉,我不太理解您的意思",
    "appendAnswers": null,
    "source": "none",
    "solved": false,
    "confidence": 0,
    "queryId": "eed1e1da-2516-4eb1-80f6-684bc9762700",
    "queryTime": "2020-02-14 12:29:53:117",
    "answerTime": "2020-02-14 12:29:53:238",
    "sessionId": "1f4eb0a4-bb86-4f71-8475-0ee8feea109d",
    "answer": null,
    "context": null,
    "botName": "test",
    "botDesc": null,
    "botPublishVersion": 0,
    "agentType": 2,
    "webhook": null
  },
  "code": 200,
  "msg": "OK"
}

NLU 预测接口

接口地址

https://api-ngd.baidu.com/api/v2/nlu/recognize

请求方式

POST

请求参数说明

request body

参数名 类型 必选 说明
query string 用户query

返回参数说明

参数名 类型 必选 说明
code int 错误码
msg string 错误信息
data json 是,结构如下

data:

参数名 类型 必选 说明
rawQuery String 原始query
nluQuery String nlu分析query
intents List 识别出的意图列表
clarifyIntents List 识别出的意图澄清列表
clarifyTemplates List 识别出的模版澄清列表
entities Map 识别出的实体列表
clarifyEntities Map 识别出的实体澄清列表
nluEntityClarifyList List 识别出的实体澄清列表
sentiment Map 识别出的情感
attitude Map 识别出的态度
action Map 识别出的动作
sensitiveWords List< String> 识别出的敏感词
noResponse Boolean 是否意图不响应问

intents/clarifyIntents/clarifyTemplates:

参数名 类型 必选 说明
id String 意图id
name String 意图英文名称
nameZh String 意图中文名称
description String 意图描述
system Boolean 是否系统意图
source String 算法名称
alias String 意图别名
templateStr String 模版字符串

nluEntityClarifyList:

参数名 类型 必选 说明
entityId String 实体id
entryId String 实体值id
value String 识别出的实体值
original String 原始query实体值
name String 实体英文名称
nameZh String 实体中文名称
offset int 原始query实体偏移量
system Boolean 是否为系统实体
display String 实体显示值
extra Map 其他信息

sentiment:

参数名 类型 必选 说明
query String 用户query
prob String 置信度
source String 来自模型
name String 标签别名称
nameZh String 标签中文名, 消极、积极、中立

attitude:

参数名 类型 必选 说明
query String 用户query
prob String 置信度
source String 来自模型
name String 标签别名称
nameZh String 标签中文名,肯定、否定、无态度

action:

参数名 类型 必选 说明
query String 用户query
prob String 置信度
source String 来自模型
name String 动作英文名
nameZh String 动作中文名

请求示例

curl -i "https://api-ngd.baidu.com/api/v2/nlu/recognize" -H 'Authorization: NGD
 develop_token' -H 'Content-Type: application/json' -XPOST -d '{"query":"气温怎么样"}'

响应结果示例

{
    "time": 1582079541029,
    "data": {
        "rawQuery": "气温怎么样",
        "nluQuery": "气温怎么样",
        "intents": [
            {
                "id": "04ac48d8-c87a-42c0-b5fe-cb0eff396741",
                "name": "climate",
                "description": "",
                "agentId": "9a5b56e7-d682-419d-95ff-85877e1c563b",
                "created": "52104-02-07 08:40:00",
                "updated": "52104-02-07 08:40:00",
                "confidence": 1,
                "source": "template",
                "threshold": 0,
                "system": false,
                "alias": "cold",
                "nameZh": "查气候",
                "examples": null,
                "hasActiveCopy": false,
                "templateStr": "气温怎么样",
                "createdUserName": null,
                "createdUserId": null,
                "lastEditUserName": null,
                "lastEditUserId": null,
                "version": 0
            },
            {
                "id": "c3eee251-525d-4d67-aeae-419d8900e39f",
                "name": "get_weather",
                "description": null,
                "agentId": null,
                "created": null,
                "updated": null,
                "confidence": 1,
                "source": "template",
                "threshold": 0,
                "system": false,
                "alias": "查天气",
                "nameZh": "查天气",
                "examples": null,
                "hasActiveCopy": false,
                "templateStr": "气温怎么样",
                "createdUserName": null,
                "createdUserId": null,
                "lastEditUserName": null,
                "lastEditUserId": null,
                "version": 0
            }
        ],
        "clarifyIntents": [],
        "entities": {
            "whether": [
                {
                    "entityId": "f8bd843e-41cb-4d96-8b8f-765a85c975ed",
                    "entryId": "0e0f96bd-f126-4661-b374-1cb58078b893",
                    "value": "气温",
                    "original": "气温",
                    "name": "whether",
                    "nameZh": "天气",
                    "subName": null,
                    "offset": 0,
                    "system": false,
                    "display": null,
                    "extra": null
                }
            ],
            "climate": [
                {
                    "entityId": "89340252-3e32-47cb-9bbd-dacc12c72676",
                    "entryId": "6ef82bfe-b84a-4e72-b5a8-58527640132b",
                    "value": "气温",
                    "original": "气温",
                    "name": "climate",
                    "nameZh": "气候",
                    "subName": null,
                    "offset": 0,
                    "system": false,
                    "display": null,
                    "extra": null
                }
            ]
        },
        "clarifyEntities": {},
        "sentiment": {
            "query": "气温怎么样",
            "label": 0,
            "prob": 1,
            "source": "model",
            "name": "neutral",
            "nameZh": "中立"
        },
        "source": null,
        "attitude": {
            "query": "气温怎么样",
            "label": 0,
            "prob": 1,
            "source": "model",
            "name": "unknown",
            "nameZh": "无态度"
        },
        "sensitiveWords": [],
        "entityClarifyList": [],
        "nluEntityClarifyList": [],
        "clarifyTemplates": [
            {
                "id": "04ac48d8-c87a-42c0-b5fe-cb0eff396741",
                "name": "climate",
                "description": "",
                "agentId": "9a5b56e7-d682-419d-95ff-85877e1c563b",
                "created": "52104-02-07 08:40:00",
                "updated": "52104-02-07 08:40:00",
                "confidence": 1,
                "source": "template",
                "threshold": 0,
                "system": false,
                "alias": "cold",
                "nameZh": "查气候",
                "examples": null,
                "hasActiveCopy": false,
                "templateStr": "气温怎么样",
                "createdUserName": null,
                "createdUserId": null,
                "lastEditUserName": null,
                "lastEditUserId": null,
                "version": 0
            },
            {
                "id": "c3eee251-525d-4d67-aeae-419d8900e39f",
                "name": "get_weather",
                "description": null,
                "agentId": null,
                "created": null,
                "updated": null,
                "confidence": 1,
                "source": "template",
                "threshold": 0,
                "system": false,
                "alias": "查天气",
                "nameZh": "查天气",
                "examples": null,
                "hasActiveCopy": false,
                "templateStr": "气温怎么样",
                "createdUserName": null,
                "createdUserId": null,
                "lastEditUserName": null,
                "lastEditUserId": null,
                "version": 0
            }
        ],
        "noResponse": false
    },
    "code": 200,
    "msg": "OK"
}

常见问题

  • 问题1: 访问core/start,core/query接口返回错误信息「bot token错误」? - 原因1: bot未发布。 - 原因2: bot token错误。bot token可以在Bot管理列表中复制Token获取。
相似文档
  • 本章介绍 UNIT企业版产品表达式配置使用规范。 表达式可以用在会话树节点配置中,节点触发条件和节点执行回复内容的配置。 平台使用的表达式标识: 无前缀:表示内置DialogState对象的属性(welcome, conversation_start, anything_else, true, false, query等)。 【百度智能云】智能客服
  • 在意图、问答和复合实体中,允许通过配置规则模板的方式来定义可以匹配的用户表述(query)的内容,从而可以实现通过规则的方式快速建立识别能力,对于一些特殊的case有比较好的针对性处理效果。 【百度智能云】智能客服
  • 本产品除了提供通过枚举方式实现的普通实体和预置的系统实体以外,还为高级用户提供了规则实体和复合实体的功能。本文将介绍这两类实体的使用方法和注意事项。 【百度智能云】智能客服
  • 第一步:服务层搭建。 说明: 本平台支持第三方会话引擎可插拔方式接入集成。调用ngd core/query接口时,UNIT企业版作为客户端会去第三方会话引擎进行查询,获取响应,根据优先级规则处理,返回用户;支持第三方会话引擎session管理。具体介绍如下:
  • 在对话过程中,往往需要用户表达相关的实体信息来决定对话流程的分支;用户表达的过程由于方言、表达方式的不同,或者是建设时语料预计不足或泛化能力不够,容易造成无法识别导致流程异常结束,用户流失。因此推出此功能,希望尽量引导用户完成流程。 【百度智能云】智能客服
官方微信
联系客服
400-826-7010
7x24小时客服热线
分享
  • QQ好友
  • QQ空间
  • 微信
  • 微博
返回顶部