Scott Cogan commited on
Commit
2b4635e
·
1 Parent(s): 1c47798

fix: Preserve system prompt template variables

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -92,10 +92,12 @@ with open("prompts.yaml", 'r') as stream:
92
  # Log the exact content before processing
93
  logger.debug(f"Raw template content: {value}")
94
 
95
- # For system prompt, wrap the entire content in a template expression
96
  if is_system_prompt:
97
- escaped_content = value.replace('"', '\\"').replace('\n', '\\n')
98
- value = f'{{{{ "{escaped_content}" }}}}'
 
 
99
  else:
100
  # For other templates, wrap non-template content
101
  if '{{' not in value and '{%' not in value:
 
92
  # Log the exact content before processing
93
  logger.debug(f"Raw template content: {value}")
94
 
95
+ # For system prompt, ensure proper spacing in template expressions
96
  if is_system_prompt:
97
+ # Ensure proper spacing in template expressions
98
+ value = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', value)
99
+ value = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', value)
100
+ value = value.replace('\n', '\\n')
101
  else:
102
  # For other templates, wrap non-template content
103
  if '{{' not in value and '{%' not in value: