https://github.com/notyusheng/query-agent
Query Agent is an AI-powered natural language interface for PostgreSQL databases. It allows users to explore and query structured data using plain English, powered by Qwen 2.5 running via LM Studio.
https://github.com/notyusheng/query-agent
docker docker-compose fastapi lm-studio postgres qwen2-5 streamlit
Last synced: about 1 year ago
JSON representation
Query Agent is an AI-powered natural language interface for PostgreSQL databases. It allows users to explore and query structured data using plain English, powered by Qwen 2.5 running via LM Studio.
- Host: GitHub
- URL: https://github.com/notyusheng/query-agent
- Owner: NotYuSheng
- Created: 2025-04-02T13:01:48.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-02T13:07:51.000Z (about 1 year ago)
- Last Synced: 2025-04-02T14:22:29.178Z (about 1 year ago)
- Topics: docker, docker-compose, fastapi, lm-studio, postgres, qwen2-5, streamlit
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π€ Query Agent
**Query Agent** is an AI-powered natural language interface for PostgreSQL databases. It allows users to explore and query structured data using plain English, powered by [Qwen 2.5](https://huggingface.co/Qwen/Qwen1.5-72B-Chat) running via [LM Studio](https://lmstudio.ai/).
Built with:
- π FastAPI backend
- π Streamlit frontend
- π PostgreSQL database
- π§ LLM-powered SQL generation
- π³ Docker & Docker Compose
---
## π Features
- Auto-discovers tables in your PostgreSQL database
- Click-to-select table interface
- LLM-generated data dictionary for any table
- Preview top 5 sample rows from selected table
- Natural language-to-SQL translation using Qwen 2.5
- Fully containerized setup for local development
---
## π§± Project Structure
```
query-agent/
βββ backend/ # FastAPI server
β βββ main.py
β βββ db.py
β βββ prompt.py
β βββ requirements.txt
βββ frontend/ # Streamlit interface
β βββ streamlit_app.py
β βββ requirements.txt
βββ postgres/ # Sample DB seed
β βββ init.sql
βββ docker-compose.yml
βββ README.md
```
---
## π οΈ Getting Started
### 1. Clone the repository
```bash
git clone https://github.com/notyusheng/query-agent.git
cd query-agent
```
### 2. Start the app
```bash
docker-compose up --build -d
```
- Frontend (Streamlit): [http://localhost:8080](http://localhost:8080)
- Backend (FastAPI): [http://localhost:3000/docs](http://localhost:3000/docs)
- Database (PostgreSQL): Port `5432` exposed locally
---
## π§ LLM Setup (Qwen 2.5 via LM Studio)
Make sure LM Studio is running locally or on your network with the following:
- Model: Qwen 2.5 (or any OpenAI-compatible LLM)
- Server URL: `http://192.168.1.130:1234/v1/chat/completions`
This is hardcoded in `backend/main.py`βupdate `LLM_URL` if needed.
---
## π§° Example Table Included
A sample `devices` table is loaded on first run via `postgres/init.sql`:
```sql
CREATE TABLE devices (
device_id SERIAL PRIMARY KEY,
model_name TEXT,
os_version TEXT,
release_year INTEGER
);
```
---
## πΈ Screenshots
_coming soon..._
---
## π To-Do / Ideas
- [ ] Add support for multiple-table joins
- [ ] Semantic search across column descriptions
- [ ] Export SQL results as CSV
- [ ] Admin interface to manage metadata
---
## π License
MIT License β free for personal and commercial use.
---
## π¬ Feedback / Contributions
Open an issue, submit a PR, or reach out if you want to collaborate. This is an ongoing project and evolving rapidly.