Skip to main content

This Python package provides functions to convert natural language to SQL queries using a pre-trained language model.

Project description

tabqa: Natural Language to SQL Query Converter

Overview

This Python library enables the conversion of natural language queries into SQL queries. It simplifies the process of querying databases by allowing users to express their queries in everyday language.

Installation

You can install the package via pip:

pip install tabqa

Quick Start

from tabqa import sql_model, generate_schema

# Define the natural language question
question = "Count Number of products"

# Path to the SQL file containing the database schema
file_path = "schema.sql"  #

# Initialize the SQL model
model = sql_model()

# Generate the SQL schema from the natural language question
result = generate_schema(question, file_path, model)

# Print the generated SQL query
print(result)

Parameters for sql_model function :

  1. model_name: str = 'defog/sqlcoder-7b',
  2. cache_dir: str = './',
  3. device_map: str = 'auto',
  4. trust_remote_code: bool = True,
  5. torch_dtype: torch.dtype = torch.float16,
  6. use_cache: bool = True,
  7. force_download: bool = False,
  8. resume_download: bool = False,
  9. output_loading_info: bool = False,
  10. local_files_only: bool = False,

Model available :

  1. defog/sqlcoder-7b (lowest Accuracy)
  2. defog/sqlcoder-34b-alpha (Medium Accuracy)
  3. defog/sqlcoder-70b-alpha (Highest Accuracy)

Warning: 'defog/sqlcoder-34b-alpha' and 'defog/sqlcoder-70b-alpha' demand high GPU and RAM resources. Please don't use on local machines.

How to Use

  1. Import the necessary functions from tabqa.
  2. Define your natural language question.
  3. Provide the path to the SQL file containing your database schema.
  4. Initialize the SQL model.
  5. Use generate_schema() function to convert the natural language question into an SQL query.
  6. Print or use the generated SQL query as needed.

Contribution

Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License.

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

tabqa-0.1.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tabqa-0.1.3-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file tabqa-0.1.3.tar.gz.

File metadata

  • Download URL: tabqa-0.1.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for tabqa-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2202bd3a97fc7e411af3c11f2d019e3f4dc9f9ac6a22050dbf50e792ff5f20d0
MD5 78ebbb8c13ddc761f49a4af7c47cf7cb
BLAKE2b-256 368c08fbce273c947f7ff64b5161cede602245b8e1fbeee370db071b9cd3f0d3

See more details on using hashes here.

File details

Details for the file tabqa-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tabqa-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for tabqa-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fec8bdb4e0296d63d67d0a73a4544a6b0ccdb1716eecbe603ed2be838c2cb69d
MD5 d6cc4cf5d9ff652c0590588fb1a5f41a
BLAKE2b-256 6ca98d4e12cb365459dd64b4df663cdb42d2e3a635b1c7720545519a3d3a2dbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page