fix(backend): filter out <br> tags from prompt context
Filter out potential web-scraping or legacy artifacts like <br>, <br/>, <br\> from prefix/suffix before using in model completion context
This commit is contained in:
+6
-1
@@ -37,8 +37,13 @@ def _sanitize_language_id(language_id: str) -> str:
|
|||||||
def _prepare_context(prefix: str, suffix: str) -> Tuple[str, str]:
|
def _prepare_context(prefix: str, suffix: str) -> Tuple[str, str]:
|
||||||
"""
|
"""
|
||||||
Prepare prefix/suffix for model completion context.
|
Prepare prefix/suffix for model completion context.
|
||||||
|
Filter out potential web-scraping or legacy artifacts like <br>, <br/>, <br\>.
|
||||||
"""
|
"""
|
||||||
return prefix, suffix
|
import re
|
||||||
|
br_pattern = re.compile(r'<br\s*/?\s*\\?>', re.IGNORECASE)
|
||||||
|
clean_prefix = br_pattern.sub('', prefix or "")
|
||||||
|
clean_suffix = br_pattern.sub('', suffix or "")
|
||||||
|
return clean_prefix, clean_suffix
|
||||||
|
|
||||||
|
|
||||||
def prepare_prompt_context(prefix: str, suffix: str) -> Tuple[str, str]:
|
def prepare_prompt_context(prefix: str, suffix: str) -> Tuple[str, str]:
|
||||||
|
|||||||
Reference in New Issue
Block a user