|
--- |
|
license: apache-2.0 |
|
datasets: |
|
- VPCSinfo/odoo-sql-query-dataset |
|
base_model: |
|
- defog/sqlcoder-7b-2 |
|
pipeline_tag: text-generation |
|
library_name: adapter-transformers |
|
tags: |
|
- code |
|
--- |
|
# Fine-Tuned SQLCoder-7B for Odoo 17 |
|
|
|
This is a fine-tuned version of [defog/sqlcoder-7b-2](https://huggingface.co/defog/sqlcoder-7b-2) trained on Odoo 17 database schemas and queries. |
|
|
|
## Model Details |
|
- Base model: defog/sqlcoder-7b-2 |
|
- Fine-tuned using LoRA for parameter-efficient adaptation |
|
- Optimized for Odoo 17 SQL queries |
|
|
|
## Usage |
|
|
|
```python |
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
|
# Load the model with PEFT adapter |
|
model = AutoModelForCausalLM.from_pretrained("VPCSinfo/odoo17-sqlcoder-7b") |
|
tokenizer = AutoTokenizer.from_pretrained("VPCSinfo/odoo17-sqlcoder-7b") |
|
|
|
# Example query |
|
schema = """ |
|
|
|
CREATE TABLE res_partner ( |
|
id INTEGER PRIMARY KEY, |
|
name VARCHAR(255), |
|
email VARCHAR(255), |
|
phone VARCHAR(64) |
|
); |
|
CREATE TABLE sale_order ( |
|
id INTEGER PRIMARY KEY, |
|
partner_id INTEGER REFERENCES res_partner(id), |
|
date_order TIMESTAMP, |
|
state VARCHAR(20), |
|
amount_total NUMERIC |
|
); |
|
|
|
""" |
|
|
|
question = "Find all customers who have orders with a total amount greater than 1000" |
|
|
|
# Format your input following SQLCoder's expected format |
|
prompt = f'''### Task |
|
Generate a SQL query to answer the question below based on the table schema. |
|
|
|
### Database Schema |
|
|
|
CREATE TABLE res_partner ( |
|
id INTEGER PRIMARY KEY, |
|
name VARCHAR(255), |
|
email VARCHAR(255), |
|
phone VARCHAR(64) |
|
); |
|
CREATE TABLE sale_order ( |
|
id INTEGER PRIMARY KEY, |
|
partner_id INTEGER REFERENCES res_partner(id), |
|
date_order TIMESTAMP, |
|
state VARCHAR(20), |
|
amount_total NUMERIC |
|
); |
|
|
|
|
|
### Question |
|
Find all customers who have orders with a total amount greater than 1000 |
|
|
|
### SQL Query |
|
''' |
|
|
|
# Generate SQL |
|
inputs = tokenizer(prompt, return_tensors="pt") |
|
outputs = model.generate(**inputs, max_new_tokens=300) |
|
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True).split("### SQL Query")[1].strip() |
|
print(sql_query) |