Skip to content

Commit

Permalink
Add filter for markdown structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Aug 12, 2023
1 parent 6a5b1cc commit 5a1618c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def do_gpt_translate(plaintext, messages):
if "' in English" in translated:
translated = translated.split("' in English")[0]

# Filter:
# We can discuss more clearly on Discord.
# Please ensure to maintain the markdown structure.
# to:
# We can discuss more clearly on Discord.
lines = translated.split('\n')
if len(lines) > 0 and 'maintain' in lines[-1] and 'markdown structure' in lines[-1]:
translated = '\n'.join(lines[:-1])

return (translated, True)
except openai.InvalidRequestError as e:
if e.code == 'context_length_exceeded':
Expand Down

0 comments on commit 5a1618c

Please sign in to comment.