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

fix: update templates in dictionary after validation

Browse files
Files changed (1) hide show
  1. app.py +8 -4
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 templates
91
  for key, value in prompt_templates.items():
92
  if isinstance(value, dict):
93
  for subkey, subvalue in value.items():
@@ -95,7 +95,7 @@ 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 template
99
  try:
100
  # Create a template with at least one template node
101
  template_str = subvalue
@@ -111,6 +111,8 @@ with open("prompts.yaml", 'r') as stream:
111
  remaining_steps=1,
112
  answer_facts="test"
113
  )
 
 
114
  logger.debug(f"Template render test successful for {key}.{subkey}")
115
  except Exception as e:
116
  logger.error(f"Template render test failed for {key}.{subkey}: {str(e)}")
@@ -119,7 +121,7 @@ with open("prompts.yaml", 'r') as stream:
119
  logger.debug(f"Validating template: {key}")
120
  logger.debug(f"Template content: {value[:200]}...")
121
 
122
- # Validate template
123
  try:
124
  # Create a template with at least one template node
125
  template_str = value
@@ -135,6 +137,8 @@ with open("prompts.yaml", 'r') as stream:
135
  remaining_steps=1,
136
  answer_facts="test"
137
  )
 
 
138
  logger.debug(f"Template render test successful for {key}")
139
  except Exception as e:
140
  logger.error(f"Template render test failed for {key}: {str(e)}")
@@ -146,7 +150,7 @@ with open("prompts.yaml", 'r') as stream:
146
  logger.error(f"Error during template validation: {str(e)}")
147
  raise
148
 
149
- # Create the agent with the templates
150
  agent = CodeAgent(
151
  model=model,
152
  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 and update 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 and update template
99
  try:
100
  # Create a template with at least one template node
101
  template_str = subvalue
 
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
  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
 
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
  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],