Skip to main content

Interactive SQLite shell with LLM support

Project description

tsellm: Use LLMs in your SQLite queries

installs

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:

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')"

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

til

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


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.0a9.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

tsellm-0.1.0a9-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file tsellm-0.1.0a9.tar.gz.

File metadata

  • Download URL: tsellm-0.1.0a9.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for tsellm-0.1.0a9.tar.gz
Algorithm Hash digest
SHA256 6e7d8bb7bca3efc34e487ea1801872b5a3242df6daeb41dad40ee941fa71cf07
MD5 a5782f61548483268e882d3ab63f1d10
BLAKE2b-256 a985b250e7744bcc4d93f78409b51c02ada5d319f72b98d1ae3b2f112d2ec4f5

See more details on using hashes here.

File details

Details for the file tsellm-0.1.0a9-py3-none-any.whl.

File metadata

  • Download URL: tsellm-0.1.0a9-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for tsellm-0.1.0a9-py3-none-any.whl
Algorithm Hash digest
SHA256 3dd9ce2bff5b13d8ae2bb5e002663ebd69daaf94007737aa20b123d159e899be
MD5 a69ab6ad544bdd279fe093a0df0cb534
BLAKE2b-256 28301dde32db475e1b62c316bfa8007e86add23f5c8e7c7fa9e0025f959eb3cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page