RunSqlGeneration
This operation generates SQL statements based on the current query information and associated data tables. This API is suitable for scenarios where your database is stored locally and cannot be accessed by Xiyan. You can associate a virtual data source with Xiyan, call this API to generate the SQL statements, and then parse and execute them locally. For more information, see the best practices document.
Debug
You can run this API directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After a successful run, OpenAPI Explorer can automatically generate SDK code examples.
RAM authorization
The following table describes the authorization information for this API. You can use the Action element in RAM policy statements to grant RAM users or RAM roles the permission to call this API. Details are as follows:
-
Action: The specific permission point.
-
Access level: The access level of each operation. Valid values: Write, Read, or List.
-
Resource type: The resource types that support authorization for the operation. Details are as follows:
- Required resource types are marked with a leading asterisk (*).
- For operations that do not support resource-level authorization,
All Resourcesis used.
-
Condition key: The condition keys defined by the cloud service itself.
-
Dependent action: The other permissions required to successfully perform the operation. The caller must also have the permissions of the dependent actions for the operation to succeed.
| Action | Access level | Resource type | Condition key | Dependent action |
|---|---|---|---|---|
| dataanalysisgbi:RunSqlGeneration | none | *All Resources * |
| None |
Request syntax
POST /gbi/runSqlGeneration HTTP/1.1
Request parameters
| Name | Type | Required | Description | Example value |
|---|---|---|---|---|
| workspaceId | string | Yes | The ID of the Alibaba Cloud Model Studio workspace used for the current request. | llm-2v3934xtp49esw64 |
| body | object | No | Request body parameters. | |
| specificationType | string | No | The version information specified for the current request. If not specified, the default workspace version is used. Valid values:
| STANDARD_MIX |
| query | string | Yes | The query entered by the user. | What are the top ten products by sales? |
| sessionId | string | No | The message session ID. Multiple request IDs can belong to the same session ID. | d5eced84-fd25-43ee-a245-adb4e4a8c3be |
Response elements
| Name | Type | Description | Example value |
|---|---|---|---|
| object | SseEmitter | ||
| data | object | Return information. | |
| errorMessage | string | Error message. | Access was denied, message: No such namespace namespaces/tech-scp-chain7. |
| event | string | Event type. Valid values:
| sql |
| evidence | string | Information used for auxiliary model inference. | This year is 2024 |
| requestId | string | The ID of the current request. | DA2578F7-88A5-5D6E-9305-33E724E97D60 |
| rewrite | string | The rewritten user input. | Query all keyword data and display it as a pie chart |
| selector | array | List of specific table names retrieved. | |
| selector | string | The name of the specific table retrieved. | table_name1 |
| sessionId | string | Conversation ID. | f64c38dd-a235-4bb4-ae6c-79eaedcba699 |
| sql | string | The SQL statement generated for the current 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 |
| sqlError | string | If the task execution fails, this field reports the reason for the failure. | Can not issue data manipulation statements with executeQuery() |
Examples
Success response
JSON format
{
"data": {
"errorMessage": "Access was denied, message: No such namespace namespaces/tech-scp-chain7.",
"event": "sql",
"evidence": "今年是2024年",
"requestId": "DA2578F7-88A5-5D6E-9305-33E724E97D60",
"rewrite": "查询全部关键字数据,并以饼图形式展示",
"selector": [
"table_name1"
],
"sessionId": "f64c38dd-a235-4bb4-ae6c-79eaedcba699",
"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",
"sqlError": "Can not issue data manipulation statements with executeQuery()",
"chat": {
"text": ""
}
}
}
Error codes
| HTTP status code | Error code | Error message | Description |
|---|---|---|---|
| 401 | Internal.Error | Bad Request: Internal Error. | Internal error. Contact customer service personnel for troubleshooting. |
| 401 | NoAuth | Bad Request: Workspace.Illegal.Auth. | The current account does not have permission to the specified business space. |
| 401 | NoResourceAuth | Bad Request: Resource Auth Error. | You do not have permission for the requested resource. Make sure the requested resource belongs to the business space specified in the current parameters. |
| 401 | SystemOperationInProgress | Xiyan GBI is learning your previous modifications. Please try again later. | Xiyan GBI is learning your previous modifications. Please try again later. |
Visit Error Center to view more error codes.