Experimental extension that brings OpenAI API to your PostgreSQL to run queries in human language.

Overview

Postgres <> ChatGPT

Experimental PostgreSQL extension that enables the use of OpenAI GPT API inside PostgreSQL, allowing for queries to be written using natural language.

Demo

(This demo uses data from the Hacker News and Azure CloudQuery plugins)

How does it work?

The extension sends a subset of the database schema to ChatGPT and asks it to generate a query based on this and the user input.

Before you start

  • Note: This plugins sends schema (without the data) to OpenAI GPT API, so it is not recommended to use it on production databases.
  • Note: This is an experimental plugin and not officially supported by CloudQuery.

Installation

Requires pgx. Install this first:

cargo install --locked cargo-pgx
cargo pgx init

Now you can install the extension:

git clone https://github.com/cloudquery/pg_gpt
cd pg_gpt
export OPENAI_KEY=<YOUR_KEY>
cargo pgx run
# will drop into psql shell
create extension pg_gpt;
set openai.key = '<YOUR OPENAPI API KEY HERE>'; -- set your key
select gpt('show me all open aws s3 buckets');
-- will output the following query, so you can execute it
-- select * from aws_s3_bucket;

Available Functions

  • gpt(text) - Generates a query based on the user input and the full database schema. This works fine for databases with small schemas.
  • gpt_tables(table_pattern, text) - Similar to gpt, but only uses the tables that match the pattern. The pattern is passed to a table_name LIKE query, so % can be used as wildcard.

Installing the extension on an existing Postgres instance

First run:

cargo pgx install

This places the extension in the postgres extensions directory. Then, in your postgres instance, run:

create extension pg_gpt;
set openai.key = '<YOUR OPENAPI API KEY HERE>';
-- proceed to use the extension

Limitations

  • Schema Size - Currently we use gpt-3.5-turbo, which is limited to 4096 tokens. Use gpt_tables to narrow down the set of tables.
You might also like...
A CLI tool you can pipe code and then ask for changes, add documentation, etc, using the OpenAI API.
A CLI tool you can pipe code and then ask for changes, add documentation, etc, using the OpenAI API.

AiBro This is your own little coding bro, immersed in the world of AI, crypto, and all other types of over hyped tech trends. You can pipe it code and

A utility for exporting administrative/moderation statistics from your Lemmy instance's PostgreSQL database to InfluxDB!
A utility for exporting administrative/moderation statistics from your Lemmy instance's PostgreSQL database to InfluxDB!

Lemmy (Stats) Data Exporter About This Project This project aims to act as a bridge between Lemmy's PostgreSQL database and InfluxDB, primarily to tra

This is choose, a human-friendly and fast alternative to cut and (sometimes) awk
This is choose, a human-friendly and fast alternative to cut and (sometimes) awk

Choose This is choose, a human-friendly and fast alternative to cut and (sometimes) awk Features terse field selection syntax similar to Python's list

Grep with human-friendly search output
Grep with human-friendly search output

hgrep: Human-friendly GREP hgrep is a grep tool to search files with given pattern and print the matched code snippets with human-friendly syntax high

Codemod - Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention

Codemod - Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.

Fuzzy Index for Python, written in Rust. Works like error-tolerant dict, keyed by a human input.

FuzzDex FuzzDex is a fast Python library, written in Rust. It implements an in-memory fuzzy index that works like an error-tolerant dictionary keyed b

Human numeric sorting program — does what `sort -h` is supposed to do!

hns — Human Numeric Sort v0.1.0 (⏫︎2022-09-20) © 2022 Fredrick R. Brennan and hns Authors Apache 2.0 licensed, see LICENSE. man page Packages hns_0.1.

Display file sizes in human-readable units

hsize Display file sizes in human-readable units $ hsize 1000 1000000 5000000 1.00 KB 1.00 MB 5.00 MB $ hsize -p 5 1048576 12345678 1.04858 MB 12.345

ChatGPT-Code-Review is a Rust application that uses the OpenAI GPT-3.5 language model to review code

ChatGPT-Code-Review is a Rust application that uses the OpenAI GPT-3.5 language model to review code. It accepts a local path to a folder containing code, and generates a review for each file in the folder and its subdirectories.

Owner
CloudQuery
The open source high performance data integration platform built for developers
CloudQuery
A Rust library for evaluating log4j substitution queries in order to determine whether or not malicious queries may exist.

log4j_interpreter A Rust library for evaluating log4j substitution queries in order to determine whether or not malicious queries may exist. Limitatio

Fastly 22 Nov 7, 2022
A PostgreSQL extension for rendering the Tera HTML templating language.

PGTera PGTera is a PostgreSQL extension that provides functions for using Tera to render HTML templates. When used with a tool like Postgrest, you can

Frankie 4 Feb 16, 2024
This repository brings together my studies in the Rust language.

Studying_Rust This repository brings together my studies in the Rust language. Study schedule in 90 days start date: 7/24 end date: 10/24 Each topic w

Débora Marim 5 Aug 8, 2023
Chaos Cat brings destruction and suffering to your software

Chaos Cat brings destruction and suffering to your software. When Chaos Cat is loaded it will randomly make predefined syscalls fail. This tests your software for the the things you might have forgotten to check because operating systems usually Just Work™ and syscalls usually never fail.

Ossi Herrala 2 Oct 8, 2022
🌈 Brings back colour console to Win64 for Garry's Mod SRCDS

?? gmsv_concolormsg This module for Garry's Mod fixes x86-64 Windows 64-bit SRCDS not displaying colours. Why does it do that? Who knows! But it's eas

William 11 Oct 4, 2022
A simple, human-friendly, embeddable scripting language

Mica Language reference · Rust API A simple, human-friendly scripting language, developed one feature at a time. Human-friendly syntax inspired by Rub

Mica programming language 32 Dec 30, 2022
Rust-based CLI library for OpenAI ChatGPT API

This is a Rust library that provides a CLI (command-line interface) for easy and convenient access to the OpenAI ChatGPT API. The library offers a simple and straightforward way to integrate the ChatGPT API into your Rust-based applications.

bigduu 10 Mar 9, 2023
A Rust client for OpenAI's API

libopenai - Rust client to interact with OpenAI's API Rust client for OpenAI's API, written with tokio and reqwest How to use To add libopenai to your

Alex 9 Mar 31, 2023
A command-line interface for interacting with the ChatGPT API from OpenAI

cligpt cligpt is a command-line interface for interacting with the ChatGPT API from OpenAI. With cligpt, you can quickly and easily generate text by s

Felipe S. S. Schneider 6 Apr 4, 2023
A simple Rust library for OpenAI API, free from complex async operations and redundant dependencies.

OpenAI API for Rust A community-maintained library provides a simple and convenient way to interact with the OpenAI API. No complex async and redundan

null 6 Apr 4, 2023