Skip to main content

RunDataAnalysis - Chat API

Xiyan provides an OpenAPI with the same conversational capabilities as its official interface. Pass workspaceId, query, and other relevant parameters to perform question answering and data analysis in an existing workspace. Use this operation when a data source is associated in the Xiyan console and Xiyan can access your database over the Internet or a VPC to execute SQL. For usage, see https://help.aliyun.com/en/model-studio/gbi-best-practices.

Usage notes

Before calling this operation, make sure that you understand the billing methods and pricing of Xiyan.

Try it out

You can call this operation in OpenAPI Explorer without calculating a signature. After a successful call, OpenAPI Explorer can automatically generate SDK code examples. Try it out

Authorization information

The following table describes the authorization information for this API operation. You can use this information in the Action element of a RAM policy statement to grant a RAM user or RAM role permission to call the operation. The columns are described as follows:
  • Action: a specific permission.
  • Access level: the access level of an action. Valid values: Write, Read, and List.
  • Resource type: the types of resources for which the action supports authorization:
    • Required resource types are marked with an asterisk (*).
    • Actions that do not support resource-level authorization use All resources.
  • Condition key: a condition key defined by the cloud service.
  • Dependent action: an additional permission required to perform the action. The caller must also have permission to perform the dependent action.
ActionAccess levelResource typeCondition keyDependent action
dataanalysisgbi:RunDataAnalysisnone
*All resources
*
    None
None

Request syntax

POST /{workspaceId}/gbi/runDataAnalysis HTTP/1.1

Request parameters

NameTypeRequiredDescriptionExample
workspaceIdstringYes

The Alibaba Cloud Model Studio workspace ID for this request.

llm-2v3934xtp49esw64
bodyobjectNo

The request body parameters.

specificationTypestringNo

The version to use for this request. If omitted, the default workspace version is used.

Valid values:
  • STANDARD_TURBO: Standard Edition turbo.
  • STANDARD_MIX: Standard Edition mix.
  • CUSTOMIZATION: Custom Edition turbo.
STANDARD_MIX
generateSqlOnlybooleanNo

Specifies that this request only generates and returns SQL without executing it.

true
querystringYes

The user query.

Which are the top ten best-selling products?
sessionIdstringNo

The conversation ID returned in the service window callback message.

sessionID
dataRolearrayNo

The data permission role names.

Note Configure data permissions on the product page before obtaining the parameters for API calls.
stringNo

The specific data permission role name.

Administrator
userParamsanyNo

The custom parameters required by the data role. Required if the role is configured with external parameters.

Note Configure data permissions on the product page before obtaining the parameters for API calls.
{ "shopId":[ "1", "2" ], "userId":"10001" }
agentCtrlParamsanyNo

The custom parameters passed through by the chat API. Currently supports skipping rewriting, skipping visualization, and enabling clarification of user questions.

{ "withoutRewrite": true, "withoutVisualization": true, "enableChatMode": true }

Response parameters

NameTypeDescriptionExample
object

Schema of Response

dataobject

The returned information.

errorMessagestring

The error message.

Access was denied, message: No such namespace namespaces/tech-scp-chain7.
eventstring

The event type.

Valid values:
  • result: final result event.
  • evidence: information used to assist model inference.
  • sql_part: intermediate event during streaming SQL generation.
  • sql_data: event containing SQL execution results.
  • selector: table selection event.
  • refine: retry event when retries are enabled.
  • rewrite: rewriting event.
  • sql: final SQL generation event.
rewrite
evidencestring

The information used to assist model inference.

The current year is 2024.
requestIdstring

The ID of the current request.

DA2578F7-88A5-5D6E-9305-33E724E97D60
rewritestring

The rewritten user input.

Query all keyword data and display it as a pie chart.
selectorarray

The tables retrieved for SQL generation in this conversation.

selectorstring

The name of a retrieved table.

table_name1
sessionIdstring

The conversation ID.

sessionid1
sqlstring

The SQL statement generated in this conversation.

select p.product_id, p.product_name, sum(o.quantity) as total_sales from products p join orders o on p.product_id = o.product_id where o.order_date between '2022-10-22' and '2024-10-22' group by p.product_id, p.product_name having total_sales > 5
sqlDataobject

The structured SQL execution results.

columnarray

The queried field names in the SQL execution results.

columnstring

A specific field name.

product
dataarray<object>

The structured data returned by SQL execution, which may contain multiple records.

valueobject

One record of structured data returned by SQL execution.

{ "product_id": "29", "total_sales": "63", "product_name":"1L迷你电热水壶" }
sqlErrorstring

The reason why the task failed.

Can not issue data manipulation statements with executeQuery()
visualizationobject

The information required by the visualization module.

dataobject

The structured information required by the visualization module.

plotTypestring

The chart type.

Valid values:
  • bar: bar chart.
  • line: line chart.
  • pie: pie chart.
bar
xAxisarray

The x-axis content of the chart.

xAxisstring

A field displayed on the x-axis.

product_name
yAxisarray

The y-axis content of the chart.

yAxisstring

A field displayed on the y-axis.

total_sales
stackboolean

Specifies whether to display a stacked bar chart. Takes effect only for bar charts.

false
optionstring

The configuration used to initialize the frontend component. Takes effect only when chartsFramework=echarts in the agentCtrlParams request parameter.

{ xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, series: [ { data: [150, 230, 224, 218, 135, 147, 260], type: 'line' } ] }
textstring

The analysis summary of the SQL execution results.

