debug cache circle ci

This commit is contained in:
ishaan-jaff 2023-08-10 15:03:33 -07:00
parent 2fb321c63b
commit 5c92a597e5
2 changed files with 8 additions and 2 deletions

View file

@ -16,7 +16,7 @@ jobs:
pip install infisical pip install infisical
pip install pytest pip install pytest
pip install openai[datalib] pip install openai[datalib]
pip install chromadb pip install -Uq chromadb
# Run pytest and generate JUnit XML report # Run pytest and generate JUnit XML report
- run: - run:

View file

@ -724,24 +724,29 @@ def add_cache(messages, model_response):
global cache_collection global cache_collection
if cache_collection == None: if cache_collection == None:
make_collection() make_collection()
print("cache collection in add cache", cache_collection)
user_question = message_to_user_question(messages) user_question = message_to_user_question(messages)
cache_collection.add( cache_collection.add(
documents=[user_question], documents=[user_question],
metadatas=[{"model_response": str(model_response)}], metadatas=[{"model_response": str(model_response)}],
ids = [ str(uuid.uuid4())] ids = [ str(uuid.uuid4())]
) )
print("in add cache, peek()", cache_collection.peek())
return return
def get_cache(messages): def get_cache(messages):
print("in get cache")
try: try:
global cache_collection global cache_collection
if cache_collection == None: if cache_collection == None:
make_collection() make_collection()
print("cache collection", cache_collection)
user_question = message_to_user_question(messages) user_question = message_to_user_question(messages)
results = cache_collection.query( results = cache_collection.query(
query_texts=[user_question], query_texts=[user_question],
n_results=1 n_results=1
) )
print("query cache result", results)
distance = results['distances'][0][0] distance = results['distances'][0][0]
sim = (1 - distance) sim = (1 - distance)
if sim >= litellm.cache_similarity_threshold: if sim >= litellm.cache_similarity_threshold:
@ -751,5 +756,6 @@ def get_cache(messages):
else: else:
# no hit # no hit
return None return None
except: except Exception as e:
print("error in get cache", e)
return None return None