RunSqlGeneration

更新时间:
复制 MD 格式

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.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

dataanalysisgbi:RunSqlGeneration

none

*All Resource

*

None None

Request syntax

POST /gbi/runSqlGeneration HTTP/1.1

Request parameters

Parameter

Type

Required

Description

Example

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 empty, the default workspace version is used.

Valid values:

  • STANDARD_TURBO :

    Standard Edition turbo

  • STANDARD_MIX :

    Standard Edition mix

  • CUSTOMIZATION :

    Customized Edition turbo

STANDARD_MIX

query

string

Yes

The query entered by the user.

请问销量前十的产品有哪些

sessionId

string

No

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

d5eced84-fd25-43ee-a245-adb4e4a8c3be

Response elements

Element

Type

Description

Example

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:

  • 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

evidence

string

Information used for auxiliary model inference.

今年是2024

requestId

string

The ID of the current request.

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

rewrite

string

The rewritten user input.

查询全部关键字数据,并以饼图形式展示

selector

array

List of specific table names retrieved.

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()

chat

object

text

string

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, please contact customer service personnel to troubleshoot
401 NoAuth Bad Request: Workspace.Illegal.Auth. The current account does not have the permission to the specified business space.
401 NoResourceAuth Bad Request: Resource Auth Error. If you do not have permission for the requested resource, make sure that the requested resource belongs to the business space in the current parameter.
401 SystemOperationInProgress Xiyan GBI is learning your previous modifications. Please try again later.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.