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.8 or higher
- Required database drivers:
psycopg2for PostgreSQL
- 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
Release history Release notifications | RSS feed
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 AIDBBot-0.1.2.tar.gz.
File metadata
- Download URL: AIDBBot-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c80f47a0890524b2c9bbb05c83099a2cb6f4dd55938e6d4fa88fa21a03575d78
|
|
| MD5 |
8d406a01a9f51d112b9b169cccf3621f
|
|
| BLAKE2b-256 |
68424bea2ec22453de99332ad51258705f3201e0a19b61f6136a4a9dbce63ef4
|
File details
Details for the file AIDBBot-0.1.2-py3-none-any.whl.
File metadata
- Download URL: AIDBBot-0.1.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1b9c85cf30f561e64352c80bc9ce2c3452c2a8b7127ded08450f5a86258523b
|
|
| MD5 |
e7644a78c638d8452873d253df3d81ea
|
|
| BLAKE2b-256 |
9be09688b79121954ca79bad698fd00252d9c1ffa612fa6bc2882aa140a999f5
|