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

fix: Wrap system prompt in template expression

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -92,20 +92,19 @@ 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, only ensure proper spacing in template expressions
96
  if is_system_prompt:
97
- value = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', value)
98
- value = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', value)
99
- value = value.replace('\n', '\\n')
100
  else:
101
  # For other templates, wrap non-template content
102
  if '{{' not in value and '{%' not in value:
103
- value = f'{{{{ "{value}" }}}}'
 
104
  else:
105
  # Ensure proper spacing in template expressions
106
  value = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', value)
107
  value = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', value)
108
- value = value.replace('\n', '\\n')
109
 
110
  logger.debug(f"Processed template content: {value}")
111
  except Exception as e:
 
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:
102
+ escaped_content = value.replace('"', '\\"').replace('\n', '\\n')
103
+ value = f'{{{{ "{escaped_content}" }}}}'
104
  else:
105
  # Ensure proper spacing in template expressions
106
  value = re.sub(r'{{([^{}]+)}}', lambda m: '{{ ' + m.group(1).strip() + ' }}', value)
107
  value = re.sub(r'{%([^{}]+)%}', lambda m: '{% ' + m.group(1).strip() + ' %}', value)
 
108
 
109
  logger.debug(f"Processed template content: {value}")
110
  except Exception as e: