Downloads · 30 days
72
8% of all-time downloads
support-pvelocity/Code-Llama-2-7B-instruct-text2sql-GGUF
Code-Llama-2-7B-instruct-text2sql-GGUF is a text generation model from support-pvelocity. Use it when you need the model to write or continue text. The card lists the license as llama2.
Model Name: Code-Llama-2-7B-instruct-text2sql-GGUF
Downloads · 30 days
72
8% of all-time downloads
All-time downloads
873
Public
Repo size
4.1 GB
Likes
0
Public
Click a slice to open those files.
.gguf4.1 GB · 100%
From the Hugging Face model README
Model Name: Code-Llama-2-7B-instruct-text2sql-GGUF
Description: This model is a GGUF quantisation of a fine-tuned version of the Code Llama 2 with 7 billion parameters, specifically tailored for text-to-SQL tasks. It has been trained to generate SQL queries given a database schema and a natural language question. The GGUF quantisation was performed with llama.cpp.
This model is governed by a custom commercial license from Code Llama. For details, please visit: Custom Commercial License
Intended Use Cases: This model is intended for commercial and research use in English. It is designed for text-to-SQL tasks, enabling users to generate SQL queries from natural language questions.
Out-of-Scope Uses: Any use that violates applicable laws or regulations, use in languages other than English, or any other use prohibited by the Acceptable Use Policy and Licensing Agreement for Code Llama and its variants.
You can use the Code-Llama-2-7B-instruct-text2sql-GGUF model to generate SQL queries from natural language questions, as demonstrated in the following code snippet:
pip install -q torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 ctransformers==0.2.27
from ctransformers import AutoModelForCausalLM
model_name = 'support-pvelocity/Code-Llama-2-7B-instruct-text2sql-GGUF'
model = AutoModelForCausalLM.from_pretrained(
model_name,
model_file=model_name.split('/')[1].replace('-GGUF', '.q4_k_m.gguf'),
model_type="llama",
gpu_layers=50,
context_length=4048
)
table = "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 );"
question = 'Find the salesperson who made the most sales.'
prompt = 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}: ``` "
output = model(prompt)
output = output.split('```')[0]
print(output.strip())
This code demonstrates how to utilize the model for generating SQL queries based on a provided database schema and a natural language question. It showcases the model's capability to assist in SQL query generation for text-to-SQL tasks.