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

fix: Handle system prompt template separately

Browse files
Files changed (1) hide show
  1. app.py +31 -17
app.py CHANGED
@@ -211,26 +211,40 @@ with open("prompts.yaml", 'r') as stream:
211
  agent_templates[key] = {}
212
  for subkey, subvalue in value.items():
213
  if isinstance(subvalue, str):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  # Ensure proper spacing in template expressions
215
- content = subvalue
216
- # Add spaces around template expressions if missing
217
  content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
218
  content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
219
- # Wrap non-template content in a simple template expression
220
- if '{{' not in content and '{%' not in content:
221
- escaped_content = content.replace('"', '\\"')
222
- content = f'{{{{ "{escaped_content}" }}}}'
223
- agent_templates[key][subkey] = content
224
- elif isinstance(value, str):
225
- # Ensure proper spacing in template expressions
226
- content = value
227
- # Add spaces around template expressions if missing
228
- content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
229
- content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
230
- # Wrap non-template content in a simple template expression
231
- if '{{' not in content and '{%' not in content:
232
- escaped_content = content.replace('"', '\\"')
233
- content = f'{{{{ "{escaped_content}" }}}}'
234
  agent_templates[key] = content
235
  else:
236
  agent_templates[key] = value
 
211
  agent_templates[key] = {}
212
  for subkey, subvalue in value.items():
213
  if isinstance(subvalue, str):
214
+ # Special handling for system prompt
215
+ if key == 'system_prompt' and subkey == 'text':
216
+ # Keep system prompt as is, only ensure proper spacing in template expressions
217
+ content = subvalue
218
+ content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
219
+ content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
220
+ else:
221
+ # For other templates, wrap non-template content
222
+ content = subvalue
223
+ if '{{' not in content and '{%' not in content:
224
+ escaped_content = content.replace('"', '\\"')
225
+ content = f'{{{{ "{escaped_content}" }}}}'
226
+ else:
227
+ # Ensure proper spacing in template expressions
228
+ content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
229
+ content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
230
+ agent_templates[key][subkey] = content
231
+ elif isinstance(value, str):
232
+ # Special handling for system prompt
233
+ if key == 'system_prompt':
234
+ # Keep system prompt as is, only ensure proper spacing in template expressions
235
+ content = value
236
+ content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
237
+ content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
238
+ else:
239
+ # For other templates, wrap non-template content
240
+ content = value
241
+ if '{{' not in content and '{%' not in content:
242
+ escaped_content = content.replace('"', '\\"')
243
+ content = f'{{{{ "{escaped_content}" }}}}'
244
+ else:
245
  # Ensure proper spacing in template expressions
 
 
246
  content = re.sub(r'{{([^{}]+)}}', r'{{ \1 }}', content)
247
  content = re.sub(r'{%([^{}]+)%}', r'{% \1 %}', content)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  agent_templates[key] = content
249
  else:
250
  agent_templates[key] = value