SQL Generation API
The SQL Generation API allows you to manage SQL queries generated from natural language prompts or predefined SQL queries. This API provides endpoints for creating, retrieving, updating, and executing SQL generations.
Endpoints
1. Create SQL Generation
Endpoint: /api/v1/sql-generations
Method: POST
Request Body:
{
"llm_config": {
"model_name": "string",
"temperature": 0.7,
"max_tokens": 150
},
"evaluate": false,
"sql": "string",
"metadata": {"key": "value"}
}Description: Creates a new SQL generation configuration with optional LLM settings, SQL query, evaluation flag, and metadata.
Response:
{
"id": "string",
"prompt_id": "string",
"status": "string",
"llm_config": {
"model_name": "string",
"temperature": 0.7,
"max_tokens": 150
},
"intermediate_steps": [
{
"step_description": "string",
"step_result": "string"
}
],
"sql": "string",
"tokens_used": 123,
"confidence_score": 0.9,
"completed_at": "string",
"error": "string",
"created_at": "string"
}2. Retrieve All SQL Generations
Endpoint: /api/v1/sql-generations
Method: GET
Description: Retrieves a list of all SQL generations.
Response:
3. Retrieve a Specific SQL Generation
Endpoint: /api/v1/sql-generations/{sql_generation_id}
Method: GET
Description: Retrieves the details of a specific SQL generation identified by sql_generation_id.
Response:
4. Update a SQL Generation
Endpoint: /api/v1/sql-generations/{sql_generation_id}
Method: PUT
Request Body:
Description: Updates the details of an existing SQL generation identified by sql_generation_id.
Response:
5. Execute SQL Query
Endpoint: /api/v1/sql-generations/{sql_generation_id}/execute
Method: GET
Description: Executes the SQL query associated with the specified SQL generation.
Response:
6. Execute SQL Query and Store to CSV
Endpoint: /api/v1/sql-generations/{sql_generation_id}/store-execute
Method: GET
Description: Executes the SQL query associated with the specified SQL generation and store the result as csv file.
Response:
Example Usage
Creating a SQL Generation
To create a new SQL generation, send a POST request to /api/v1/sql-generations:
Request:
Response:
Retrieving All SQL Generations
To retrieve a list of all SQL generations, send a GET request to /api/v1/sql-generations:
Request:
Response:
Retrieving a Specific SQL Generation
To retrieve a specific SQL generation, send a GET request to /api/v1/sql-generations/{sql_generation_id}:
Request:
Response:
Updating a SQL Generation
To update a SQL generation, send a PUT request to /api/v1/sql-generations/{sql_generation_id}:
Request:
Response:
Executing a SQL Query
To execute the SQL query associated with a specific SQL generation, send a GET request to /api/v1/sql-generations/{sql_generation_id}/execute:
Request:
Response:
Executing a SQL Query and Store Into CSV
To execute the SQL query associated with a specific SQL generation and store into csv, send a GET request to /api/v1/sql-generations/{sql_generation_id}/store-execute:
Request:
Response:
This guide provides a comprehensive overview of how to use the SQL Generation API to handle SQL queries and their results effectively.
Last updated