You can use the chat completion API to obtain real-time results during the querying process. The chat completion API is a streaming interface; the event stream outputs [DONE] or the termination of the response stream indicates completion.
This API currently does not support multi-turn conversations.
/dataAgent/llm/openApi/v2/signed/agent/chatCompletiontext/event-streamThe body parameters are as follows.
Parameter | Type | Required | Example value | Description |
|---|---|---|---|---|
sessionId | int | Yes | 12886164 | Session ID. Enter the |
type | string | Yes | query | Enter "query" as a fixed value. |
source | string | Yes | openapi | Request source. Enter the fixed value "openapi". |
data | object | Yes | See the request example below | Details of the chat completion session. |
data.userInput | string | Yes | See the request example below | The question for intelligent query. |
data.enableClarify | boolean | No | true | Indicates whether to enable clarification by counter-questioning. Clarification by counter-questioning is enabled only when this value is true and the clarification switch is enabled in the agent management console. |
data.enable_report_search | boolean | No | true | Indicates whether to enable chart search. Chart search is enabled only when this value is true and a chart-type data source is configured in the agent management console. |
data.clarifyResults | object | No | See the request example below | Intent clarification result. When the previous session result is returned in the format of message number 11, fill in this field to indicate the user's selection during the intent clarification interaction. |
data.clarifyResults.toolCallId | string | Yes | See the request example below | Fill in the toolCallId from the event in the previous session result. |
data.clarifyResults.skipClarify | boolean | No | false | Indicates whether to skip clarification by counter-questioning and let the model decide. Default is false. |
data.clarifyResults.userChoices | array | Yes | Refer to the request example below | Selection of clarification content for ambiguous questions. |
data.clarifyResults.userChoices[].type | string | Yes | Refer to the request example below | Just fill back the result.suggestions[].type field in event. |
data.clarifyResults.userChoices[].options | array | Yes | Refer to the request example below | Just fill back the information from result.suggestions[].options in event based on the user's selection. |
data.clarifyResults.userChoices[].description | string | Yes | Refer to the request example below | Just fill back the result.suggestions[].description field in event. |
{ "sessionId": 12886164, "type": "query", "data": { "userInput": "在超市数据集中,有哪些带“北”字的城市", "enableClarify": true, "enable_report_search": true, "clarifyResults": { // The initial question count can be empty. "toolCallId": "", "skipClarify": false, "userChoices": [ { "type": "", "options": [ { "tableName": "", "tableId": int, "fieldName": "", "value": "", "appId": int, } ], "description": "" } ] } } }
The response (text/event-stream) from this API follows the SSE protocol. For details about the SSE protocol, refer to SSE protocol description (external link). The returned result is a message prefixed with data:. The parameters contain key message results of the streaming output. Details about data are as follows.
Detailed description of the returned data is as follows.
tip
The core parameters contained in the data response message are as follows:
type=result, it means the returned message is the model's result; status=success indicates that the model's result is a successful query.The current data message types and examples are described as follows.
Serial number | Sample message format | Key parameter description |
|---|---|---|
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":"Error message","result":{}} |
|
3 | {"round_id": 0, "sub_id": 0, "is_major": true, "type": "thought", "content": "Starting chart search......\n\n"} |
|
4 | {"round_id": 1, "sub_id": 0, "is_major": true, "type": "code", "content": "Based on"} |
|
5 | {"round_id": 2, "sub_id": 0, "is_major": false, "type": "tool", "content": "Preparing to call tool: (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 generated by the model \n SELECT DISTINCT |
|
8 | {"round_id": 0, "sub_id": 0, "is_major": true, "type": "exec_result", "content": "Tool invocation execution result"} |
|
9 | {"round_id": 1, "sub_id": 0, "type": "tool", "status": "tool_end", "msg": "{Parameters and results of tool invocation}"} |
|
9 | {"round_id": 1, "sub_id": 0, "is_major": true, "type": "interpret", "content": "Based on query"} |
|
10 | {"round_id": 0, "sub_id": 0, "type": "result", "status": "success", "msg": "success", "result": {"historyId": 4225437, "dataSetId": 4250665}, "title": "Which cities in the supermarket dataset contain the character '北'", "round_title": "Which cities in the supermarket dataset contain the character '北'"} |
|
11 | {"round_id": null, "sub_id": 0, "type": "result", "status": "success", "msg": "success", "result": {"thought": "The user needs to analyze data trends, but has not specified the time range or the metric definition for analysis. According to the table information, multiple tables contain date fields and different metric fields. The user needs to specify the time range and metric definition.", "fuzzyRequirements": "The time range and metric definition for analysis need to be specified.", "suggestions": [{"options": [{"tableId": 4530118, "value": "2015-09-30 to 2022-01-05", "tableName": "zhouyf_simple_test_01", "fieldName": "Employment date", "appId": 1008919}, {"tableId": 4494668, "value": "2015-01-01 to 2018-12-30", "tableName": "mxl0903回归", "fieldName": "Order date", "appId": 555163}, {"tableId": 4494668, "value": "2015-01-03 to 2019-01-06", "tableName": "mxl0903回归", "fieldName": "Shipping date", "appId": 555163}], "description": "You have not specified a time range. Here are several possible time range options for you. Please select the appropriate time range.", "type": "Time range"}, {"options": [{"tableId": 4530127, "tableName": "zhouyf_simple_test_03", "fieldName": "Deposit balance (yuan)", "appId": 1008919}, {"tableId": 4494668, "tableName": "mxl0903回归", "fieldName": "Sales amount", "appId": 555163}, {"tableId": 4530123, "tableName": "zhouyf_simple_test_02", "fieldName": "Annual income (RMB 10,000)", "appId": 1008919}], "description": "You have not specified the metric definition for analysis. Here are several possible metric options for you. Please select the appropriate metric.", "type": "Metric definition"}], "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 customer Sales amount", "dataSetName": "Supermarket data - Zhixing (copy)", "dataSetId": 2978669, "dashboardId": 0, "dashboardName": null, "role": true, "whereList": [{"id": "10000006952807", "name": "Customer name length > 2", "op": "==", "option": {"customList": [], "desensitizationList": [], "displayType": "multiDropDownList", "filterPattern": "Condition", "isReportFilter": false}, "preRelation": "and", "uniqueId": 250710205658092, "val": [1], "valOption": {"currentTab": "manual"}}]}} |
|
13 | [DONE] |
|
Enumeration value | Meaning |
|---|---|
init | Chat initialization signal |
report | The model returns a chart as the result |
thought | Large model thought process, or the thought process for tool invocation (execution thinking). |
exec_context | Execution process information for tool invocation (execution content). |
exec_result | Summary of tool invocation results (execution result). |
result | The model returns results, including clarification and final results
|
code | Some model outputs, no need to pay attention. |
tool | MCP tool invocation related information, used for key message exposure, no need to pay attention. |
interpret | Data interpretation is enabled only when the "Enable chart analysis" switch is turned on in the "Basic information" section of the agent management console. |
debug | Some debug key frame information, including the generation and results of voting, streaming heartbeat, and more. |
When type = result, status has the following enumeration values.
Enumeration value | Meaning |
|---|---|
failed | Query failed. tip
|
success | Query succeeded. |
simple_text_shut_down | Simple question and answer ended. |
When type = tool, status has the following enumeration values.
Enumeration value | Meaning |
|---|---|
tool_end | Tool invocation ended. |
warning
You only need to pay attention to messages with round_id=0 and is_major = true.