RunSqlGeneration

Updated at:

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.

Debug

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 Resources is 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.

ActionAccess levelResource typeCondition keyDependent action
dataanalysisgbi:RunSqlGenerationnone
*All Resources
*
    None
None

Request syntax

POST /gbi/runSqlGeneration HTTP/1.1

Request parameters

NameTypeRequiredDescriptionExample value
workspaceIdstringYes

The ID of the Alibaba Cloud Model Studio workspace used for the current request.

llm-2v3934xtp49esw64
bodyobjectNo

Request body parameters.

specificationTypestringNo

The version information specified for the current request. If not specified, the default workspace version is used.

Valid values:
  • STANDARD_TURBO: Standard Edition turbo.
  • STANDARD_MIX: Standard Edition mix.
  • CUSTOMIZATION: Customized Edition turbo.
STANDARD_MIX
querystringYes

The query entered by the user.

What are the top ten products by sales?
sessionIdstringNo

The message session ID. Multiple request IDs can belong to the same session ID.

d5eced84-fd25-43ee-a245-adb4e4a8c3be

Response elements

NameTypeDescriptionExample value
object

SseEmitter

dataobject

Return information.

errorMessagestring

Error message.

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

Event type.

Valid values:
  • evidence: Information used for auxiliary model inference.
  • sql_part: Intermediate event for streaming SQL generation.
  • selector: Table selection event.
  • rewrite: Rewrite event.
  • sql: Final event for SQL generation.
sql
evidencestring

Information used for auxiliary model inference.

This 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

List of specific table names retrieved.

selectorstring

The name of the specific table retrieved.

table_name1
sessionIdstring

Conversation ID.

f64c38dd-a235-4bb4-ae6c-79eaedcba699
sqlstring

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
sqlErrorstring

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 codeError codeError messageDescription
401Internal.ErrorBad Request: Internal Error.Internal error. Contact customer service personnel for troubleshooting.
401NoAuthBad Request: Workspace.Illegal.Auth.The current account does not have permission to the specified business space.
401NoResourceAuthBad 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.
401SystemOperationInProgressXiyan 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.