BlockQuery - 阻塞式对话
更新时间:2025-02-26
API访问域名
请求方式 | POST | 说明 |
---|---|---|
URI | https://api-ngd.baidu.com | |
后缀接口 | /core/v5/block/query |
说明
- 在阻塞式对话模式中,系统不是片段式地返回答案,而是一次性返回完整答案,但是需要等待所有步骤节点处理完成。阻塞式对话可以对整体内容进行全面分析,确保响应的准确性和一致性。
适用场景:
- 对响应时间不敏感的场景:适用于用户不要求立即得到回复,而是更关注答案准确性和完整性的情况。比如在企业内部的财务咨询场景中,员工询问复杂的税务计算问题,更希望得到完整、准确的计算方法和结果,而不是快速但可能不完整的回答。
- 需要依赖完整答案做决策的场景:若需要智能客服回答复杂的技术支持问题,如服务器故障排除,用户需要完整的解决方案来进行之后的维修操作,此场景下可使用阻塞式对话。
请求参数
Header参数
名称 | 类型 | 必填 | 中文名 | 说明 |
---|---|---|---|---|
token | string | 是 | bot_access_token | access_token: access_token是bot的属性,通过bot管理列表获取 |
Uid | string | 否 | c 端用户id | |
Username | string | 否 | c 端用户名称 | |
ACTIVE | boolean | 否 | 调用环境 | online/offline 分别代表线上环境和测试环境公有云环境该参数不生效 |
Body参数
名称 | 类型 | 必填 | 中文名 | 说明 |
---|---|---|---|---|
queryText | string | 否 | 用户问题 | 请求的问题,比如示例中的:你好 |
variables | object | 否 | 变量 | Map格式,key 是变量名称,value是变量值。对话中使用的变量,如果传了会覆盖当前中对话中已有的变量值 |
sessionId | string | 否 | 会话id | 首轮可以为空(如果首轮传了,后续需要使用首轮传的。),首轮会返回sessionId,后续对话需使用返回的sessionId。 |
chatSessionLatitudeSwitch | boolean | 否 | 单次session闲聊 | 该字段控制单次session闲聊是否开启,默认值:true |
topicId | string | 否 | 主题id | 对话测试时使用,执行指定的topic,和nodeId配合使用 |
engines | array | 否 | 使用的对话引擎 | String类型,FAQ("faq", "知识库-FAQ"),DOC_QA("docQa", "知识库-文档问答"),TASK_FLOW("taskflow", "流程画布"),TASK_BASED("task_based", "意图识别"),为null 或taskflow是支持所有引擎 |
multimodal | array | 否 | 多模态输入 | 当前支持图片,不能单独使用,需要和queryText 一起传递,目前仅标准版支持 |
multimodal \ fileKey | string | 否 | 文件唯一标识 | 使用/open/api/v2/file/upload接口上传后返回的key |
multimodal \ type | string | 否 | 文件类型 | 1 :图片,目前只支持图片,上传一张图片 |
startId | string | 否 | 节点id | 对话测试时使用,执行指定的节点id。和topicId配合使用 |
channel | string | 否 | 渠道 | 渠道管理中的渠道标识,传递该参数,可以命中FAQ中配置的条件答案 |
button | object | 否 | 按钮 | 按钮步骤会回复所有按钮的id,名称集合,点击按钮时需传递该字段 |
button \ id | string | 否 | 按钮id | |
button \ name | string | 否 | 按钮名称 | |
collect | boolean | 否 | 对话数据收集 | 是否收集会话数据,用于统计、标注 |
响应参数
名称 | 类型 | 必填 | 中文名 | 说明 |
---|---|---|---|---|
sessionId | string | 是 | 会话ID | 用于标识本轮会话的唯一ID |
queryId | string | 是 | 查询ID | 用于标识本次会话的唯一ID |
replyStatus | integer | 是 | 回复状态 | 回复状态, 默认成功 SUCCESS(200, "成功"); FAIL(4008001, "失败"); |
answer | array | 是 | 回答列表 | 包含各个回答块的数组 |
answer \ chunkId | integer | 是 | 流式chunkId | 流式chunkId |
answer \ status | string | 是 | 流式返回数据状态 | RUNNING("running"); DONE("done"); |
answer \ topicId | string | 否 | 主题ID | 对应的主题ID |
answer \ blockId | string | 否 | 区块ID | 对应的区块ID |
answer \ nodeId | string | 否 | 节点ID | 对应的节点ID |
answer \ reply | object | 否 | 回复 | 包含回复相关详细信息的对象 |
answer \ reply \ type | integer | 是 | 回复类型 | 1(文本)3(富文本)8(列表) |
answer \ reply \ text | string | 是 | 文本 | 文本/富文本答案 |
answer \ reply \ textList | array | 否 | 文本列表 | 回复的文本列表 |
answer \ reply \ buttons | array | 否 | 按钮列表 | replySource是BUTTONS时该字段有值 |
answer \ reply \ buttons \ id | string | 否 | 按钮id | |
answer \ reply \ buttons \ name | string | 否 | 按钮名称 | |
answer \ reply \ clarifyGuide | string | 否 | 澄清指南 | 提供澄清相关的指南和信息 |
answer \ reply \ replySource | string | 是 | 回复来源 | FAQ("faq", "知识库-FAQ"), DOC_QA("docQa", "知识库-文档"), TEXT_REPLY("text", "文本回复"), INTENT_CLARIFY("intentClarify", "意图澄清"), LARGE_MODEL_REPLY("largeModelReply", "大模型回复"), COLLECT_SLOT_ENTITY("collectSlotEntity", "收集槽位实体"), CHITCHAT("chitchat", "闲聊"), UNMATCHED("unmatch", "未匹配固定话术"), SENSITIVE("sensitive", "敏感拒答话术"), SYSTEM("system", "系统异常"), INSTRUCTION("instruction", "指令"); |
answer \ reply \ showDocumentSource | boolean | 否 | 显示文档源 | 是否显示文档来源 |
answer \ reply \ documents | array | 是 | 文档 | 知识问答信息,replySource是DOC_QA 该字段有值 |
answer \ reply \ documents \ document_id | string | 是 | 文档ID | 文档的唯一标识符 |
answer \ reply \ documents \ document_name | string | 是 | 文档名 | 文档的名称 |
answer \ reply \ documents \ knowledge_type | string | 是 | 文档类型 | 文档类型:doc 普通文档, web 网页知识 |
answer \ reply \ documents \ web_url | string | 是 | 文档链接 | 文档链接,当knowledgeType是web时有值 |
answer \ reply \ documents \ data | array | 是 | 数据 | 文档的数据内容 |
answer \ reply \ documents \ data \ segment_id | string | 是 | 段落ID | 段落的唯一标识符 |
answer \ reply \ documents \ data \ segment_content | string | 是 | 段落内容 | 段落的文本内容 |
answer \ reply \ documents \ data \ score | string | 是 | 得分 | 段落相关性得分 |
answer \ reply \ documents \ data \ segment_coord | string | 是 | 段落坐标 | 段落在文档中的位置坐标 |
answer \ reply \ documents \ data \ data | array | 是 | 数据 | 段落中的句子数据 |
answer \ reply \ documents \ data \ data \ sentence_id | string | 是 | 句子ID | 句子的唯一标识符 |
answer \ reply \ documents \ data \ data \ sentence_content | string | 是 | 句子内容 | 句子的文本内容 |
answer \ reply \ documents \ data \ data \ score | string | 是 | 得分 | 句子相关性得分 |
answer \ docDebug | object | 否 | 文档调试 | 提供文档调试相关信息,replySource是DOC_QA 该字段有值 |
answer \ faqSearch | array | 否 | FAQ搜索 | faq 检索信息,replySource是FAQ 该字段有值 |
answer \ slotCollectInfo | object | 否 | 槽收集信息 | 收集槽信息 |
answer \ slotCollectInfo \ waitCollectResultList | array | 是 | 待收集结果列表 | 列出待收集的结果 |
answer \ slotCollectInfo \ waitCollectResultList \ name | string | 是 | 名称 | 待收集的槽名称 |
answer \ slotCollectInfo \ waitCollectResultList \ result | string | 是 | 结果 | 已收集的结果 |
answer \ slotCollectInfo \ waitCollectResultList \ option | array | 否 | 可选值 | 可选的答案 |
answer \ slotCollectInfo \ waitCollectResultList \ optionSize | integer | 否 | 选项数量 | 选项数量 |
answer \ slotCollectInfo \ waitCollectResultList \ clarity | string | 否 | 清晰度 | 澄清话术 |
answer \ slotCollectInfo \ waitCollectResultList \ inputExample | string | 是 | 输入示例 | 输入的示例 |
answer \ slotCollectInfo \ waitCollectResultList \ outputExample | string | 是 | 输出示例 | 输出的示例 |
answer \ slotCollectInfo \ hasCollectResultList | array | 是 | 已收集结果列表 | 列出已收集的结果 |
instruction | object | 否 | 指令 | 发出指令后有值,指令详细信息 Map<String, Map<String, String>>, 外层key为指令标识,value为指令参数map |
variables | object | 是 | 变量 | Map<String, Object>存储会话期间的各种变量信息 |
endTime | string | 否 | 结束时间 | 会话结束时间 |
recommendList | array | 是 | 推荐列表 | 提供可能的操作或信息的推荐列表 |
rewriteQuery | string | 是 | 重写查询 | 用户输入的重写版本 |
intent | array | 是 | 意图 | 列出此次会话涉及的意图 |
intent \ _effect | integer | 是 | 影响 | 表示此意图的效果 |
intent \ id | string | 是 | ID | 意图的唯一标识符 |
intent \ name | string | 是 | 名称 | 意图的名称 |
intent \ description | string | 否 | 描述 | 意图的描述 |
intent \ agentId | string | 否 | 代理ID | 代理的ID |
intent \ created | string | 否 | 创建时间 | 意图创建时间 |
intent \ updated | string | 否 | 更新时间 | 意图最后更新时间 |
intent \ confidence | float | 是 | 置信度 | 意图识别的置信度 |
intent \ source | string | 是 | 来源 | 意图识别的来源 |
intent \ threshold | float | 是 | 阈值 | 意图识别的阈值 |
intent \ system | boolean | 是 | 系统意图 | 是否为系统预定义的意图 |
intent \ needClarify | boolean | 是 | 需要澄清 | 是否需要澄清此意图 |
intent \ alias | string | 否 | 别名 | 意图的别名 |
intent \ nameZh | string | 是 | 中文名称 | 意图的中文名称 |
intent \ examples | array | 否 | 示例 | 意图的示例 |
intent \ hasActiveCopy | boolean | 是 | 活跃副本 | 意图是否有活跃的副本 |
intent \ templateStr | string | 否 | 模板字符串 | 意图的模板字符串 |
intent \ createdUserName | string | 否 | 创建者用户名 | 创建此意图的用户的用户名 |
intent \ createdUserId | string | 否 | 创建者用户ID | 创建此意图的用户的用户ID |
intent \ lastEditUserName | string | 否 | 最后编辑用户名 | 最后编辑此意图的用户的用户名 |
intent \ lastEditUserId | string | 否 | 最后编辑用户ID | 最后编辑此意图的用户的用户ID |
intent \ version | integer | 是 | 版本 | 意图的版本 |
intent \ industryIntent | boolean | 是 | 行业意图 | 是否为特定行业的意图 |
intent \ knnExampleStr | string | 是 | KNN示例字符串 | 用于KNN匹配的示例字符串 |
intent \ extra | object | 否 | 额外信息 | 包含额外信息的对象 |
intent \ recSource | string | 否 | 推荐来源 | 意图推荐的来源 |
intent \ noResponse | boolean | 是 | 无响应 | 是否未响应 |
请求示例
Bash
1curl --location 'https://keyue.cloud.baidu.com/online/core/v5/block/query'
2--header 'token: xxxx'
3--header 'Content-Type: application/json'
4--data '{
5 "queryText": "你好",
6 "sessionId": "ecb95fcc-0e49-4ab0-b026-c20a8aac1585",
7 "variables": {
8 "homeAddress": "chengdu"
9 }
10}'
响应示例
成功示例
1{
2 "time": 1715169513855,
3 "data": {
4 "sessionId": "3b86845a-94c0-4120-a961-79ce479e2773",
5 "queryId": "7641ef40-e741-43cb-b0b5-59d86f3a6abe",
6 "replyStatus": 200,
7 "answer": [
8 {
9 "chunkId": 0,
10 "status": null,
11 "topicId": null,
12 "blockId": null,
13 "nodeId": "start00000000000000000000",
14 "reply": null,
15 "instruction": null
16 },
17 {
18 "chunkId": 1,
19 "status": null,
20 "topicId": "a52cce91-f235-4c6e-96b0-fdb026c0c09c",
21 "blockId": null,
22 "nodeId": "3rkayHkJR_9gQ707XXmnfEuVmhvyir4eYJiL",
23 "reply": null,
24 "instruction": null
25 },
26 {
27 "chunkId": 2,
28 "status": null,
29 "topicId": "a52cce91-f235-4c6e-96b0-fdb026c0c09c",
30 "blockId": "3rkayHkJR_9gQ707XXmnfEuVmhvyir4eYJiL",
31 "nodeId": "kJ_HMFObG5uGwRaoqG3synofT5PVZYoXk3Zy",
32 "reply": {
33 "type": 1,
34 "text": "这是一个文本",
35 "textList": null,
36 "clarifyGuide": null,
37 "replySource": "TEXT_REPLY",
38 "showDocumentSource": null,
39 "documents": null,
40 "docDebug": null,
41 "faqSearch": null,
42 "slotCollectInfo": null,
43 "instruction": null
44 },
45 "instruction": null
46 }
47 ],
48 "variables": {
49 "date": "2024-05-08",
50 "last_intent": "",
51 "week": "3",
52 "last_task_prompt": "这是一个文本",
53 "time": "19:58:33",
54 "last_response": "这是一个文本",
55 "last_user_response": ""
56 },
57 "endTime": "2024-05-08 19:58:33",
58 "recommendList": [],
59 "rewriteQuery": null,
60 "intent": null
61 },
62 "code": 200,
63 "msg": "OK"
64}