mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-07-05 16:02:14 +02:00
Merge pull request #16 from iorisa/feature/bug-1113
fixbug: exceed length
This commit is contained in:
commit
4a2d610e52
3 changed files with 50 additions and 22 deletions
|
|
@ -242,14 +242,18 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
"""Generate text title"""
|
||||
max_response_token_count = 50
|
||||
max_token_count = max_token_count_per_ask or CONFIG.MAX_TOKENS or DEFAULT_MAX_TOKENS
|
||||
text_windows = self.split_texts(text, window_size=max_token_count - max_response_token_count)
|
||||
while True:
|
||||
text_windows = self.split_texts(text, window_size=max_token_count - max_response_token_count)
|
||||
|
||||
summaries = []
|
||||
for ws in text_windows:
|
||||
response = await self.get_summary(ws)
|
||||
summaries.append(response)
|
||||
if len(summaries) == 1:
|
||||
return summaries[0]
|
||||
summaries = []
|
||||
for ws in text_windows:
|
||||
response = await self.get_summary(ws, max_words=max_response_token_count)
|
||||
summaries.append(response)
|
||||
if len(summaries) == 1:
|
||||
return summaries[0]
|
||||
text = "\n".join(summaries)
|
||||
if len(text) <= max_words * 2 and len(text) <= max_token_count:
|
||||
break
|
||||
|
||||
language = CONFIG.language or DEFAULT_LANGUAGE
|
||||
command = f"Translate the above summary into a {language} title of less than {max_words} words."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue