Interactive SQLite shell with LLM support
Project description
tsellm: Use LLMs in SQLite
tsellm is the easiest way to access LLMs through your SQLite database.
pip install tsellm
Behind the scenes, tsellm is based on the beautiful llm library, so you can use any of its plugins:
Generative
For example, to access gpt4all
models
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')"
Embeddings
llm install llm-sentence-transformers
llm sentence-transformers register all-MiniLM-L12-v2
tsellm :memory: "select embed('Hello', 'sentence-transformers/all-MiniLM-L12-v2')"
Embeddings for binary (BLOB
) columns
wget https://tselai.com/img/flo.jpg
sqlite3 images.db <<EOF
CREATE TABLE images(name TEXT, type TEXT, img BLOB);
INSERT INTO images(name,type,img) VALUES('flo','jpg',readfile('flo.jpg'));
EOF
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 SQLite queries.
First, create a db with some data
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:
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"
Interactive Shell
If you don't provide an SQL query, you'll enter an interactive shell instead.
tsellm prompts.db
Installation
pip install tsellm
How
tsellm relies on the following facts:
- SQLite is bundled with the standard Python library (
import sqlite3
) - Python 3.12 ships with a SQLite interactive shell
- one can create Python-written user-defined functions to be used in SQLite queries (see create_function)
- Simon Willison has gone through the process of creating the beautiful llm Python library and CLI
Development
pip install -e '.[test]'
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tsellm-0.1.0a10.tar.gz
.
File metadata
- Download URL: tsellm-0.1.0a10.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af1cbd86c45e3b9855cb651c5333c1a33899fd7ce6dc38db90e494fd4ef34ad5 |
|
MD5 | a18cc5becb2ab539adf0ff2dbb59a796 |
|
BLAKE2b-256 | 9a716db864d2f35948b971bb64b43cfc21ab002b24bd2e972907ef072c2edd1d |
File details
Details for the file tsellm-0.1.0a10-py3-none-any.whl
.
File metadata
- Download URL: tsellm-0.1.0a10-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e709ffc9bf4ecd4b29027dac944bd5d51b761b878ff21b6c90ceb3e4c982b5cf |
|
MD5 | 224ed2f2223ff51ebfe572e9cc8d13b2 |
|
BLAKE2b-256 | 48e97fc5dee81bb4f14c15367b39fe2f1308c968efd3673cb1be536bb8a4f259 |