Skip to content

Commit

Permalink
Improve markdown preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
smathot committed Jan 11, 2025
1 parent 6c375a7 commit 6ac9472
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sigmund/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
#
# When set to True, replies will be logged. This should disabled during
# production for privacy.
log_replies = False
log_replies = os.environ.get('SIGMUND_LOG_REPLIES', False)

# MODELS
#
Expand Down Expand Up @@ -227,9 +227,16 @@ def process_ai_message(msg):
# This pattern looks for a colon possibly followed by any number of
# whitespaces # and/or HTML tags, followed by a newline and a dash, and
# replaces it with a colon, newline, newline, and dash
pattern = r':\s*(<[^>]+>\s*)?\n-'
replacement = ':\n\n-'
return re.sub(pattern, replacement, msg)
# pattern = r':\s*(<[^>]+>\s*)?\n-'
pattern = r':\s*(<[^>]+>\s*)?\n(?=-|\d+\.)'
replacement = ':\n\n'
msg = re.sub(pattern, replacement, msg)
# If the message doesn't start with a letter, then it may start with some
# markdown character that we should properly interpret, and thus needs to
# be on a newline preceded by an empty line.
if msg and not msg[0].isalpha():
msg = '\n\n' + msg
return msg


def validate_user(username, password):
Expand Down

0 comments on commit 6ac9472

Please sign in to comment.