File size: 2,048 Bytes
8c121eb
 
 
 
 
 
d0e0fa9
8c121eb
 
 
 
522b12f
f9dfcda
522b12f
f9dfcda
 
522b12f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c121eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
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)