tired!"SQLite Cache‚Äãrm .langchain.db# We can do the same thing with a SQLite cachefrom langchain.cache import SQLiteCacheset_llm_cache(SQLiteCache(database_path=".langchain.db"))# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 33.2 ms, sys: 18.1 ms, total: 51.2 ms    Wall time: 667 ms    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'# The second time it is, so it goes fasterllm("Tell me a joke")    CPU times: user 4.86 ms, sys: 1.97 ms, total: 6.83 ms    Wall time: 5.79 ms    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'Upstash Redis Cache‚ÄãStandard Cache‚ÄãUse Upstash Redis to cache prompts and responses with a serverless HTTP API.from upstash_redis import Redisfrom langchain.cache import UpstashRedisCacheURL = "<UPSTASH_REDIS_REST_URL>"TOKEN = "<UPSTASH_REDIS_REST_TOKEN>"langchain.llm_cache = UpstashRedisCache(redis_=Redis(url=URL, token=TOKEN))# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 7.56 ms, sys: 2.98 ms, total: 10.5 ms    Wall time: 1.14 s    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side!'# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 2.78 ms, sys: 1.95 ms, total: 4.73 ms    Wall time: 82.9 ms    '\n\nTwo guys stole a calendar. They got six months each.'Redis Cache‚ÄãStandard Cache‚ÄãUse Redis to cache prompts and responses.# We can do the same thing with a Redis cache# (make sure your local Redis instance is running first before running this example)from redis import Redisfrom langchain.cache import RedisCacheset_llm_cache(RedisCache(redis_=Redis()))# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 6.88 ms, sys: 8.75 ms, total: 15.6 ms    Wall time: 1.04 s    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side!'# The second time it
This notebook covers how to cache results of individual LLM calls using different caches.
This notebook covers how to cache results of individual LLM calls using different caches. ->: tired!"SQLite Cache‚Äãrm .langchain.db# We can do the same thing with a SQLite cachefrom langchain.cache import SQLiteCacheset_llm_cache(SQLiteCache(database_path=".langchain.db"))# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 33.2 ms, sys: 18.1 ms, total: 51.2 ms    Wall time: 667 ms    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'# The second time it is, so it goes fasterllm("Tell me a joke")    CPU times: user 4.86 ms, sys: 1.97 ms, total: 6.83 ms    Wall time: 5.79 ms    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side.'Upstash Redis Cache‚ÄãStandard Cache‚ÄãUse Upstash Redis to cache prompts and responses with a serverless HTTP API.from upstash_redis import Redisfrom langchain.cache import UpstashRedisCacheURL = "<UPSTASH_REDIS_REST_URL>"TOKEN = "<UPSTASH_REDIS_REST_TOKEN>"langchain.llm_cache = UpstashRedisCache(redis_=Redis(url=URL, token=TOKEN))# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 7.56 ms, sys: 2.98 ms, total: 10.5 ms    Wall time: 1.14 s    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side!'# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 2.78 ms, sys: 1.95 ms, total: 4.73 ms    Wall time: 82.9 ms    '\n\nTwo guys stole a calendar. They got six months each.'Redis Cache‚ÄãStandard Cache‚ÄãUse Redis to cache prompts and responses.# We can do the same thing with a Redis cache# (make sure your local Redis instance is running first before running this example)from redis import Redisfrom langchain.cache import RedisCacheset_llm_cache(RedisCache(redis_=Redis()))# The first time, it is not yet in cache, so it should take longerllm("Tell me a joke")    CPU times: user 6.88 ms, sys: 8.75 ms, total: 15.6 ms    Wall time: 1.04 s    '\n\nWhy did the chicken cross the road?\n\nTo get to the other side!'# The second time it