Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Florents-Tselai authored Jul 8, 2024
1 parent ab84e83 commit c521b66
Showing 1 changed file with 23 additions and 71 deletions.
94 changes: 23 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,20 @@
[![codecov](https://codecov.io/gh/Florents-Tselai/tsellm/branch/main/graph/badge.svg)](https://codecov.io/gh/Florents-Tselai/tsellm)
[![License](https://img.shields.io/badge/BSD%20license-blue.svg)](https://github.com/Florents-Tselai/tsellm/blob/main/LICENSE)

**tsellm** is the easiest way to access LLMs through your SQLite or DuckDB database.
**tsellm** is the easiest way to access LLMs from SQLite or DuckDB.

```shell
pip install tsellm
```

```shell
usage: tsellm [-h] [--sqlite | --duckdb] [-v] [filename] [sql]

Use LLMs in SQLite and DuckDB

positional arguments:
filename SQLite/DuckDB database to open (defaults to SQLite ':memory:').
A new database is created if the file does not previously exist.
sql An SQL query to execute. Any returned rows are printed to
stdout.

options:
-h, --help show this help message and exit
--sqlite SQLite mode
--duckdb DuckDB mode
-v, --version Print tsellm version

```bash
cat <<EOF | tee >(sqlite3 prompts.sqlite3) | duckdb prompts.duckdb
CREATE TABLE prompts ( p TEXT);
INSERT INTO prompts VALUES('hello world!');
INSERT INTO prompts VALUES('how are you?');
INSERT INTO prompts VALUES('is this real life?');
INSERT INTO prompts VALUES('1+1=?');
EOF
```

Behind the scenes, **tsellm** is based on the beautiful [llm](https://llm.datasette.io) library,
Expand All @@ -42,95 +33,56 @@ For example, to access `gpt4all` models

```shell
llm install llm-gpt4all
# Then pick any gpt4all (it will be downloaded automatically the first time you use any model
tsellm :memory: "select prompt('What is the capital of Greece?', 'orca-mini-3b-gguf2-q4_0')"
tsellm :memory: "select prompt('What is the capital of Greece?', 'orca-2-7b')"
```

```sql
tsellm prompts.duckdb "select prompt(p, 'orca-mini-3b-gguf2-q4_0') from prompts"
tsellm prompts.sqlite3 "select prompt(p, 'orca-2-7b') from prompts"
```

## Embeddings

```shell
llm install llm-sentence-transformers
llm sentence-transformers register all-MiniLM-L12-v2
tsellm :memory: "select embed('Hello', 'sentence-transformers/all-MiniLM-L12-v2')"
```

```sql
tsellm prompts.sqlite3 "select embed(p, 'sentence-transformers/all-MiniLM-L12-v2')"
```

### Embeddings for binary (`BLOB`) columns

```shell
wget https://tselai.com/img/flo.jpg
sqlite3 images.db <<EOF
sqlite3 images.sqlite3 <<EOF
CREATE TABLE images(name TEXT, type TEXT, img BLOB);
INSERT INTO images(name,type,img) VALUES('flo','jpg',readfile('flo.jpg'));
EOF
```

```shell
llm install llm-clip
tsellm images.db "select embed(img, 'clip') from images"
```
## Examples
Things get more interesting if you
combine models in your standard queries.
First, create a db with some data.
You can easily toggle between SQLite and DuckDB,
and **tsellm** will pick this up automatically.
### SQLite
```bash
sqlite3 prompts.db <<EOF
CREATE TABLE prompts (
p TEXT
);
INSERT INTO prompts VALUES('hello world!');
INSERT INTO prompts VALUES('how are you?');
INSERT INTO prompts VALUES('is this real life?');
INSERT INTO prompts VALUES('1+1=?');
EOF
```

With a single query you can access get prompt
responses from different LLMs:
```sql
tsellm prompts.db "
select p,
prompt(p, 'orca-2-7b'),
prompt(p, 'orca-mini-3b-gguf2-q4_0'),
embed(p, 'sentence-transformers/all-MiniLM-L12-v2')
from prompts"
tsellm images.sqlite3 "select embed(img, 'clip') from images"
```

### DuckDB
### Multiple Prompts

```bash
duckdb prompts.duckdb <<EOF
CREATE TABLE prompts (
p TEXT
);
INSERT INTO prompts VALUES('hello world!');
INSERT INTO prompts VALUES('how are you?');
INSERT INTO prompts VALUES('is this real life?');
INSERT INTO prompts VALUES('1+1=?');
EOF
```
With a single query you can access get prompt
With a single query you can easily access get prompt
responses from different LLMs:

```sql
tsellm prompts.duckdb "
tsellm prompts.sqlite3 "
select p,
prompt(p, 'orca-2-7b'),
prompt(p, 'orca-mini-3b-gguf2-q4_0'),
embed(p, 'sentence-transformers/all-MiniLM-L12-v2')
from prompts"
```

## Interactive Shell

If you don't provide an SQL query,
Expand Down

0 comments on commit c521b66

Please sign in to comment.