Ashad001 commited on
Commit
66a12d4
·
1 Parent(s): dfcb54b

code combiner fix v1

Browse files
Files changed (2) hide show
  1. agents.py +5 -2
  2. format_response.py +9 -9
agents.py CHANGED
@@ -426,8 +426,11 @@ class auto_analyst(dspy.Module):
426
 
427
  # Execute code combiner after all agents complete
428
  code_list = [result['code'] for _, result in completed_results if 'code' in result]
429
- combiner_result = self.code_combiner_agent(agent_code_list=str(code_list), dataset=dict_['dataset'])
430
- yield 'code_combiner_agent', dict(combiner_result)
 
 
 
431
 
432
  # Agent to make a Chat history name from a query
433
  class chat_history_name_agent(dspy.Signature):
 
426
 
427
  # Execute code combiner after all agents complete
428
  code_list = [result['code'] for _, result in completed_results if 'code' in result]
429
+ try:
430
+ combiner_result = self.code_combiner_agent(agent_code_list=str(code_list), dataset=dict_['dataset'])
431
+ yield 'code_combiner_agent', dict(combiner_result)
432
+ except Exception as e:
433
+ yield 'code_combiner_agent', {'error': str(e)}
434
 
435
  # Agent to make a Chat history name from a query
436
  class chat_history_name_agent(dspy.Signature):
format_response.py CHANGED
@@ -149,8 +149,14 @@ def format_response_to_markdown(api_response, agent_name = None, dataframe=None)
149
  markdown.append(f"### Commentary\n{content['commentary']}\n")
150
 
151
  if 'refined_complete_code' in content:
152
- clean_code = format_code_block(content['refined_complete_code'])
153
- output, json_outputs = execute_code_from_markdown(clean_code, dataframe)
 
 
 
 
 
 
154
 
155
  markdown.append(f"### Refined Complete Code\n{format_code_backticked_block(content['refined_complete_code'])}\n")
156
 
@@ -162,8 +168,6 @@ def format_response_to_markdown(api_response, agent_name = None, dataframe=None)
162
  if json_outputs:
163
  markdown.append("### Plotly JSON Outputs\n")
164
  for idx, json_output in enumerate(json_outputs):
165
- if len(json_output) > 1000000: # If JSON is larger than 1MB
166
- logger.warning(f"Large JSON output detected: {len(json_output)} bytes")
167
  markdown.append(f"```plotly\n{json_output}\n```\n")
168
  # print("Length of json_outputs: ", len(json_outputs))
169
 
@@ -174,13 +178,9 @@ def format_response_to_markdown(api_response, agent_name = None, dataframe=None)
174
  except Exception as e:
175
  logger.error(f"Error in format_response_to_markdown: {str(e)}")
176
  return f"**Error**: {str(e)}"
177
- finally:
178
- duration = time.time() - start_time
179
- if duration > 1.0:
180
- logger.warning(f"Slow response formatting: {duration:.2f}s")
181
 
182
  if not markdown:
183
- return "No content generated"
184
 
185
  return '\n'.join(markdown)
186
 
 
149
  markdown.append(f"### Commentary\n{content['commentary']}\n")
150
 
151
  if 'refined_complete_code' in content:
152
+ print("content['refined_complete_code']: ", content['refined_complete_code'])
153
+ try:
154
+ clean_code = format_code_block(content['refined_complete_code'])
155
+ output, json_outputs = execute_code_from_markdown(clean_code, dataframe)
156
+ except Exception as e:
157
+ logger.error(f"Error in execute_code_from_markdown: {str(e)}")
158
+ markdown.append(f"**Error**: {str(e)}")
159
+ continue
160
 
161
  markdown.append(f"### Refined Complete Code\n{format_code_backticked_block(content['refined_complete_code'])}\n")
162
 
 
168
  if json_outputs:
169
  markdown.append("### Plotly JSON Outputs\n")
170
  for idx, json_output in enumerate(json_outputs):
 
 
171
  markdown.append(f"```plotly\n{json_output}\n```\n")
172
  # print("Length of json_outputs: ", len(json_outputs))
173
 
 
178
  except Exception as e:
179
  logger.error(f"Error in format_response_to_markdown: {str(e)}")
180
  return f"**Error**: {str(e)}"
 
 
 
 
181
 
182
  if not markdown:
183
+ return "Please provide a valid query..."
184
 
185
  return '\n'.join(markdown)
186