typetext
{
"debug": false,
"max_length": 1200,
"num_beams": 5,
"prompt": "Which salesperson made the most sales?",
"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",
"seed": -1
}npm install replicate
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_8wR**********************************
This is your API token. Keep it to yourself.
import Replicate from "replicate";
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN,
});
Run gregwdata/defog-sqlcoder-q8 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
const output = await replicate.run(
"gregwdata/defog-sqlcoder-q8:ad5a6671d23f7eeb47fde0b6e1ced085bdb14854bc1494ec3b96dfa2ed993a7a",
{
input: {
debug: false,
max_length: 1200,
num_beams: 5,
prompt: "Which salesperson made the most sales?",
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",
seed: -1
}
}
);
console.log(output);
To learn more, take a look at the guide on getting started with Node.js.
pip install replicate
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_8wR**********************************
This is your API token. Keep it to yourself.
import replicate
Run gregwdata/defog-sqlcoder-q8 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
output = replicate.run(
"gregwdata/defog-sqlcoder-q8:ad5a6671d23f7eeb47fde0b6e1ced085bdb14854bc1494ec3b96dfa2ed993a7a",
input={
"debug": False,
"max_length": 1200,
"num_beams": 5,
"prompt": "Which salesperson made the most sales?",
"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",
"seed": -1
}
)
# The gregwdata/defog-sqlcoder-q8 model can stream output as it's running.
# The predict method returns an iterator, and you can iterate over that output.
for item in output:
# https://replicate.com/gregwdata/defog-sqlcoder-q8/api#output-schema
print(item, end="")
To learn more, take a look at the guide on getting started with Python.
REPLICATE_API_TOKEN environment variable:export REPLICATE_API_TOKEN=r8_8wR**********************************
This is your API token. Keep it to yourself.
Run gregwdata/defog-sqlcoder-q8 using Replicate’s API. Check out the model's schema for an overview of inputs and outputs.
curl -s -X POST \
-H "Authorization: Bearer $REPLICATE_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Prefer: wait" \
-d $'{
"version": "gregwdata/defog-sqlcoder-q8:ad5a6671d23f7eeb47fde0b6e1ced085bdb14854bc1494ec3b96dfa2ed993a7a",
"input": {
"debug": false,
"max_length": 1200,
"num_beams": 5,
"prompt": "Which salesperson made the most sales?",
"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",
"seed": -1
}
}' \
https://api.replicate.com/v1/predictions
To learn more, take a look at Replicate’s HTTP API reference docs.
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;{
"id": "d6iwgy3be7agcrkdhtnz3q2fsm",
"model": "gregwdata/defog-sqlcoder-q8",
"version": "ad5a6671d23f7eeb47fde0b6e1ced085bdb14854bc1494ec3b96dfa2ed993a7a",
"input": {
"debug": false,
"max_length": 1200,
"num_beams": 5,
"prompt": "Which salesperson made the most sales?",
"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",
"seed": -1
},
"logs": "",
"output": "SELECT salespeople.name,\n sum(sales.quantity) AS total_sales\nFROM salespeople join sales on salespeople.salesperson_id = sales.salesperson_id\nGROUP BY salespeople.name\nORDER BY total_sales DESC\nLIMIT 1;",
"data_removed": false,
"error": null,
"source": "web",
"status": "succeeded",
"created_at": "2023-08-22T06:08:47.873893Z",
"started_at": "2023-08-22T06:16:19.463991Z",
"completed_at": "2023-08-22T06:16:41.738356Z",
"urls": {
"cancel": "https://api.replicate.com/v1/predictions/d6iwgy3be7agcrkdhtnz3q2fsm/cancel",
"get": "https://api.replicate.com/v1/predictions/d6iwgy3be7agcrkdhtnz3q2fsm"
},
"metrics": {
"predict_time": 22.274365,
"total_time": 473.864463
}
}