forked from pilotpirxie/ormGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
259a2fe
commit 754a12a
Showing
9 changed files
with
220 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,146 @@ | ||
# ormGPT | ||
# ormGPT | ||
|
||
An ORM based on OpenAI that translates plain language into SQL queries and executes them on a database. | ||
|
||
Currently supports database dialects: MySQL, PostgreSQL, and SQLite. | ||
|
||
Supported languages: English, German, French, Spanish, Polish, Italian, Dutch, Portuguese, Ukrainian, Arabic, Chinese, Japanese, Korean, Turkish and many more. | ||
|
||
```shell | ||
ormgpt.query("give me post with id 1, all comments for this post and user information about author"); | ||
``` | ||
|
||
Generated query: | ||
```sql | ||
SELECT | ||
p.id AS post_id, | ||
p.title, | ||
p.body, | ||
c.id AS comment_id, | ||
c.body AS comment_body, | ||
u.username AS author_username, | ||
u.email AS author_email | ||
FROM | ||
posts p | ||
JOIN comments c ON p.id = c.post_id | ||
JOIN users u ON u.id = p.user_id | ||
WHERE | ||
p.id = 1; | ||
``` | ||
|
||
Response: | ||
```js | ||
[ | ||
{ | ||
post_id: 1, | ||
title: 'Hello world!', | ||
body: 'This is my first post!', | ||
comment_id: 1, | ||
comment_body: 'Hello world!', | ||
author_username: 'test', | ||
author_email: 'test@example.com' | ||
} | ||
] | ||
``` | ||
|
||
![./preview.gif](./preview.gif) | ||
|
||
## Installation | ||
|
||
```shell | ||
npm install ormgpt | ||
|
||
# or | ||
|
||
yarn add ormgpt | ||
|
||
# or | ||
|
||
pnpm add ormgpt | ||
``` | ||
|
||
## Usage | ||
Prepare a database schema file, for example `schema.sql`. This file will be used to generate queries. | ||
|
||
```js | ||
const client = await createConnection({ | ||
host: 'localhost', | ||
port: 3306, | ||
database: 'ormgpt', | ||
user: 'root', | ||
password: 'mysecretpassword', | ||
}); | ||
|
||
const mysqlAdapter = new MysqlAdapter({ | ||
client | ||
}); | ||
|
||
const ormgpt = new ormGPT({ | ||
apiKey: "OPENAI_API_KEY", | ||
schemaFilePath: "./example/schema.sql", | ||
dialect: "postgres", | ||
dbEngineAdapter: mysqlAdapter, | ||
}); | ||
|
||
await ormgpt.query( | ||
"add new user with username 'test' and email 'test@example.com'", | ||
); | ||
|
||
const users = await ormgpt.query("get all users"); | ||
console.log(users); | ||
``` | ||
|
||
### Adapters | ||
|
||
MySQL | ||
```js | ||
const client = await createConnection({ | ||
host: 'localhost', | ||
port: 3306, | ||
database: 'ormgpt', | ||
user: 'root', | ||
password: 'mysecretpassword', | ||
}); | ||
|
||
const mysqlAdapter = new MysqlAdapter({ | ||
client | ||
}); | ||
``` | ||
|
||
Postgres | ||
```js | ||
const client = new Client({ | ||
host: 'localhost', | ||
port: 5432, | ||
database: 'ormgpt', | ||
user: 'mysecretuser', | ||
password: 'mysecretpassword', | ||
}); | ||
client.connect(); | ||
|
||
const postgresAdapter = new PostgresAdapter({ | ||
client | ||
}); | ||
``` | ||
|
||
SQLite | ||
```js | ||
const sqliteAdapter = new SqliteAdapter({ | ||
dbFilePath: "./example/db.sqlite", | ||
}); | ||
|
||
const ormgpt = new ormGPT({ | ||
apiKey: process.env.OPENAI_API_KEY || "", | ||
schemaFilePath: "./example/schema.sql", | ||
dialect: "postgres", | ||
dbEngineAdapter: sqliteAdapter, | ||
}); | ||
``` | ||
|
||
### Why? | ||
|
||
In the last two years, I found ORMs to be new "days since the last javascript framework" in the JavaScript ecosystem. And since AI is a hot buzzword | ||
I decided to combine both and create an ORM that uses OpenAI to generate SQL queries. Please don't use this in production. | ||
|
||
### License | ||
MIT |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type ModelTuning = { | ||
temperature: number; | ||
max_tokens: number; | ||
top_p: number; | ||
frequency_penalty: number; | ||
presence_penalty: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters