🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
update:修改get_summary,加上是否保持语言的配置
zhangleid4878f23a004
diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.pyindex 844cd4c1c..26929575c 100644--- a/metagpt/provider/openai_api.py+++ b/metagpt/provider/openai_api.py@@ -221,18 +221,18 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):return CONFIG.max_tokens_rspreturn get_max_completion_tokens(messages, self.model, CONFIG.max_tokens_rsp)- async def get_summary(self, text: str, max_words=200):+ async def get_summary(self, text: str, max_words=200, keep_language: bool = False):max_token_count = DEFAULT_MAX_TOKENSmax_count = 100while max_count > 0:if len(text) < max_token_count:- return await self._get_summary(text, max_words=max_words)+ return await self._get_summary(text=text, max_words=max_words,keep_language=keep_language)padding_size = 20 if max_token_count > 20 else 0text_windows = self.split_texts(text, window_size=max_token_count - padding_size)summaries = []for ws in text_windows:- response = await self._get_summary(ws, max_words=max_words)+ response = await self._get_summary(text=ws, max_words=max_words,keep_language=keep_language)summaries.append(response)if len(summaries) == 1:return summaries[0]@@ -243,11 +243,14 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):max_count -= 1 # safeguardraise openai.error.InvalidRequestError("text too long")- async def _get_summary(self, text: str, max_words=20):+ async def _get_summary(self, text: str, max_words=20, keep_language: bool = False):"""Generate text summary"""if len(text) < max_words:return text- command = f"Translate the above content into a summary of less than {max_words} words."+ if keep_language:+ command = f".Translate the above content into a summary of less than {max_words} words in language of the content."+ else:+ command = f"Translate the above content into a summary of less than {max_words} words."msg = text + "\n\n" + commandlogger.info(f"summary ask:{msg}")response = await self.aask(msg=msg, system_msgs=[])