Skip to content

Commit

Permalink
revert feat of omitting curly braces { }
Browse files Browse the repository at this point in the history
it may clash with normal writings
  • Loading branch information
atomiechen committed Aug 9, 2024
1 parent 804898e commit b6e7a65
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/handyllm/prompt_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def split_pattern(self):
return (
r"^\$("
+ "|".join(self.role_keys)
+ r")\$[^\S\r\n]*(?:{([^{}]*?)}|([^{}]*?))?[^\S\r\n]*$"
+ r")\$[^\S\r\n]*(?:{([^{}]*?)})?[^\S\r\n]*$"
)

def detect(self, raw_prompt: str):
Expand Down Expand Up @@ -48,16 +48,17 @@ def raw2msgs(self, raw_prompt: str):
# convert plain text to messages format
msgs = []
blocks = re.split(self.split_pattern, raw_prompt, flags=re.MULTILINE)
for idx in range(1, len(blocks), 4):
for idx in range(1, len(blocks), 3):
role = blocks[idx]
extra = blocks[idx + 1] or blocks[idx + 2]
content = blocks[idx + 3]
extra = blocks[idx + 1]
content = blocks[idx + 2]
if content:
content = content.strip()
msg = {"role": role, "content": content}
if extra:
key_values_pairs = re.findall(
r'(\w+)\s*=\s*("[^"]*"|\'[^\']*\')|(?:(?<=\s)|^)(?:(tool)|(array))(?=\s|$)', extra
r'(\w+)\s*=\s*("[^"]*"|\'[^\']*\')|(?:(?<=\s)|^)(?:(tool)|(array))(?=\s|$)',
extra,
)
# parse extra properties
extra_properties = {}
Expand Down

0 comments on commit b6e7a65

Please sign in to comment.