gregwdata/defog-sqlcoder-q8 🔢✓📝 → 📝

▶️ 12.5K runs 📅 Aug 2023 ⚙️ Cog 0.8.6 🔗 GitHub ⚖️ License
nl2sql text-generation text-to-sql

About

Defog's SQLCoder is a state-of-the-art LLM for converting natural language questions to SQL queries. SQLCoder is a 15B parameter fine-tuned on a base StarCoder model.

Example Output

Prompt:

"Which salesperson made the most sales?"

Output

SELECT salespeople.name,
sum(sales.quantity) AS total_sales
FROM salespeople join sales on salespeople.salesperson_id = sales.salesperson_id
GROUP BY salespeople.name
ORDER BY total_sales DESC
LIMIT 1;

Performance Metrics

22.27s Prediction Time
473.86s Total Time
All Input Parameters
{
  "seed": -1,
  "debug": false,
  "prompt": "Which salesperson made the most sales?",
  "num_beams": 5,
  "max_length": 1200,
  "prompt_template": "### Instructions:\nYour task is convert a question into a SQL query, given a Postgres database schema.\nAdhere to these rules:\n- **Deliberately go through the question and database schema word by word** to appropriately answer the question\n- **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`.\n- When creating a ratio, always cast the numerator as float\n\n### Input:\nGenerate a SQL query that answers the question `{user_question}`.\nThis query will run on a database whose schema is represented in this string:\n{table_metadata_string}\n\n### Response:\nBased on your instructions, here is the SQL query I have generated to answer the question `{user_question}`:\n```sql",
  "schema_metadata": "CREATE TABLE products (\n  product_id INTEGER PRIMARY KEY, -- Unique ID for each product\n  name VARCHAR(50), -- Name of the product\n  price DECIMAL(10,2), -- Price of each unit of the product\n  quantity INTEGER  -- Current quantity in stock\n);\n\nCREATE TABLE customers (\n   customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer\n   name VARCHAR(50), -- Name of the customer\n   address VARCHAR(100) -- Mailing address of the customer\n);\n\nCREATE TABLE salespeople (\n  salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson \n  name VARCHAR(50), -- Name of the salesperson\n  region VARCHAR(50) -- Geographic sales region \n);\n\nCREATE TABLE sales (\n  sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale\n  product_id INTEGER, -- ID of product sold\n  customer_id INTEGER,  -- ID of customer who made purchase\n  salesperson_id INTEGER, -- ID of salesperson who made the sale\n  sale_date DATE, -- Date the sale occurred \n  quantity INTEGER -- Quantity of product sold\n);\n\nCREATE TABLE product_suppliers (\n  supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier\n  product_id INTEGER, -- Product ID supplied\n  supply_price DECIMAL(10,2) -- Unit price charged by supplier\n);\n\n-- sales.product_id can be joined with products.product_id\n-- sales.customer_id can be joined with customers.customer_id \n-- sales.salesperson_id can be joined with salespeople.salesperson_id\n-- product_suppliers.product_id can be joined with products.product_id\n"
}
Input Parameters
seed Type: integerDefault: -1Range: -1 - ∞
Set seed for reproducible outputs. Set to -1 for random seed.
debug Type: booleanDefault: false
provide debugging output in logs
prompt (required) Type: string
Text prompt
num_beams Type: integerDefault: 5Range: 1 - ∞
Number of beams for beam search
max_length Type: integerDefault: 1200Range: 1 - ∞
Maximum number of tokens to generate. A word is generally 2-3 tokens
prompt_template Type: stringDefault: ### Instructions: Your task is convert a question into a SQL query, given a Postgres database schema. Adhere to these rules: - **Deliberately go through the question and database schema word by word** to appropriately answer the question - **Use Table Aliases** to prevent ambiguity. For example, `SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id`. - When creating a ratio, always cast the numerator as float ### Input: Generate a SQL query that answers the question `{user_question}`. This query will run on a database whose schema is represented in this string: {table_metadata_string} ### Response: Based on your instructions, here is the SQL query I have generated to answer the question `{user_question}`: ```sql
Prompt template for SQLcoder - see https://github.com/defog-ai/sqlcoder/blob/main/prompt.md . Must contain {user_question} and {table_metadata_string} parameters.
schema_metadata Type: stringDefault: CREATE TABLE products ( product_id INTEGER PRIMARY KEY, -- Unique ID for each product name VARCHAR(50), -- Name of the product price DECIMAL(10,2), -- Price of each unit of the product quantity INTEGER -- Current quantity in stock ); CREATE TABLE customers ( customer_id INTEGER PRIMARY KEY, -- Unique ID for each customer name VARCHAR(50), -- Name of the customer address VARCHAR(100) -- Mailing address of the customer ); CREATE TABLE salespeople ( salesperson_id INTEGER PRIMARY KEY, -- Unique ID for each salesperson name VARCHAR(50), -- Name of the salesperson region VARCHAR(50) -- Geographic sales region ); CREATE TABLE sales ( sale_id INTEGER PRIMARY KEY, -- Unique ID for each sale product_id INTEGER, -- ID of product sold customer_id INTEGER, -- ID of customer who made purchase salesperson_id INTEGER, -- ID of salesperson who made the sale sale_date DATE, -- Date the sale occurred quantity INTEGER -- Quantity of product sold ); CREATE TABLE product_suppliers ( supplier_id INTEGER PRIMARY KEY, -- Unique ID for each supplier product_id INTEGER, -- Product ID supplied supply_price DECIMAL(10,2) -- Unit price charged by supplier ); -- sales.product_id can be joined with products.product_id -- sales.customer_id can be joined with customers.customer_id -- sales.salesperson_id can be joined with salespeople.salesperson_id -- product_suppliers.product_id can be joined with products.product_id
Description of database schema. See https://github.com/defog-ai/sqlcoder/blob/main/metadata.sql
Output Schema

Output

Type: arrayItems Type: string

Version Details
Version ID
0a9abc0d143072fd5d8920ad90b8fbaafaf16b10ffdad24bd897b5bffacfce0b
Version Created
August 25, 2023
Run on Replicate →