Replaying cache for LangChain
This is a replay cache implementation for LangChain. It is useful when you want to make the same LLM queries, and you do not want to get a single answer from the cache each time.
replay_cache wraps any cache from LangChain and remembers not only prompt & LLM configuration but also
adds a sequential number to the cached value.
So when it is used for the first time,
it will only fill the cache and query the model each time.
When replay_cache is used again over the same cache, then it will return
the results from the cache in the order
how it was obtained in the previous run (on the same prompts over the same models).
Each pair prompt & LLM configuration remembers its own order
of responses. If a query is called more times than in the previous run,
then a model is queried again and the result is stored in cached.
Installation
$ pip install replay_cache
Example
Without replay cache
cache = InMemoryCache()
set_llm_cache(cache)
llm.invoke("How are you?") # Answer A (model queried)
llm.invoke("How are you?") # Answer A (taken from cache)
llm.invoke("How are you?") # Answer A (taken from cache)
With replay cache
from replay_cache import replay_cache
cache = InMemoryCache()
with replay_cache(cache):
llm.invoke("How are you?") # Answer A (model queried)
llm.invoke("How are you?") # Answer B (model queried)
llm.invoke("How are you?") # Answer C (model queried)
with replay_cache(cache):
llm.invoke("How are you?") # Answer A (taken from cache)
llm.invoke("How are you?") # Answer B (taken from cache)
llm.invoke("How are you?") # Answer C (taken from cache)
llm.invoke("How are you?") # Answer D (model queried)
with replay_cache(cache):
llm.invoke("How are you?") # Answer A (taken from cache)
llm.invoke("How are you?") # Answer B (taken from cache)
from replay_cache import replay_cache
cache = InMemoryCache()
with replay_cache(cache):
llm.invoke("How are you?") # Answer A (model queried)
llm.invoke("How are you?") # Answer B (model queried)
llm.invoke("What is your name?") # Answer C (model queried)
llm.invoke("What is your name?") # Answer D (model queried)
with replay_cache(cache):
llm.invoke("How are you?") # Answer A (taken from cache)
llm.invoke("What is your name?") # Answer C (taken from cache)
llm.invoke("How are you?") # Answer B (taken from cache)
llm.invoke("What is your name?") # Answer D (taken from cache)
Metadata
Release files for replay-cache 0.2.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 |
|---|---|---|---|---|
| replay_cache-0.2.0.tar.gz | 2.7 kB | Without provenance | Details for replay_cache-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| replay_cache-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for replay_cache-0.2.0-py3-none-any.whl |
Total release size: 6.2 kB
Release files / replay_cache-0.2.0.tar.gz
| Download URL | replay_cache-0.2.0.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
37b1708307f4375ba1d37cbf332d550da2625e69adeae9ede796806ae5341216
|
|
BLAKE2b-256 checksum How to use checksums |
510936eafd358b918d9c2b0f75aa84f4fe7f39e28f50ce6693e857b55f53350a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.12 Linux/6.5.0-21-generic
|
Release files / replay_cache-0.2.0-py3-none-any.whl
| Download URL | replay_cache-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea0f29d6fad10faa8ba34873769d40be7b90cc4fd8d2588038bc776935cc55f1
|
|
BLAKE2b-256 checksum How to use checksums |
12adca6f625950265f44fcb13bc600d88ce5d5bcdd4713e49a03dfb5d4ff6e8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.6.1 CPython/3.10.12 Linux/6.5.0-21-generic
|
Security for replay-cache 0.2.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.