Use LLMs in SQLite and DuckDB
Project description
tsellm: Use LLMs in SQLite and DuckDB
tsellm is the easiest way to access LLMs from SQLite or DuckDB.
pip install tsellm
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 library, so you can use any of its plugins:
Generative
For example, to access gpt4all
models
llm install llm-gpt4all
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
llm install llm-sentence-transformers
llm sentence-transformers register all-MiniLM-L12-v2
tsellm prompts.sqlite3 "select embed(p, 'sentence-transformers/all-MiniLM-L12-v2')"
Embeddings for binary (BLOB
) columns
wget https://tselai.com/img/flo.jpg
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
llm install llm-clip
tsellm images.sqlite3 "select embed(img, 'clip') from images"
Multiple Prompts
With a single query you can easily access get prompt responses from different LLMs:
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, 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
tsellm-0.1.0a12.tar.gz
(10.4 kB
view details)
Built Distribution
File details
Details for the file tsellm-0.1.0a12.tar.gz
.
File metadata
- Download URL: tsellm-0.1.0a12.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 917c5416270ff9215b604997acd90b918e9ca5e6f74d896705df1839834618a8 |
|
MD5 | d113cb6b446539190ddda687f551974f |
|
BLAKE2b-256 | b7d56835b6d7fde7404ae3ac7a23ef4ae61027fc2b786fbb646b25688aebd184 |
File details
Details for the file tsellm-0.1.0a12-py3-none-any.whl
.
File metadata
- Download URL: tsellm-0.1.0a12-py3-none-any.whl
- Upload date:
- Size: 7.9 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 | 679ac39a2e62a46b81700fc96cee298ec80364e1dcd92cfc9343f482545c6a83 |
|
MD5 | f20a21a732a6646c125c8059d953f47a |
|
BLAKE2b-256 | e2961167892466f475261ea6d72fce775c897df9b13fe7d35a8ebbcdfbdf77ec |