CoolFace
Apppublic

mlnsio/text2sql

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
prompt.py70 linesDownload Raw Back to text2sql
1def get_prompt(question):2    database_schema = """3CREATE TABLE core_mutualfund (4    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),5    created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,6    updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,7    fund_name VARCHAR(200) UNIQUE,8    isin_number VARCHAR(50) UNIQUE,9    security_id VARCHAR(50) UNIQUE,10    data JSONB,11    rank INTEGER UNIQUE,12    crisil_rank INTEGER,13    aum DOUBLE PRECISION,14    expense_ratio DOUBLE PRECISION,15    nav DOUBLE PRECISION,16    return_m12 DOUBLE PRECISION17);18 19CREATE TABLE core_mfholdings (20    "id" uuid NOT NULL PRIMARY KEY,21    "isin_number" varchar(20) NULL,22    "security_id" varchar(20) NULL,23    "sector" varchar(50) NULL,24    "country" varchar(50) NULL,25    "currency" varchar(100) NULL,26    "weighting" double precision NULL,27    "sector_code" varchar(100) NULL,28    "holding_type" varchar(100) NULL,29    "market_value" double precision NULL,30    "stock_rating" varchar(100) NULL,31    "total_assets" double precision NULL,32    "currency_name" varchar(150) NULL,33    "holding_name" varchar(100) NULL,34    "holding_type" varchar(100) NULL,35    "holding_type_id" varchar(100) NULL,36    "number_of_shares" double precision NULL,37    "one_year_return" double precision NULL,38    "mutual_fund_id" uuid NOT NULL REFERENCES "core_mutualfund" ("id") DEFERRABLE INITIALLY DEFERRED39);40 41CREATE TABLE core_mfvolatility (42    "id" uuid NOT NULL PRIMARY KEY,43    "mutual_fund_id" uuid NOT NULL REFERENCES "core_mutualfund" ("id") DEFERRABLE INITIALLY DEFERRED,44    "year" varchar(100) NOT NULL,45    "alpha" double precision NULL,46    "beta" double precision NULL,47    "sharpe_ratio" double precision NULL,48    "standard_deviation" double precision NULL49);50 51-- core_mfvolatility.mutual_fund_id can be joined with core_mutualfund.id52-- core_mfholdings.mutual_fund_id can be joined with core_mutualfund.id53    """54 55    sql_prompt = f"""56Your task is to convert a question into a PostgresSQL query, given a database schema.57 58###Task:59Generate a SQL query that answers the question `{question}`.60 61### Database Schema:62This query will run on a database whose schema is represented below:63{database_schema}64 65### Response:66Based on your instructions, here is the PostgresSQL query I have generated to answer the question `{question}`:67```PostgresSQL68    """69    return sql_prompt70