Spaces:
Runtime error
Runtime error
Scott Cogan commited on
Commit ·
4481e03
1
Parent(s): 2304ec1
fix: simplify template processing to prevent double-wrapping and ensure proper spacing
Browse files
app.py
CHANGED
|
@@ -90,23 +90,15 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 90 |
if not isinstance(template_content, str):
|
| 91 |
return template_content
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
if
|
| 95 |
-
#
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
return
|
| 100 |
|
| 101 |
-
# For non-
|
| 102 |
-
if '{{' not in template_content and '{%' not in template_content:
|
| 103 |
-
return template_content
|
| 104 |
-
|
| 105 |
-
# If it's already wrapped in double curly braces, return as is
|
| 106 |
-
if template_content.startswith('{{') and template_content.endswith('}}'):
|
| 107 |
-
return template_content
|
| 108 |
-
|
| 109 |
-
# Otherwise, wrap in double curly braces
|
| 110 |
return f"{{{{ {template_content} }}}}"
|
| 111 |
|
| 112 |
logger.debug("Starting template processing...")
|
|
@@ -199,38 +191,12 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 199 |
agent_templates[key] = {}
|
| 200 |
for subkey, subvalue in value.items():
|
| 201 |
if isinstance(subvalue, str):
|
| 202 |
-
#
|
| 203 |
-
|
| 204 |
-
# Keep system prompt as is, only ensure proper spacing in template expressions
|
| 205 |
-
content = subvalue
|
| 206 |
-
content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
|
| 207 |
-
content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
|
| 208 |
-
else:
|
| 209 |
-
# For other templates, only wrap if not already a template
|
| 210 |
-
content = subvalue
|
| 211 |
-
if '{{' not in content and '{%' not in content:
|
| 212 |
-
content = f'{{{{ "{content}" }}}}'
|
| 213 |
-
else:
|
| 214 |
-
# Ensure proper spacing in template expressions
|
| 215 |
-
content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
|
| 216 |
-
content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
|
| 217 |
agent_templates[key][subkey] = content
|
| 218 |
elif isinstance(value, str):
|
| 219 |
-
#
|
| 220 |
-
|
| 221 |
-
# Keep system prompt as is, only ensure proper spacing in template expressions
|
| 222 |
-
content = value
|
| 223 |
-
content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
|
| 224 |
-
content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
|
| 225 |
-
else:
|
| 226 |
-
# For other templates, only wrap if not already a template
|
| 227 |
-
content = value
|
| 228 |
-
if '{{' not in content and '{%' not in content:
|
| 229 |
-
content = f'{{{{ "{content}" }}}}'
|
| 230 |
-
else:
|
| 231 |
-
# Ensure proper spacing in template expressions
|
| 232 |
-
content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
|
| 233 |
-
content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
|
| 234 |
agent_templates[key] = content
|
| 235 |
else:
|
| 236 |
agent_templates[key] = value
|
|
|
|
| 90 |
if not isinstance(template_content, str):
|
| 91 |
return template_content
|
| 92 |
|
| 93 |
+
# If it's already a template (contains {{ or {%), return as is
|
| 94 |
+
if '{{' in template_content or '{%' in template_content:
|
| 95 |
+
# Just ensure proper spacing in template expressions
|
| 96 |
+
content = template_content
|
| 97 |
+
content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
|
| 98 |
+
content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
|
| 99 |
+
return content
|
| 100 |
|
| 101 |
+
# For non-template strings, wrap in double curly braces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
return f"{{{{ {template_content} }}}}"
|
| 103 |
|
| 104 |
logger.debug("Starting template processing...")
|
|
|
|
| 191 |
agent_templates[key] = {}
|
| 192 |
for subkey, subvalue in value.items():
|
| 193 |
if isinstance(subvalue, str):
|
| 194 |
+
# Process template with proper spacing
|
| 195 |
+
content = process_template(subvalue, key == 'system_prompt')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
agent_templates[key][subkey] = content
|
| 197 |
elif isinstance(value, str):
|
| 198 |
+
# Process template with proper spacing
|
| 199 |
+
content = process_template(value, key == 'system_prompt')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
agent_templates[key] = content
|
| 201 |
else:
|
| 202 |
agent_templates[key] = value
|