From 327e5fc9871cff1693fef512bd9a09645c69a7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Tue, 5 Sep 2023 00:02:21 +0800 Subject: [PATCH] fixbug: last_talk --- metagpt/provider/openai_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py index d0dd5b9d8..9f65dd905 100644 --- a/metagpt/provider/openai_api.py +++ b/metagpt/provider/openai_api.py @@ -226,15 +226,17 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter): async def get_summary(self, text: str, max_words=200, keep_language: bool = False): max_token_count = DEFAULT_MAX_TOKENS max_count = 100 + text_length = len(text) while max_count > 0: - if len(text) < max_token_count: + if text_length < max_token_count: return await self._get_summary(text=text, max_words=max_words, keep_language=keep_language) padding_size = 20 if max_token_count > 20 else 0 text_windows = self.split_texts(text, window_size=max_token_count - padding_size) + part_max_words = int(max_words / len(text_windows)) + 1 summaries = [] for ws in text_windows: - response = await self._get_summary(text=ws, max_words=max_words, keep_language=keep_language) + response = await self._get_summary(text=ws, max_words=part_max_words, keep_language=keep_language) summaries.append(response) if len(summaries) == 1: return summaries[0]