Views
No views yet
pip install mlx-lm1from mlx_lm import load, generate
2
3# Load the model
4model, tokenizer = load("aikhan1/DuckDB-NSQL-7B-v0.1-mlx")
5
6# Example schema
7schema = """
8CREATE TABLE hospitals (
9 hospital_id BIGINT PRIMARY KEY,
10 hospital_name VARCHAR,
11 region VARCHAR,
12 bed_capacity INTEGER
13);
14
15CREATE TABLE patients (
16 patient_id BIGINT PRIMARY KEY,
17 full_name VARCHAR,
18 gender VARCHAR,
19 date_of_birth DATE,
20 region VARCHAR
21);
22"""
23
24# Example question
25question = "How many patients are there in each region?"
26
27# Build prompt
28prompt = f"""You are an assistant that writes valid DuckDB SQL queries.
29
30### Schema:
31{schema}
32
33### Question:
34{question}
35
36### Response (DuckDB SQL only):"""
37
38# Generate SQL
39response = generate(model, tokenizer, prompt=prompt, max_tokens=200, temp=0.0)
40print(response)1# Start the server
2mlx_lm.server --model aikhan1/DuckDB-NSQL-7B-v0.1-mlx --port 8080
3
4# In another terminal, make requests
5curl -X POST http://localhost:8080/v1/completions \
6 -H "Content-Type: application/json" \
7 -d '{
8 "prompt": "CREATE TABLE patients(...)\n\nQuestion: Count patients by region\n\nSQL:",
9 "max_tokens": 200,
10 "temperature": 0
11 }'You are an assistant that writes valid DuckDB SQL queries.
### Schema:
CREATE TABLE table_name (
column1 TYPE,
column2 TYPE
);
### Question:
[Your natural language question]
### Response (DuckDB SQL only):1@misc{duckdb-nsql-mlx,
2 title={DuckDB-NSQL-7B MLX Conversion},
3 author={aikhan1},
4 year={2025},
5 publisher={Hugging Face},
6 howpublished={\url{https://huggingface.co/aikhan1/DuckDB-NSQL-7B-v0.1-mlx}}
7}1@misc{duckdb-nsql,
2 title={DuckDB-NSQL-7B: Natural Language to SQL for DuckDB},
3 author={MotherDuck},
4 year={2024},
5 publisher={Hugging Face},
6 howpublished={\url{https://huggingface.co/motherduckdb/DuckDB-NSQL-7B-v0.1}}
7}