Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lmangani/chdb-gpt

Generate chDB and ClickHouse queries with ChatGPT/OpenAI APIs
https://github.com/lmangani/chdb-gpt

chatgpt chdb clickhouse clickhouse-local clickhouse-server gpt openai sql

Last synced: 24 days ago
JSON representation

Generate chDB and ClickHouse queries with ChatGPT/OpenAI APIs

Awesome Lists containing this project

README

        

# chdb-GPT
Generate chDB and ClickHouse queries using natural language with ChatGPT/OpenAI APIs

๐Ÿ‘‰ [Run & Clone on Google Colab](https://colab.research.google.com/drive/1pXdgOsgfuY-8Li-vJd3ZvJI08iCOapWY?usp=sharing)

### Status
* Just a toy, hallucinating states ๐Ÿ
* Needs Prompt fine tuning and hacks
* Do not use this!

### Requirements
* `OPENAI_API_KEY`
```bash
export OPENAI_API_KEY {your_openai_token_here}
```

### Usage
#### Count local files
```bash
python3 promtp.py "count rows from file data.csv"
```
```sql
SELECT count(*) FROM file('data.csv')
```

#### URL Engine, Parquet
```bash
python3 promtp.py "show the top 10 towns from url https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet"
```
```sql
SELECT town, COUNT(*) AS count
FROM url('https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet', 'Parquet')
GROUP BY town
ORDER BY count DESC
LIMIT 10;
```

#### โš ๏ธ Pipe query to chdb
```
# python3 -m chdb "$(./prompt.py "count rows from file data.csv" | awk -v FS="(sql|\`\`\`)" '{print $1}')" Pretty
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ count() โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ 2 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

#### Interactive Mode

```bash
# python3 interactive.py

Hi, I'm chdbGPT, an AI assistant that can execute ClickHouse SQL queries for you.

What would you like to know? => show the top 10 towns by price from url https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet

The query returned data for 10 towns. The towns are listed in descending order of price.
The town with the highest price is London, with a price of 337,000,000.
The remaining towns are also in London, with prices ranging from 315,000,000 to 160,000,000.

```