Provide the utility to count the token saved using Semantic Cache
Open
@justin-cechmanek is already working on this.
Since Aug 20, 2024.
enhancement
- Dominant language
- Python
- Stars
- 427
- Forks
- 101
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 20
Description
It would be nice to have an optional mode permitting to monitor the number of token the Semantic Cache permits to save.
To do so, today we can store the token as metadata item.
from langchain_community.callbacks import get_openai_callback
with get_openai_callback() as cb:
response = agent.run(input=user_query, callbacks=[retrieval_handler])
red.set("query_token_total",cb.total_tokens)
red.incr("session_token",cb.total_tokens)
return response
(...)
metadata=dict()
if int(red.get("query_token_total").decode('utf-8'))!=0:
metadata["token"]= int(red.get("query_token_total").decode('utf-8'))
llmcache.store(user_query, response, metadata=metadata)
else:
llmcache.store(user_query, response)
I am wondering if it would make sense to make such easier as it permits to highlight the Semantic Cache value.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.