Views
No views yet
pip install -q torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 ctransformers==0.2.271from ctransformers import AutoModelForCausalLM
2
3model_name = 'support-pvelocity/Llama-2-7B-instruct-text2sql-GGUF'
4
5model = AutoModelForCausalLM.from_pretrained(
6 model_name,
7 model_file=model_name.split('/')[1].replace('-GGUF', '.q4_k_m.gguf'),
8 model_type="llama",
9 gpu_layers=50,
10 context_length=4048
11)
12
13table = "CREATE TABLE sales ( sale_id number PRIMARY KEY, product_id number, customer_id number, salesperson_id number, sale_date DATE, quantity number, FOREIGN KEY (product_id) REFERENCES products(product_id), FOREIGN KEY (customer_id) REFERENCES customers(customer_id), FOREIGN KEY (salesperson_id) REFERENCES salespeople(salesperson_id)); CREATE TABLE product_suppliers ( supplier_id number PRIMARY KEY, product_id number, supply_price number, FOREIGN KEY (product_id) REFERENCES products(product_id)); CREATE TABLE customers ( customer_id number PRIMARY KEY, name text, address text ); CREATE TABLE salespeople ( salesperson_id number PRIMARY KEY, name text, region text ); CREATE TABLE product_suppliers ( supplier_id number PRIMARY KEY, product_id number, supply_price number );"
14
15question = 'Find the salesperson who made the most sales.'
16
17prompt = f"[INST] Write SQLite query to answer the following question given the database schema. Please wrap your code answer using ```: Schema: {table} Question: {question} [/INST] Here is the SQLite query to answer to the question: {question}: ``` "
18
19output = model(prompt)
20output = output.split('```')[0]
21print(output.strip())