A simple implementation of NL2SQL.
Project description
NL2SQL
A simple implementation of NL2SQL.
Requirements
- Python 3.12+
- Postgresql / Mysql
- LLM API
- Milvus 2.5.0+
- Embedding API
Definition
LLM URI
A db-uri-style string that provides information for calling the model API.
Format
<model_type>+<api_type>://<model>[:<model_tag>]@[<api_key>]@<url>
Supported Model Type
- llm
- embedding
Supported API Type
- ollama
- openai
Example
llm+ollama://qwen2.5:32b@localhost:11434 llm+openai://gpt-3.5-turbo:32b@your_token@http://localhost:11434/v1
SQL References
Optional metadata stored in Milvus. Provide some sql references for problems similar to the current problem.
Format
Must contain query and sql fields.
Vector field will be matched the embedding of query.
Usage
generate sql
from nl2sql.tools.text2sql import Text2SQL
worker = Text2SQL(
db_uri="postgresql+psycopg2://postgres:123456@localhost:5432/test",
llm_uri="llm+ollama://qwen2.5:32b@localhost:11434",
milvus_uri="http://read:123456@localhost:19530",
collection_name="sql_references",
embedding_uri="embedding+ollama://bge-m3@localhost:11434"
)
sql = worker.generate("公司的设备清单", ["assets", "users", "projects"]).sql
optimize sql
from nl2sql.tools.text2sql import Text2SQL
worker = Text2SQL(
db_uri="postgresql+psycopg2://postgres:123456@localhost:5432/test",
llm_uri="llm+ollama://qwen2.5:32b@localhost:11434",
milvus_uri="http://read:123456@localhost:19530",
collection_name="sql_references",
embedding_uri="embedding+ollama://bge-m3@localhost:11434"
)
sql = worker.optimize("select * from users", "所有用户的用户名", "有多余的字段", ["users", "projects"]).sql
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simple_nl2sql-0.1.0.tar.gz.
File metadata
- Download URL: simple_nl2sql-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a246bddeb531f231efb2c3f355d28f2a981af008cab9b5f8e8e67fd3ebdaea0
|
|
| MD5 |
533a0410a1202990c4ed0095b7c53337
|
|
| BLAKE2b-256 |
4bb3e029eb47541f6e5ca7d7a201d772f9a506f5c984f3864be8768d9a474dbd
|
File details
Details for the file simple_nl2sql-0.1.0-py3-none-any.whl.
File metadata
- Download URL: simple_nl2sql-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1331b32b30261f5e124f7f2911b6ecd84a1d854508d4df463e761ff03fe59b7
|
|
| MD5 |
f96ea6dc9a1d5e73c82eb5f24047b373
|
|
| BLAKE2b-256 |
35792fc9c97512bea0f8f6ff6b75fb648fdaf344ead2af5239b8765fa43caeaa
|