Merge pull request #16 from iorisa/feature/bug-1113

fixbug: exceed length
This commit is contained in:
send18 2023-09-02 11:00:12 +08:00 committed by GitHub
commit 4a2d610e52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 22 deletions

View file

@ -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."