Name | datasette-llm-usage JSON |
Version |
0.1a0
JSON |
| download |
home_page | None |
Summary | Track usage of LLM tokens in a SQLite table |
upload_time | 2024-12-02 20:40:39 |
maintainer | None |
docs_url | None |
author | Simon Willison |
requires_python | >=3.9 |
license | Apache-2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# datasette-llm-usage
[![PyPI](https://img.shields.io/pypi/v/datasette-llm-usage.svg)](https://pypi.org/project/datasette-llm-usage/)
[![Changelog](https://img.shields.io/github/v/release/datasette/datasette-llm-usage?include_prereleases&label=changelog)](https://github.com/datasette/datasette-llm-usage/releases)
[![Tests](https://github.com/datasette/datasette-llm-usage/actions/workflows/test.yml/badge.svg)](https://github.com/datasette/datasette-llm-usage/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/datasette/datasette-llm-usage/blob/main/LICENSE)
Track usage of LLM tokens in a SQLite table
This is a **very early alpha**.
## Installation
Install this plugin in the same environment as Datasette.
```bash
datasette install datasette-llm-usage
```
## Usage
This plugin adds functionality to track and manage LLM token usage in Datasette. It creates two tables.
- `_llm_usage`: Tracks usage of LLM tokens
- `_llm_allowance`: Manages credit allowances for LLM usage
### Configuration
By default the tables are created in the internal database passed to Datasette using `--internal internal.db`. You can change that by setting the following in your Datasette plugin configuration:
```json
{
"plugins": {
"datasette-llm-usage": {
"database": "your_database_name"
}
}
}
```
### Setting up allowances
Before using LLM models, you need to set up an allowance in the `_llm_allowance` table. You can do this with SQL like:
```sql
insert into _llm_allowance (
id,
created,
credits_remaining,
daily_reset,
daily_reset_amount,
purpose
) values (
1,
strftime('%s', 'now')
10000,
0,
0,
null
);
```
The other columns are not yet used.
### Using the LLM wrapper
The plugin provides an `LLM` class that wraps the `llm` library to track token usage:
```python
from datasette_llm_usage import LLM
llm = LLM(datasette)
# Get available models
models = llm.get_async_models()
# Get a specific model
model = llm.get_async_model("gpt-4o-mini", purpose="my_purpose")
# Use the model
response = await model.prompt("Your prompt here")
text = await response.text()
```
Usage will be automatically recorded.
### Built-in endpoint
The plugin provides a simple demo endpoint at `/-/llm-usage-simple-prompt` that requires authentication and uses the gpt-4o-mini model.
### Supported Models and Pricing
The plugin includes pricing information for various models including:
- Gemini models (1.5-flash, 1.5-pro)
- Claude models (3.5-sonnet, 3-opus, 3-haiku)
- GPT models (gpt-4o, gpt-4o-mini, o1-preview, o1-mini)
Different models have different input and output token costs.
## Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
```bash
cd datasette-llm-usage
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
python -m pytest
```
Raw data
{
"_id": null,
"home_page": null,
"name": "datasette-llm-usage",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Simon Willison",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/47/a4/bdaaa6e0c81b15881c7a2c0881a3135464dee2f673ee1c704ad438325dd7/datasette_llm_usage-0.1a0.tar.gz",
"platform": null,
"description": "# datasette-llm-usage\n\n[![PyPI](https://img.shields.io/pypi/v/datasette-llm-usage.svg)](https://pypi.org/project/datasette-llm-usage/)\n[![Changelog](https://img.shields.io/github/v/release/datasette/datasette-llm-usage?include_prereleases&label=changelog)](https://github.com/datasette/datasette-llm-usage/releases)\n[![Tests](https://github.com/datasette/datasette-llm-usage/actions/workflows/test.yml/badge.svg)](https://github.com/datasette/datasette-llm-usage/actions/workflows/test.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/datasette/datasette-llm-usage/blob/main/LICENSE)\n\nTrack usage of LLM tokens in a SQLite table\n\nThis is a **very early alpha**.\n\n## Installation\n\nInstall this plugin in the same environment as Datasette.\n```bash\ndatasette install datasette-llm-usage\n```\n## Usage\n\nThis plugin adds functionality to track and manage LLM token usage in Datasette. It creates two tables.\n\n- `_llm_usage`: Tracks usage of LLM tokens\n- `_llm_allowance`: Manages credit allowances for LLM usage\n\n### Configuration\n\nBy default the tables are created in the internal database passed to Datasette using `--internal internal.db`. You can change that by setting the following in your Datasette plugin configuration:\n\n```json\n{\n \"plugins\": {\n \"datasette-llm-usage\": {\n \"database\": \"your_database_name\"\n }\n }\n}\n```\n\n### Setting up allowances\n\nBefore using LLM models, you need to set up an allowance in the `_llm_allowance` table. You can do this with SQL like:\n\n```sql\ninsert into _llm_allowance (\n id,\n created,\n credits_remaining,\n daily_reset,\n daily_reset_amount,\n purpose\n) values (\n 1,\n strftime('%s', 'now')\n 10000,\n 0,\n 0,\n null\n);\n```\nThe other columns are not yet used.\n\n### Using the LLM wrapper\n\nThe plugin provides an `LLM` class that wraps the `llm` library to track token usage:\n\n```python\nfrom datasette_llm_usage import LLM\n\nllm = LLM(datasette)\n\n# Get available models\nmodels = llm.get_async_models()\n\n# Get a specific model\nmodel = llm.get_async_model(\"gpt-4o-mini\", purpose=\"my_purpose\")\n\n# Use the model\nresponse = await model.prompt(\"Your prompt here\")\ntext = await response.text()\n```\nUsage will be automatically recorded.\n\n### Built-in endpoint\n\nThe plugin provides a simple demo endpoint at `/-/llm-usage-simple-prompt` that requires authentication and uses the gpt-4o-mini model.\n\n### Supported Models and Pricing\n\nThe plugin includes pricing information for various models including:\n\n- Gemini models (1.5-flash, 1.5-pro)\n- Claude models (3.5-sonnet, 3-opus, 3-haiku)\n- GPT models (gpt-4o, gpt-4o-mini, o1-preview, o1-mini)\n\nDifferent models have different input and output token costs.\n\n## Development\n\nTo set up this plugin locally, first checkout the code. Then create a new virtual environment:\n```bash\ncd datasette-llm-usage\npython -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e '.[test]'\n```\nTo run the tests:\n```bash\npython -m pytest\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Track usage of LLM tokens in a SQLite table",
"version": "0.1a0",
"project_urls": {
"CI": "https://github.com/datasette/datasette-llm-usage/actions",
"Changelog": "https://github.com/datasette/datasette-llm-usage/releases",
"Homepage": "https://github.com/datasette/datasette-llm-usage",
"Issues": "https://github.com/datasette/datasette-llm-usage/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "78fdaeaeb77915a93c0ff6035eaf177ac87368374af527e4ea66446bd668a440",
"md5": "c573834253a1dc08a3a8593ff9f027ba",
"sha256": "1df205c636eeb063daaf74c4794b7f23529194554fad2167a5276238f5ff28b0"
},
"downloads": -1,
"filename": "datasette_llm_usage-0.1a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c573834253a1dc08a3a8593ff9f027ba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 9409,
"upload_time": "2024-12-02T20:40:37",
"upload_time_iso_8601": "2024-12-02T20:40:37.960158Z",
"url": "https://files.pythonhosted.org/packages/78/fd/aeaeb77915a93c0ff6035eaf177ac87368374af527e4ea66446bd668a440/datasette_llm_usage-0.1a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "47a4bdaaa6e0c81b15881c7a2c0881a3135464dee2f673ee1c704ad438325dd7",
"md5": "10f9348fd5210aea0d4e3c636405fb12",
"sha256": "6afc779c99b135a1ad6a74b1dc9dcf1cf4f16298a042bb69639e46e1219b5509"
},
"downloads": -1,
"filename": "datasette_llm_usage-0.1a0.tar.gz",
"has_sig": false,
"md5_digest": "10f9348fd5210aea0d4e3c636405fb12",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 9304,
"upload_time": "2024-12-02T20:40:39",
"upload_time_iso_8601": "2024-12-02T20:40:39.867402Z",
"url": "https://files.pythonhosted.org/packages/47/a4/bdaaa6e0c81b15881c7a2c0881a3135464dee2f673ee1c704ad438325dd7/datasette_llm_usage-0.1a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 20:40:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "datasette",
"github_project": "datasette-llm-usage",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "datasette-llm-usage"
}