From b3dc1eccc38a1f53cbd15550182d9eae59d44808 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Tue, 24 Oct 2023 16:03:06 -0700 Subject: [PATCH] (fix) utils.token trimming ensure new length always greater than 0 --- litellm/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/litellm/utils.py b/litellm/utils.py index 7c67fcf3c..a74874edd 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4156,6 +4156,7 @@ def shorten_message_to_fit_limit( ratio = (tokens_needed) / total_tokens new_length = int(len(content) * ratio) -1 + new_length = max(0, new_length) half_length = new_length // 2 left_half = content[:half_length]