Agents With Database
Most of the time, we want the agent to answer questions based on the data in the database, or make decisions based on the data in the database. In this case, we need to connect the agent to the database.
Installation
To use the database in the agent, you need to install the dependencies with the following command:
pip install "dbgpt[simple_framework]>=0.5.9rc0"
Create A Database Connector
- SQLite(Temporary)
- SQLite
- MySQL
NOTE
We provide a temporary SQLite database for testing. The temporary database will be created in temporary directory and will be deleted after the program exits.
from dbgpt.datasource.rdbms.conn_sqlite import SQLiteTempConnector
connector = SQLiteTempConnector.create_temporary_db()
connector.create_temp_tables(
{
"user": {
"columns": {
"id": "INTEGER PRIMARY KEY",
"name": "TEXT",
"age": "INTEGER",
},
"data": [
(1, "Tom", 10),
(2, "Jerry", 16),
(3, "Jack", 18),
(4, "Alice", 20),
(5, "Bob", 22),
],
}
}
)
NOTE
We connect to the SQLite database by giving the database file path, please make sure the file path is correct.
from dbgpt.datasource.rdbms.conn_sqlite import SQLiteConnector
connector = SQLiteConnector.from_file_path("path/to/your/database.db")