Scott Cogan commited on
Commit
9253c9f
·
1 Parent(s): 8c1f404

fix: Use Jinja2 raw tags for non-template content

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -89,10 +89,10 @@ with open("prompts.yaml", 'r') as stream:
89
  if isinstance(value, str):
90
  logger.debug(f"Processing template string: {value[:100]}...")
91
  try:
92
- # Ensure all content is wrapped in a template expression
93
  if not ('{{' in value or '{%' in value):
94
- # If no template syntax, wrap the entire string in a template expression
95
- value = '{{ ' + value.replace('\n', '\\n') + ' }}'
96
  else:
97
  # Process existing template syntax
98
  value = value.replace('{{', '{{ ').replace('}}', ' }}')
@@ -173,7 +173,7 @@ with open("prompts.yaml", 'r') as stream:
173
  system_prompt = prompt_templates['system_prompt']['text']
174
  # Ensure system prompt is a valid template
175
  if not ('{{' in system_prompt or '{%' in system_prompt):
176
- system_prompt = '{{ ' + system_prompt.replace('\n', '\\n') + ' }}'
177
  else:
178
  system_prompt = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', system_prompt)
179
  system_prompt = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', system_prompt)
 
89
  if isinstance(value, str):
90
  logger.debug(f"Processing template string: {value[:100]}...")
91
  try:
92
+ # Ensure all content is properly formatted as a template
93
  if not ('{{' in value or '{%' in value):
94
+ # If no template syntax, wrap the entire string in raw tags
95
+ value = '{% raw %}' + value.replace('\n', '\\n') + '{% endraw %}'
96
  else:
97
  # Process existing template syntax
98
  value = value.replace('{{', '{{ ').replace('}}', ' }}')
 
173
  system_prompt = prompt_templates['system_prompt']['text']
174
  # Ensure system prompt is a valid template
175
  if not ('{{' in system_prompt or '{%' in system_prompt):
176
+ system_prompt = '{% raw %}' + system_prompt.replace('\n', '\\n') + '{% endraw %}'
177
  else:
178
  system_prompt = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', system_prompt)
179
  system_prompt = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', system_prompt)