Skip to main content

AI-driven natural language queries for databases using AutoGen

Project description

DBBot

DBBot is an AI-driven Python library that converts natural language queries into SQL queries using OpenAI’s AutoGen, enabling seamless interaction with databases. It empowers developers and data analysts to retrieve and manipulate data effortlessly using plain English queries.

Features

  • AI-Driven Query Generation: Converts natural language questions into valid SQL queries using AutoGen.
  • Multi-Database Support: Works with PostgreSQL, MySQL, and MongoDB.
  • Seamless Integration: Easily integrates with your existing Python projects.
  • Flexible Setup: Users provide their own database and OpenAI credentials.
  • Extensible: Allows adding support for more databases or customizing AI behavior.
  • Logging & Debugging: Built-in features to help troubleshoot queries.

Installation

Install DBBot using pip:

pip install dbqna

Requirements

  • Python 3.6 or higher
  • Required database drivers:
    • psycopg2 for PostgreSQL
    • pymysql for MySQL
    • pymongo for MongoDB
  • OpenAI API key (for using the GPT model)

Setup

Database Credentials

Provide the following details for database connection:

  • Host
  • Port
  • Database Name
  • User
  • Password

OpenAI Credentials

You'll need an OpenAI API key and additional configurations:

  • API Key
  • Base URL
  • API Version
  • Deployment Name

You can set these as environment variables in a .env file or provide them directly in the code.

Usage

1. Initialize DBBot with OpenAI Credentials

from dbqna import DBQnA

db_bot = DBQnA(
    azure_api_key="your-azure-api-key",
    azure_api_base="your-azure-api-base",
    azure_api_version="your-api-version",
    azure_deployment_name="your-deployment-name"
)

2. Provide Database Credentials

from dbqna import DBHelper

db_helper = DBHelper(
    host="localhost",
    port="5432",
    database="your-database",
    user="postgres",
    password="your-password"
)

3. Query the Database Using Natural Language

query = "how many work orders are there for tenant 1289?"
result = await db_bot.query_database(query)
print(result)

4. Example Response

Result: 
[
    ('work_order_count', 35)
]

Contributing

We welcome contributions! Feel free to fork the repository, open issues, or submit pull requests to enhance DBBot.

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

AIDBBot-0.1.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

AIDBBot-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file AIDBBot-0.1.1.tar.gz.

File metadata

  • Download URL: AIDBBot-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for AIDBBot-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f6f75a6b3dc0703f0d5ba962fd1860f9da3d7dec4fea3c244f75fcb6c8f47fb6
MD5 198f6ae3d1da386e3c65743ecd2596f5
BLAKE2b-256 8f1fbc0fbb40a9c16c072142a50d69a23f17b58a64c30b4c9d4a0913fccfbf30

See more details on using hashes here.

File details

Details for the file AIDBBot-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: AIDBBot-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for AIDBBot-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9581a0f1a082f48fa6df62e23f21c4a7b929d3e5d81228d31f4629375afa2c8b
MD5 6fbb74a7ad045fa497f5a237b4ea9f18
BLAKE2b-256 115e4ce29d90b9d35afc3f2ca18007ce43bd14d5f43058c92c0ef8ffdacaac57

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