From 9998068512cf040dc5b0d604fa4d22a100c4c637 Mon Sep 17 00:00:00 2001 From: FelixFehse Date: Thu, 18 Apr 2024 13:15:35 +0200 Subject: [PATCH] fix issue 743 --- .../use_cases/summarize/recursive_summarize.py | 1 + tests/use_cases/summarize/test_recursive_summarize.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/intelligence_layer/use_cases/summarize/recursive_summarize.py b/src/intelligence_layer/use_cases/summarize/recursive_summarize.py index d1a5a5426..1e51df707 100644 --- a/src/intelligence_layer/use_cases/summarize/recursive_summarize.py +++ b/src/intelligence_layer/use_cases/summarize/recursive_summarize.py @@ -51,6 +51,7 @@ def do_run( num_partial_summaries = 0 text_to_summarize = input.text summary = "" + num_generated_tokens = 0 while True: summarize_output = self.long_context_summarize_task.run( LongContextSummarizeInput( diff --git a/tests/use_cases/summarize/test_recursive_summarize.py b/tests/use_cases/summarize/test_recursive_summarize.py index 5fc16d647..1f23c01ae 100644 --- a/tests/use_cases/summarize/test_recursive_summarize.py +++ b/tests/use_cases/summarize/test_recursive_summarize.py @@ -68,6 +68,17 @@ def test_recursive_summarize_stops_when_num_partial_summaries_stays_same( assert output.generated_tokens > 50 +def test_recursive_summarize_stops_when_num_partial_summaries_stays_same_with_empty_text( + steerable_long_context_summarize: SteerableLongContextSummarize, +) -> None: + max_tokens = 2048 + input = RecursiveSummarizeInput(text="", max_tokens=max_tokens) + task = RecursiveSummarize(steerable_long_context_summarize) + output = task.run(input, NoOpTracer()) + + assert output.generated_tokens == 0 + + def test_recursive_summarize_stops_after_one_chunk( recursive_counting_client: RecursiveCountingClient, ) -> None: