From 578256a6a281f0f70a84d56a9f1ac91c54bf5151 Mon Sep 17 00:00:00 2001 From: Duarte OC Date: Thu, 18 Jan 2024 11:38:05 +0100 Subject: [PATCH 1/3] Update s3 cache to support folder --- litellm/integrations/s3.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/integrations/s3.py b/litellm/integrations/s3.py index 0187d13d6a67..c6d64dc02ac5 100644 --- a/litellm/integrations/s3.py +++ b/litellm/integrations/s3.py @@ -16,6 +16,7 @@ class S3Logger: def __init__( self, s3_bucket_name=None, + s3_path=None, s3_region_name=None, s3_api_version=None, s3_use_ssl=True, @@ -57,6 +58,7 @@ def __init__( # done reading litellm.s3_callback_params self.bucket_name = s3_bucket_name + self.s3_path = s3_path # Create an S3 client with custom endpoint URL self.s3_client = boto3.client( "s3", @@ -122,8 +124,9 @@ def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose): pass s3_object_key = ( + (self.s3_path.rstrip('/') + '/' if self.s3_path else '') + payload["id"] + "-time=" + str(start_time) - ) # we need the s3 key to include the time, so we log cache hits too + ) import json From dbadd6439591328c1836c22e2031c2388667f33d Mon Sep 17 00:00:00 2001 From: Duarte OC Date: Thu, 18 Jan 2024 17:26:38 +0100 Subject: [PATCH 2/3] revert comment --- litellm/integrations/s3.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/s3.py b/litellm/integrations/s3.py index c6d64dc02ac5..98614949ea98 100644 --- a/litellm/integrations/s3.py +++ b/litellm/integrations/s3.py @@ -124,9 +124,11 @@ def log_event(self, kwargs, response_obj, start_time, end_time, print_verbose): pass s3_object_key = ( - (self.s3_path.rstrip('/') + '/' if self.s3_path else '') + - payload["id"] + "-time=" + str(start_time) - ) + (self.s3_path.rstrip("/") + "/" if self.s3_path else "") + + payload["id"] + + "-time=" + + str(start_time) + ) # we need the s3 key to include the time, so we log cache hits too import json From 5d0654e6f66b75ce79ebeb6bba0bc508aaf48e70 Mon Sep 17 00:00:00 2001 From: Duarte OC Date: Thu, 18 Jan 2024 17:32:42 +0100 Subject: [PATCH 3/3] docs --- docs/my-website/docs/caching/redis_cache.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/my-website/docs/caching/redis_cache.md b/docs/my-website/docs/caching/redis_cache.md index 3d70c5e3dbb6..8a580f087ca7 100644 --- a/docs/my-website/docs/caching/redis_cache.md +++ b/docs/my-website/docs/caching/redis_cache.md @@ -204,6 +204,7 @@ def __init__( s3_bucket_name: Optional[str] = None, s3_region_name: Optional[str] = None, s3_api_version: Optional[str] = None, + s3_path: Optional[str] = None, # if you wish to save to a spefic path s3_use_ssl: Optional[bool] = True, s3_verify: Optional[Union[bool, str]] = None, s3_endpoint_url: Optional[str] = None,