From f2da34517379d693f1c8cf7a626183e813b412a3 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 3 Jan 2024 17:29:27 +0530 Subject: [PATCH] fix(caching.py): handle cached_response being a dict not json string --- litellm/caching.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/caching.py b/litellm/caching.py index 3dc70d2b5..0b1e18e46 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -498,9 +498,12 @@ class Cache: # cached_response is in `b{} convert it to ModelResponse cached_response = cached_result.get("response") try: - cached_response = json.loads( - cached_response - ) # Convert string to dictionary + if isinstance(cached_response, dict): + pass + else: + cached_response = json.loads( + cached_response + ) # Convert string to dictionary except: cached_response = ast.literal_eval(cached_response) return cached_response