您可使用聊天补全接口获取问数过程中的实时结果,聊天补全接口为一个流式接口,事件流输出[DONE]或接口响应流终止代表结束。
当前此接口暂不支持多轮会话。
/dataAgent/llm/openApi/v2/signed/agent/chatCompletiontext/event-streamBody参数如下。
参数 | 类型 | 是否必选 | 示例值 | 描述 |
|---|---|---|---|---|
sessionId | int | 是 | 12886164 | 会话ID,填上面createSession返回的 |
type | string | 是 | query | 固定填写query即可。 |
data | object | 是 | 参见下文请求示例 | 补全的会话详情。 |
data.userInput | string | 是 | 参见下文请求示例 | 智能问数的问题。 |
data.enableClarify | boolean | 否 | true | 是否开启反问澄清,当此值为true,且智能体管理后台打开反问澄清开关,才会开启反问澄清。 |
data.enable_report_search | boolean | 否 | true | 是否开启图表检索,当此值为true,且智能体管理后台中配置了图表类的数据源,才开启图表检索。 |
data.clarifyResults | object | 否 | 参见下文请求示例 | 意图澄清结果,当上一轮会话结果返回的格式为编号为11的报文时,填充此字段说明用户在意图澄清交互过程中的选择结果。 |
data.clarifyResults.toolCallId | string | 是 | 参见下文请求示例 | 将上一轮会话结果中event中的toolCallId回填即可。 |
data.clarifyResults.skipClarify | boolean | 否 | false | 是否跳过反问澄清,让模型自己发挥,默认false。 |
data.clarifyResults.userChoices | array | 是 | 参见下文请求示例 | 对于模糊问题澄清内容的选择。 |
data.clarifyResults.userChoices[].type | string | 是 | 参见下文请求示例 | 将event中result.suggestions[].type字段回填即可。 |
data.clarifyResults.userChoices[].options | array | 是 | 参见下文请求示例 | 将用户选择的event中result.suggestions[].options的信息回填即可。 |
data.clarifyResults.userChoices[].description | string | 是 | 参见下文请求示例 | 将event中result.suggestions[].description字段回填即可。 |
{ "sessionId": 12886164, "type": "query", "data": { "userInput": "在超市数据集中,有哪些带“北”字的城市", "enableClarify": true, "enable_report_search": true, "clarifyResults": { // 首次问数可以为空。 "toolCallId": "", "skipClarify": false, "userChoices": [ { "type": "", "options": [ { "tableName": "", "tableId": int, "fieldName": "", "value": "", "appId": int, } ], "description": "" } ] } } }
本接口的返回Response(text/event-stream)遵循SSE协议,SSE协议详情可参考 SSE协议说明(外链)。返回结果为data:为前缀的报文,参数包含流式结果的关键报文结果,data的详细说明如下。
返回结果data详细说明如下。
说明
data返回的报文中包含的核心参数如下:
当前data的报文类型和示例说明如下。
编号 | 报文格式格式样例 | 关键参数说明 |
|---|---|---|
1 | {"type":"init","query_type":"normal","sub_query_info":[{"question": ${user_input} }],"is_thought_mode":true} |
|
2 | {"sub_id":0,"type":"result","status":"failed","msg":"错误信息","result":{}} |
|
3 | {"round_id": 0, "sub_id": 0, "is_major": true, "type": "thought", "content": "开始搜索图表......\n\n"} |
|
4 | {"round_id": 1, "sub_id": 0, "is_major": true, "type": "code", "content": "根据"} |
|
5 | {"round_id": 2, "sub_id": 0, "is_major": false, "type": "tool", "content": "准备调用工具: (round_id=2, sub_id=0)function::ansi_sql_execution,id::call_dw4nr47544y4itglz76up2n1"} |
|
6 | {"type": "debug", "content": "voting_result: all_full_equals True, major_index 1, diverge_index_list[], similar_index_list[]"} |
|
7 | {"round_id": 0, "sub_id": 0, "is_major": true, "type": "exec_context", "content": "-- 模型生成的SQL \n SELECT DISTINCT |
|
8 | {"round_id": 0, "sub_id": 0, "is_major": true, "type": "exec_result", "content": "工具调用执行结果"} |
|
9 | {"round_id": 1, "sub_id": 0, "type": "tool", "status": "tool_end", "msg": "{调用工具的参数和结果}"} |
|
9 | {"round_id": 1, "sub_id": 0, "is_major": true, "type": "interpret", "content": "根据查"} |
|
10 | {"round_id": 0, "sub_id": 0, "type": "result", "status": "success", "msg": "success", "result": {"historyId": 4225437, "dataSetId": 4250665}, "title": "在超市数据集中,有哪些带“北”字的城市", "round_title": "在超市数据集中,有哪些带“北”字的城市"} |
|
11 | {"round_id": null, "sub_id": 0, "type": "result", "status": "success", "msg": "success", "result": {"thought": "用户需要分析数据变化趋势,但未明确时间范围和分析的指标口径,根据表信息,有多个表包含日期字段和不同的指标字段,需要用户明确时间范围和指标口径。", "fuzzyRequirements": "需要明确时间范围和分析的指标口径。", "suggestions": [{"options": [{"tableId": 4530118, "value": "2015-09-30 到 2022-01-05", "tableName": "zhouyf_simple_test_01", "fieldName": "入职日期", "appId": 1008919}, {"tableId": 4494668, "value": "2015-01-01 到 2018-12-30", "tableName": "mxl0903回归", "fieldName": "订单日期", "appId": 555163}, {"tableId": 4494668, "value": "2015-01-03 到 2019-01-06", "tableName": "mxl0903回归", "fieldName": "发货日期", "appId": 555163}], "description": "你未明确时间范围,这里为你提供了几个可能的时间范围选项,请选择合适的时间范围。", "type": "时间范围"}, {"options": [{"tableId": 4530127, "tableName": "zhouyf_simple_test_03", "fieldName": "存款余额(元)", "appId": 1008919}, {"tableId": 4494668, "tableName": "mxl0903回归", "fieldName": "销售额", "appId": 555163}, {"tableId": 4530123, "tableName": "zhouyf_simple_test_02", "fieldName": "年收入(万元)", "appId": 1008919}], "description": "你未明确要分析的指标口径,这里为你提供了几个可能的指标选项,请选择合适的指标。", "type": "指标口径"}], "toolCallId": "call_41cplq8c5exulc5jnzc8py1d"}, "title": "", "round_title": ""} |
|
12 | {"sub_id": 0, "round_id": 0, "is_major": true, "type": "report", "status": "success", "result": {"reportId": 11587438, "appId": 555371, "reportName": "Top客户销售额", "dataSetName": "超市数据-知行 副本", "dataSetId": 2978669, "dashboardId": 0, "dashboardName": null, "role": true, "whereList": [{"id": "10000006952807", "name": "客户名称长度>2", "op": "==", "option": {"customList": [], "desensitizationList": [], "displayType": "multiDropDownList", "filterPattern": "Condition", "isReportFilter": false}, "preRelation": "and", "uniqueId": 250710205658092, "val": [1], "valOption": {"currentTab": "manual"}}]}} |
|
13 | [DONE] |
|
枚举值 | 含义 |
|---|---|
init | chat的初始化信号 |
report | 模型返回结果是图表 |
thought | 大模型思考过程,或调用工具的思考过程(执行思考)。 |
exec_context | 工具调用的执行过程信息(执行内容)。 |
exec_result | 工具调用的结果摘要(执行结果)。 |
result | 模型返回结果,包括反问澄清和最终结果两种情况
|
code | 一些模型输出,无需关注。 |
tool | MCP工具调用相关信息,用作关键消息透出,无需关注。 |
interpret | 数据解读,智能体管理后台的【基本信息】中打开【开启图表分析】开关时才会开启。 |
debug | 部分debug关键帧信息,包括:投票的产生与结果、流式心跳等。 |
当type = result时,status存在如下枚举值。
枚举值 | 含义 |
|---|---|
failed | 查询失败。 说明
|
success | 查询成功。 |
simple_text_shut_down | 简单问答结束。 |
当type = tool时,status存在如下枚举值。
枚举值 | 含义 |
|---|---|
tool_end | 工具调用结束 |
注意
您只需要关注round_id=0且is_major = true的消息即可。