improve backticks

This commit is contained in:
Hussam.lawen
2024-01-15 19:07:41 +02:00
parent ea39e8684f
commit 31576b77ff
3 changed files with 45 additions and 64 deletions

View File

@ -474,4 +474,13 @@ def clip_tokens(text: str, max_tokens: int, add_three_dots=True) -> str:
return clipped_text
except Exception as e:
get_logger().warning(f"Failed to clip tokens: {e}")
return text
return text
def replace_code_tags(text):
"""
Replace odd instances of ` with <code> and even instances of ` with </code>
"""
parts = text.split('`')
for i in range(1, len(parts), 2):
parts[i] = '<code>' + parts[i] + '</code>'
return ''.join(parts)