Spaces:
Runtime error
Runtime error
Scott Cogan commited on
Commit ·
7c709cd
1
Parent(s): 97f78cf
fix: Simplify template processing to only handle template variables
Browse files
app.py
CHANGED
|
@@ -89,12 +89,8 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 89 |
if isinstance(value, str):
|
| 90 |
logger.debug(f"Processing template string: {value[:100]}...")
|
| 91 |
try:
|
| 92 |
-
#
|
| 93 |
if '{{' in value or '{%' in value:
|
| 94 |
-
# Pre-process the template to ensure it's valid Jinja2
|
| 95 |
-
# Replace any non-template content with a comment
|
| 96 |
-
value = re.sub(r'(?<!{{|{%)([^{}]+)(?!}}|%})', lambda m: '{# ' + m.group(1) + ' #}', value)
|
| 97 |
-
|
| 98 |
# Ensure template variables are properly formatted
|
| 99 |
value = value.replace('{{', '{{ ').replace('}}', ' }}')
|
| 100 |
value = value.replace('{%', '{% ').replace('%}', ' %}')
|
|
@@ -174,8 +170,9 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 174 |
# Pre-process the system prompt template
|
| 175 |
if 'system_prompt' in prompt_templates and 'text' in prompt_templates['system_prompt']:
|
| 176 |
system_prompt = prompt_templates['system_prompt']['text']
|
| 177 |
-
#
|
| 178 |
-
system_prompt = re.sub(r'
|
|
|
|
| 179 |
prompt_templates['system_prompt']['text'] = system_prompt
|
| 180 |
logger.debug("Pre-processed system prompt template")
|
| 181 |
|
|
|
|
| 89 |
if isinstance(value, str):
|
| 90 |
logger.debug(f"Processing template string: {value[:100]}...")
|
| 91 |
try:
|
| 92 |
+
# Only process if template syntax is present
|
| 93 |
if '{{' in value or '{%' in value:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
# Ensure template variables are properly formatted
|
| 95 |
value = value.replace('{{', '{{ ').replace('}}', ' }}')
|
| 96 |
value = value.replace('{%', '{% ').replace('%}', ' %}')
|
|
|
|
| 170 |
# Pre-process the system prompt template
|
| 171 |
if 'system_prompt' in prompt_templates and 'text' in prompt_templates['system_prompt']:
|
| 172 |
system_prompt = prompt_templates['system_prompt']['text']
|
| 173 |
+
# Only process template variables, leave other text unchanged
|
| 174 |
+
system_prompt = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', system_prompt)
|
| 175 |
+
system_prompt = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', system_prompt)
|
| 176 |
prompt_templates['system_prompt']['text'] = system_prompt
|
| 177 |
logger.debug("Pre-processed system prompt template")
|
| 178 |
|