Skip to content

Commit

Permalink
Document regex
Browse files Browse the repository at this point in the history
  • Loading branch information
monst committed Oct 10, 2023
1 parent 153d2b7 commit 28961f0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/services/guidance_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def query(self) -> dict:
ValueError: if handlebars do not generate 'response'
"""

# Perform a regex search to find the names of the variables being generated
# by the handlebars template
# This regex matches strings like: {{gen 'response' temperature=0.0 max_tokens=500}}
# and extracts the variable name 'response'
import re

pattern = r'{{(?:gen|geneach|set) [\'"]([^\'"]+)[\'"]$}}'
var_names = re.findall(pattern, self.handlebars)

Expand Down

0 comments on commit 28961f0

Please sign in to comment.