Scott Cogan commited on
Commit
e573c02
·
1 Parent(s): f5b36b1

fix: preserve original template structure from prompts.yaml

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -87,7 +87,7 @@ with open("prompts.yaml", 'r') as stream:
87
 
88
  logger.debug("Starting template validation...")
89
  try:
90
- # Validate and update templates
91
  for key, value in prompt_templates.items():
92
  if isinstance(value, dict):
93
  for subkey, subvalue in value.items():
@@ -95,13 +95,14 @@ with open("prompts.yaml", 'r') as stream:
95
  logger.debug(f"Validating template: {key}.{subkey}")
96
  logger.debug(f"Template content: {subvalue[:200]}...")
97
 
98
- # Validate and update template
99
  try:
100
  # Create a template with at least one template node
101
  template_str = subvalue
102
  if '{{' not in template_str and '{%' not in template_str:
103
  template_str = "{{ task }}\n" + template_str
104
 
 
105
  template = Template(template_str, undefined=StrictUndefined)
106
  rendered = template.render(
107
  tools=[],
@@ -111,8 +112,6 @@ with open("prompts.yaml", 'r') as stream:
111
  remaining_steps=1,
112
  answer_facts="test"
113
  )
114
- # Update the template in the dictionary
115
- prompt_templates[key][subkey] = template_str
116
  logger.debug(f"Template render test successful for {key}.{subkey}")
117
  except Exception as e:
118
  logger.error(f"Template render test failed for {key}.{subkey}: {str(e)}")
@@ -121,13 +120,14 @@ with open("prompts.yaml", 'r') as stream:
121
  logger.debug(f"Validating template: {key}")
122
  logger.debug(f"Template content: {value[:200]}...")
123
 
124
- # Validate and update template
125
  try:
126
  # Create a template with at least one template node
127
  template_str = value
128
  if '{{' not in template_str and '{%' not in template_str:
129
  template_str = "{{ task }}\n" + template_str
130
 
 
131
  template = Template(template_str, undefined=StrictUndefined)
132
  rendered = template.render(
133
  tools=[],
@@ -137,8 +137,6 @@ with open("prompts.yaml", 'r') as stream:
137
  remaining_steps=1,
138
  answer_facts="test"
139
  )
140
- # Update the template in the dictionary
141
- prompt_templates[key] = template_str
142
  logger.debug(f"Template render test successful for {key}")
143
  except Exception as e:
144
  logger.error(f"Template render test failed for {key}: {str(e)}")
@@ -150,7 +148,7 @@ with open("prompts.yaml", 'r') as stream:
150
  logger.error(f"Error during template validation: {str(e)}")
151
  raise
152
 
153
- # Create the agent with the updated templates
154
  agent = CodeAgent(
155
  model=model,
156
  tools=[final_answer, DuckDuckGoSearchTool(), calculate_min_price, extract_price_from_snippet, get_current_time_in_timezone],
 
87
 
88
  logger.debug("Starting template validation...")
89
  try:
90
+ # Validate templates
91
  for key, value in prompt_templates.items():
92
  if isinstance(value, dict):
93
  for subkey, subvalue in value.items():
 
95
  logger.debug(f"Validating template: {key}.{subkey}")
96
  logger.debug(f"Template content: {subvalue[:200]}...")
97
 
98
+ # Validate template
99
  try:
100
  # Create a template with at least one template node
101
  template_str = subvalue
102
  if '{{' not in template_str and '{%' not in template_str:
103
  template_str = "{{ task }}\n" + template_str
104
 
105
+ # Create a template with the task variable
106
  template = Template(template_str, undefined=StrictUndefined)
107
  rendered = template.render(
108
  tools=[],
 
112
  remaining_steps=1,
113
  answer_facts="test"
114
  )
 
 
115
  logger.debug(f"Template render test successful for {key}.{subkey}")
116
  except Exception as e:
117
  logger.error(f"Template render test failed for {key}.{subkey}: {str(e)}")
 
120
  logger.debug(f"Validating template: {key}")
121
  logger.debug(f"Template content: {value[:200]}...")
122
 
123
+ # Validate template
124
  try:
125
  # Create a template with at least one template node
126
  template_str = value
127
  if '{{' not in template_str and '{%' not in template_str:
128
  template_str = "{{ task }}\n" + template_str
129
 
130
+ # Create a template with the task variable
131
  template = Template(template_str, undefined=StrictUndefined)
132
  rendered = template.render(
133
  tools=[],
 
137
  remaining_steps=1,
138
  answer_facts="test"
139
  )
 
 
140
  logger.debug(f"Template render test successful for {key}")
141
  except Exception as e:
142
  logger.error(f"Template render test failed for {key}: {str(e)}")
 
148
  logger.error(f"Error during template validation: {str(e)}")
149
  raise
150
 
151
+ # Create the agent with the templates
152
  agent = CodeAgent(
153
  model=model,
154
  tools=[final_answer, DuckDuckGoSearchTool(), calculate_min_price, extract_price_from_snippet, get_current_time_in_timezone],