LLMTrack is a Python package for enabling caching (avoiding repeated API calls) and recording token usage on a per-model basis.
Why do we call it "per-model"? Because we want to track the token usage and cache for each model separately under the root directory, following the rule
{root_dir}/{client name}/{model name}.
Installation
pip install llmtrack
Root Directory for Saving Cache and Token Usage
By default, the root directory for saving cache and token usage is the current working directory (os.getcwd()). You can change it, as follows:
from llmtrack import set_root_dir, get_root_dir
set_root_dir("~/my_project/llmtrack")
print(get_root_dir())
Caching and Recording Token Usage
You can use get_llm to get a language model instance, as follows:
from llmtrack import get_llm
client_name = "openai"
model_name = "gpt-4o-mini"
llm = get_llm(f"{client_name}/{model_name}", cache=True, token_usage=True)
usr_message = "ONLY generate a positve word"
client_response = llm.respond(usr_message, verbal=True)
After running the code above, the cache and token-usage files will be stored in ~/my_project/llmtrack/openai/gpt-4o-mini, following the rule {root_dir}/{client name}/{model name}. Now, if you invoke the same model with the same prompt, the cache will be used.
You can check the token usage and cache by:
# check token usage
print('Token Usage')
usage = llm.token_usage
print(usage)
# check cache
print('\n\nCache')
cache_key = llm.get_cache_key(usr_message)
print(llm.cache[cache_key])
Supported Clients and Model Names
Public LLM APIs are specified by simply specifying model_name consisting of API providers and model names. The supported APIs include :
- OpenAI, e.g., "openai/xxxx" (xxxx should be replaced by specific model names)
- The environment variable has to be setup:
OPENAI_API_KEY
- All Available
model_name: See the document
- The environment variable has to be setup:
- Azure OpenAI, e.g., "azure_openai/chatgpt-4k"
- The three environment variables have to be setup:
AZURE_OPENAI_ENDPOINT,AZURE_OPENAI_API_KEY,AZURE_OPENAI_API_VERSION - Ask providers for specific model names
- The three environment variables have to be setup:
- MoonShot, e.g., "moonshot/moonshot-v1-8k"
- The environment variable has to be setup:
MOONSHOT_API_KEY
- The environment variable has to be setup:
- Groq
- All Available
model_name: See the document
- All Available
Metadata
Release files for llmtrack 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| llmtrack-1.0.0.tar.gz | 11.4 kB | Without provenance | Details for llmtrack-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| llmtrack-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for llmtrack-1.0.0-py3-none-any.whl |
Total release size: 22.9 kB
Release files / llmtrack-1.0.0.tar.gz
| Download URL | llmtrack-1.0.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61d6ba66c6b9da476725078777dcd4b13117f60d0c26c292716749f9d0455350
|
|
BLAKE2b-256 checksum How to use checksums |
664776d3499ed34887ca129273c32fa23978b43d62d800a99f03294c287eea93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.2
|
Release files / llmtrack-1.0.0-py3-none-any.whl
| Download URL | llmtrack-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dbc3f13f28acc2ab6fcabfb05f11dd54228ed0445f767ad7510b7dfbf72e0b6b
|
|
BLAKE2b-256 checksum How to use checksums |
4c51a15c62231d1d8cfa76e0beaa40580df521edf5132dc95608fbfdae1a60a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.2
|
Security for llmtrack 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.