The query results show that all products with sales exceeding 5 in the past two years include: 2L large-capacity air fryer sold 109 units, Youth Edition sports wristband sold 119 units, 2L large-capacity fully automatic soy milk maker sold 106 units, wireless Bluetooth earphones fast-charging edition sold 84 units, 2L large-capacity portable juicer sold 136 units, Youth Edition smartwatch sold 104 units, wall-mounted eye-protection desk lamp sold 102 units, P30 phone 8+256G sold 83 units, 2L large-capacity electric kettle sold 84 units, men's electric makeup brush set sold 197 units, suitcase sold 82 units, bracelet sold 101 units, necklace sold 84 units, hair chain sold 89 units, wristwatch sold 98 units, ring sold 157 units, genuine leather handbag sold 136 units, trench coat and overcoat sold 76 units, sports travel bag sold 91 units, silk scarf sold 265 units, 1L mini air fryer sold 85 units, Deluxe Edition sports wristband sold 132 units, 1L mini fully automatic soy milk maker sold 81 units, Deluxe Edition wireless Bluetooth earphones (green) sold 122 units, 1L mini portable juicer sold 76 units, Deluxe Edition smartwatch sold 76 units, stick-on eye-protection desk lamp sold 109 units, M60 phone 16+512G sold 109 units, 1L mini electric kettle sold 63 units, and women's electric makeup brush set sold 158 units.
httpStatusCodelong

The HTTP status code for an individual event. Normally omitted and does not require processing.

200
attemptsarray

An event field returned when SQL validation is enabled. Contains the SQL generated during each retry and the error reason.

attemptsany

The SQL generated during each retry and the specific error information.

[{"sql":"SHOW TABLES","sqlError":"sql is invalid"},{"sql":"SHOW TABLES;","sqlError":"sql is invalid"}]
chatobject

A clarification event generated when the user question is ambiguous and clarification is enabled.

textstring

The clarification question generated when the model determines that the user question does not match the associated data, to help the user clarify the request.

Do you want to query the creation time field in the orders table?
messagestring

The system error message for troubleshooting. No user processing is required.

org.springframework.core.task.TaskRejectedException: ExecutorService in active state did not accept task: java.util.concurrent.CompletableFuture$AsyncSupply@25653b3b
codestring

The system error code for troubleshooting. No user processing is required.

NoAuth
httpStatusCodelong

The HTTP status code for the current request. Normally omitted and does not require processing.

200

Examples

Sample success response JSON format
{
  "data": {
    "errorMessage": "Access was denied, message: No such namespace namespaces/tech-scp-chain7.",
    "event": "rewrite",
    "evidence": "今年是2024年",
    "requestId": "DA2578F7-88A5-5D6E-9305-33E724E97D60",
    "rewrite": "查询全部关键字数据,并以饼图形式展示",
    "selector": [
      "table_name1"
    ],
    "sessionId": "sessionid1",
    "sql": "select p.product_id, p.product_name, sum(o.quantity) as total_sales from products p join orders o on p.product_id = o.product_id where o.order_date between '2022-10-22' and '2024-10-22' group by p.product_id, p.product_name having total_sales > 5",
    "sqlData": {
      "column": [
        "product"
      ],
      "data": [
        {
          "product_id": 29,
          "total_sales": 63,
          "product_name": "1L迷你电热水壶"
        }
      ]
    },
    "sqlError": "Can not issue data manipulation statements with executeQuery()",
    "visualization": {
      "data": {
        "plotType": "bar",
        "xAxis": [
          "product_name"
        ],
        "yAxis": [
          "total_sales"
        ],
        "stack": false,
        "option": "{\n  xAxis: {\n    type: 'category',\n    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']\n  },\n  yAxis: {\n    type: 'value'\n  },\n  series: [\n    {\n      data: [150, 230, 224, 218, 135, 147, 260],\n      type: 'line'\n    }\n  ]\n}"
      },
      "text": "查询结果显示,在过去两年中销量超过5的所有产品包括:2L大容量空气炸锅销售了109件,青春版运动手环销售了119件,2L大容量全自动豆浆机销售了106件,无线蓝牙耳机快充版销售了84件,2L大容量便携式榨汁机销售了136件,青春版智能手表销售了104件,挂壁式护眼台灯销售了102件,P30手机8+256G销售了83件,2L大容量电热水壶销售了84件,男士电动化妆刷套装销售了197件,旅行箱销售了82件,手链销售了101件,项链销售了84件,头饰发链销售了89件,腕表销售了98件,戒指销售了157件,真皮皮包销售了136件,风衣大衣销售了76件,运动旅行包销售了91件,丝巾销售了265件,1L迷你空气炸锅销售了85件,豪华款运动手环销售了132件,1L迷你全自动豆浆机销售了81件,豪华版无线蓝牙耳机(绿色)销售了122件,1L迷你便携式榨汁机销售了76件,豪华款智能手表销售了76件,粘贴式护眼台灯销售了109件,M60手机16+512G销售了109件,1L迷你电热水壶销售了63件,女士电动化妆刷套装销售了158件。"
    },
    "httpStatusCode": 200,
    "attempts": [
      [
        {
          "sql": "SHOW TABLES",
          "sqlError": "sql is invalid"
        },
        {
          "sql": "SHOW TABLES;",
          "sqlError": "sql is invalid"
        }
      ]
    ],
    "chat": {
      "text": "您想查询的是订单表的创建时间字段嘛?"
    }
  },
  "message": "org.springframework.core.task.TaskRejectedException: ExecutorService in active state did not accept task: java.util.concurrent.CompletableFuture$AsyncSupply@25653b3b",
  "code": "NoAuth",
  "httpStatusCode": 200
}

Error codes

HTTP status codeError codeError messageDescription
401NoAuthBad Request: Workspace.Illegal.Auth.The current account does not have permission to access the specified workspace.
401Internal.ErrorBad Request: Internal Error.An internal error occurred. Contact customer service for troubleshooting.
For more error codes, see Error Center.