Skip to content

Commit

Permalink
Improved asterisks removal when whole sentence contained in asterisks (
Browse files Browse the repository at this point in the history
  • Loading branch information
art-from-the-machine authored Aug 22, 2024
1 parent 8ffa82b commit 8ceaecb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/output_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def remove_as_a(sentence: str) -> str:
def parse_asterisks_brackets(sentence: str) -> str:
if ('*' in sentence):
original_sentence = sentence
sentence = re.sub(r'\*[^*]*\*', '', sentence)
sentence = re.sub(r'\*[^*]*?\*', '', sentence)
sentence = sentence.replace('*', '')

if sentence != original_sentence:
removed_text = original_sentence.replace(sentence, '').strip()
removed_text = original_sentence.replace(sentence.strip(), '').strip()
logging.log(28, f"Removed asterisks text from response: {removed_text}")

if ('(' in sentence) or (')' in sentence):
Expand Down Expand Up @@ -199,10 +199,15 @@ async def process_response(self, active_character: Character, blocking_queue: se
sentence += content
# Check for the last occurrence of sentence-ending punctuation
last_punctuation = max(sentence.rfind(p) for p in self.__end_of_sentence_chars)
if last_punctuation != -1:
asterisks_count = sentence.count('*')
if (last_punctuation != -1) and (asterisks_count % 2 == 0):
# Split the sentence at the last punctuation mark
remaining_content = sentence[last_punctuation + 1:]
current_sentence = sentence[:last_punctuation + 1]
# if sentence is contained in bracket or asterisk, include the bracket / asterisk
if remaining_content.strip() in ['*',')','}',']']:
remaining_content = ''
else:
current_sentence = sentence[:last_punctuation + 1]

current_sentence = self.clean_sentence(current_sentence)
if not current_sentence:
Expand Down

0 comments on commit 8ceaecb

Please sign in to comment.