SQL function for SQLite to directly query OpenAI's ChatGPT.
npm install --global sqlitegpt
export OPENAI_API_KEY="sk-XXX"
sqlitegpt example.sqlite "SELECT gpt('Name of tallest mountain')"
import { sqliteGpt } from "sqlitegpt"
sqliteGpt(
":memory:",
"SELECT gpt('Name of tallest mountain') as tallest_mountain"
)
sqliteGpt(
"example.sqlite",
`
SELECT
country,
gpt('capital of ' || country || ', no explanation') as capital
FROM users
`
)
- This implementation currently uses
sync-request
which forces HTTP requests to be synchronous. You should not use this in production! However, it's currently the only way to make it work withbetter-sqlite3
. - It's only implemented as an application-defined SQL function and can therefore only be used in JavaScript projects. To make it work in every SQLite environment, it should be implemented as a loadable extension.
If you like SQLiteGPT, please star the project and I will re-implement it as a proper loadable extension in Rust with sqlite-loadable-rs.