Skip to content

Commit

Permalink
fix: DIA-1629: Enforce template fields in refined prompt (#292)
Browse files Browse the repository at this point in the history
Co-authored-by: nik <[email protected]>
Co-authored-by: pakelley <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent b21e909 commit 7549f4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 611 deletions.
5 changes: 4 additions & 1 deletion adala/utils/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class TemplateChunks(TypedDict):
start: int
end: int
type: str


match_fields_regex = re.compile(r"(?<!\{)\{([a-zA-Z0-9_]+)\}(?!})")


def parse_template(string, include_texts=True) -> List[TemplateChunks]:
Expand All @@ -135,7 +138,7 @@ def parse_template(string, include_texts=True) -> List[TemplateChunks]:
chunks: List[TemplateChunks] = []
last_index = 0

for match in re.finditer(r"(?<!\{)\{(.*?)\}(?!})", string):
for match in match_fields_regex.finditer(string):
# for match in re.finditer(r'\{(.*?)\}', string):
# Text before field
if last_index < match.start() and include_texts:
Expand Down
Loading

0 comments on commit 7549f4f

Please sign in to comment.