Team Ai
Modelpublic

OneGate/OG-SQL-7B

sourceHugging Facecc-by-4.0updated 2y agoView on Hugging Face
2likes42downloads
README.md78 linesDownload Raw Back to root
1---2license: cc-by-4.03language:4- en5tags:6- Text-to-sql7---8# OGSQL-7B9 10![image/png](https://cdn-uploads.huggingface.co/production/uploads/657ad4e2583493c1d1efb05b/RFfCWir0Jzhm-biGceU0c.png)11 12### Model Description13OGSQL-7B  was fine-tuned for the task of converting natural language text into SQL queries.14 15- **Model type**: Transformer16- **Language(s) (NLP)**: SQL (target language for generation)17- **Finetuned from model**: codellama 7b18 19## Use Case20OGSQL-7B is designed to facilitate the conversion of natural language queries into structured SQL commands, aiding in database querying without the need for manual SQL knowledge.21 22## How to Get Started with the Model23```python24# Example code to load and use the model25from transformers import AutoModelForSeq2SeqLM, AutoTokenizer26 27model_name = "OGSQL-7B"28tokenizer = AutoTokenizer.from_pretrained(model_name)29model = AutoModelForSeq2SeqLM.from_pretrained(model_name)30 31def generate_sql(query):32    inputs = tokenizer.encode(query, return_tensors="pt")33    outputs = model.generate(inputs)34    return tokenizer.decode(outputs[0], skip_special_tokens=True)35 36# Example use37query = """38using this context:39-- Create Customers Table40CREATE TABLE Customers (41    customer_id INTEGER PRIMARY KEY,42    name TEXT NOT NULL,43    email TEXT,44    join_date DATE45);46 47-- Create Products Table48CREATE TABLE Products (49    product_id INTEGER PRIMARY KEY,50    name TEXT NOT NULL,51    price DECIMAL(10, 2)52);53 54-- Create Orders Table55CREATE TABLE Orders (56    order_id INTEGER PRIMARY KEY,57    customer_id INTEGER,58    product_id INTEGER,59    order_date DATE,60    quantity INTEGER,61    total_price DECIMAL(10, 2),62    FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),63    FOREIGN KEY (product_id) REFERENCES Products(product_id)64);65 66show me all the orders from last month , sort by date67 68 69"""70print(generate_sql(query))71 72```73 74 75## alternatively  you can use this notebook:  76[![Colab notebook](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zfuzV3R1GQflHV_va03WArb8vhwPh_2T)77 78