Skip to content

Commit 6415b64

Browse files
author
nik
committed
fix: DIA-1629: Enforce template fields in refined prompt
1 parent fd18e21 commit 6415b64

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

adala/utils/parse.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ class TemplateChunks(TypedDict):
110110
text: str
111111
start: int
112112
end: int
113-
type: str
113+
type:
114+
115+
116+
match_fields_regex = re.compile(r"(?<!\{)\{([a-zA-Z0-9_]+)\}(?!})")
114117

115118

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

138-
for match in re.finditer(r"(?<!\{)\{(.*?)\}(?!})", string):
141+
for match in match_fields_regex.finditer(string):
139142
# for match in re.finditer(r'\{(.*?)\}', string):
140143
# Text before field
141144
if last_index < match.start() and include_texts:

0 commit comments

Comments
 (0)