Spaces:
Runtime error
Runtime error
Scott Cogan commited on
Commit ·
17177b2
1
Parent(s): a3a0c02
fix: Ensure all content is valid Jinja2 template syntax
Browse files
app.py
CHANGED
|
@@ -92,27 +92,18 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 92 |
# Log the exact content before processing
|
| 93 |
logger.debug(f"Raw template content: {value}")
|
| 94 |
|
| 95 |
-
#
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
# Handle newlines
|
| 106 |
-
value = value.replace('\n', '\\n')
|
| 107 |
-
|
| 108 |
-
logger.debug(f"Processed template with syntax: {value}")
|
| 109 |
-
else:
|
| 110 |
-
# For non-template content, just handle newlines
|
| 111 |
-
value = value.replace('\n', '\\n')
|
| 112 |
-
logger.debug(f"Processed non-template content: {value}")
|
| 113 |
|
| 114 |
-
|
| 115 |
-
logger.debug(f"Final processed content: {value}")
|
| 116 |
except Exception as e:
|
| 117 |
logger.error(f"Error processing template string: {str(e)}")
|
| 118 |
raise
|
|
|
|
| 92 |
# Log the exact content before processing
|
| 93 |
logger.debug(f"Raw template content: {value}")
|
| 94 |
|
| 95 |
+
# Ensure proper spacing in template expressions
|
| 96 |
+
value = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', value)
|
| 97 |
+
value = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', value)
|
| 98 |
+
|
| 99 |
+
# Handle newlines
|
| 100 |
+
value = value.replace('\n', '\\n')
|
| 101 |
+
|
| 102 |
+
# If no template syntax exists, wrap in a simple template expression
|
| 103 |
+
if '{{' not in value and '{%' not in value:
|
| 104 |
+
value = f'{{{{ "{value}" }}}}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
logger.debug(f"Processed template content: {value}")
|
|
|
|
| 107 |
except Exception as e:
|
| 108 |
logger.error(f"Error processing template string: {str(e)}")
|
| 109 |
raise
|