From 726dad57560888c619943dc4fc73aa83cf34a38e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 6 Mar 2024 18:07:28 -0800 Subject: [PATCH 1/4] fix(caching.py): add s3 path as a top-level param --- litellm/caching.py | 3 +++ litellm/tests/test_caching.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/caching.py b/litellm/caching.py index ac9d559dc..bf11f4c39 100644 --- a/litellm/caching.py +++ b/litellm/caching.py @@ -572,6 +572,7 @@ class S3Cache(BaseCache): self.bucket_name = s3_bucket_name self.key_prefix = s3_path.rstrip("/") + "/" if s3_path else "" # Create an S3 client with custom endpoint URL + self.s3_client = boto3.client( "s3", region_name=s3_region_name, @@ -776,6 +777,7 @@ class Cache: s3_aws_secret_access_key: Optional[str] = None, s3_aws_session_token: Optional[str] = None, s3_config: Optional[Any] = None, + s3_path: Optional[str] = None, redis_semantic_cache_use_async=False, redis_semantic_cache_embedding_model="text-embedding-ada-002", **kwargs, @@ -825,6 +827,7 @@ class Cache: s3_aws_secret_access_key=s3_aws_secret_access_key, s3_aws_session_token=s3_aws_session_token, s3_config=s3_config, + s3_path=s3_path, **kwargs, ) if "cache" not in litellm.input_callback: diff --git a/litellm/tests/test_caching.py b/litellm/tests/test_caching.py index f649bff02..3518b4cd8 100644 --- a/litellm/tests/test_caching.py +++ b/litellm/tests/test_caching.py @@ -698,7 +698,6 @@ def test_s3_cache_acompletion_stream_azure(): @pytest.mark.asyncio -@pytest.mark.skip(reason="AWS Suspended Account") async def test_s3_cache_acompletion_azure(): import asyncio import logging @@ -717,7 +716,9 @@ async def test_s3_cache_acompletion_azure(): } ] litellm.cache = Cache( - type="s3", s3_bucket_name="cache-bucket-litellm", s3_region_name="us-west-2" + type="s3", + s3_bucket_name="litellm-my-test-bucket-2", + s3_region_name="us-east-1", ) print("s3 Cache: test for caching, streaming + completion") From c3c0727366ffb6ac562c9636e3322005240dff0e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 6 Mar 2024 18:53:30 -0800 Subject: [PATCH 2/4] fix(factory.py): retry failed get request --- litellm/llms/prompt_templates/factory.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index e776bee50..616833a2e 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -485,7 +485,12 @@ def convert_url_to_base64(url): import requests import base64 - response = requests.get(url) + for _ in range(3): + try: + response = requests.get(url) + break + except: + pass if response.status_code == 200: image_bytes = response.content base64_image = base64.b64encode(image_bytes).decode("utf-8") @@ -536,6 +541,8 @@ def convert_to_anthropic_image_obj(openai_image_url: str): "data": base64_data, } except Exception as e: + if "Error: Unable to fetch image from URL" in str(e): + raise e raise Exception( """Image url not in expected format. Example Expected input - "image_url": "data:image/jpeg;base64,{base64_image}". Supported formats - ['image/jpeg', 'image/png', 'image/gif', 'image/webp'] """ ) From f1aa400d91f1483113b25a1bd218ccc5275ba2c6 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 6 Mar 2024 19:07:38 -0800 Subject: [PATCH 3/4] test(test_completion.py): temporary patch for wikipedia get image issue --- litellm/tests/test_completion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/litellm/tests/test_completion.py b/litellm/tests/test_completion.py index af00275d3..d2d74bba5 100644 --- a/litellm/tests/test_completion.py +++ b/litellm/tests/test_completion.py @@ -219,6 +219,7 @@ def test_completion_claude_3_base64(): pytest.fail(f"An exception occurred - {str(e)}") +@pytest.mark.skip(reason="issue getting wikipedia images in ci/cd") def test_completion_claude_3_function_plus_image(): litellm.set_verbose = True From 2163e43b9a97a58c56b61a196e4f4160aed44f07 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Wed, 6 Mar 2024 19:21:57 -0800 Subject: [PATCH 4/4] test(test_parallel_request_limiter.py): add more verbose logging --- litellm/tests/test_parallel_request_limiter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/litellm/tests/test_parallel_request_limiter.py b/litellm/tests/test_parallel_request_limiter.py index bd5185a23..627e395cf 100644 --- a/litellm/tests/test_parallel_request_limiter.py +++ b/litellm/tests/test_parallel_request_limiter.py @@ -647,6 +647,7 @@ async def test_streaming_router_tpm_limit(): @pytest.mark.asyncio async def test_bad_router_call(): + litellm.set_verbose = True model_list = [ { "model_name": "azure-model",