Fix json schema for final answer
This commit is contained in:
		
							parent
							
								
									8bd5144da1
								
							
						
					
					
						commit
						93569bd7c1
					
				|  | @ -539,6 +539,7 @@ class MultiStepAgent: | ||||||
|             final_step_log = ActionStep(error=AgentMaxIterationsError(error_message)) |             final_step_log = ActionStep(error=AgentMaxIterationsError(error_message)) | ||||||
|             self.logs.append(final_step_log) |             self.logs.append(final_step_log) | ||||||
|             final_answer = self.provide_final_answer(task) |             final_answer = self.provide_final_answer(task) | ||||||
|  |             console.print(Text(f"Final answer: {final_answer}")) | ||||||
|             final_step_log.action_output = final_answer |             final_step_log.action_output = final_answer | ||||||
|             final_step_log.end_time = time.time() |             final_step_log.end_time = time.time() | ||||||
|             final_step_log.duration = step_log.end_time - step_start_time |             final_step_log.duration = step_log.end_time - step_start_time | ||||||
|  | @ -588,6 +589,7 @@ class MultiStepAgent: | ||||||
|             final_step_log = ActionStep(error=AgentMaxIterationsError(error_message)) |             final_step_log = ActionStep(error=AgentMaxIterationsError(error_message)) | ||||||
|             self.logs.append(final_step_log) |             self.logs.append(final_step_log) | ||||||
|             final_answer = self.provide_final_answer(task) |             final_answer = self.provide_final_answer(task) | ||||||
|  |             console.print(Text(f"Final answer: {final_answer}")) | ||||||
|             final_step_log.action_output = final_answer |             final_step_log.action_output = final_answer | ||||||
|             final_step_log.duration = 0 |             final_step_log.duration = 0 | ||||||
|             for callback in self.step_callbacks: |             for callback in self.step_callbacks: | ||||||
|  |  | ||||||
|  | @ -105,6 +105,7 @@ class PythonInterpreterTool(Tool): | ||||||
| 
 | 
 | ||||||
|     def forward(self, code: str) -> str: |     def forward(self, code: str) -> str: | ||||||
|         state = {} |         state = {} | ||||||
|  |         try: | ||||||
|             output = str( |             output = str( | ||||||
|                 self.python_evaluator( |                 self.python_evaluator( | ||||||
|                     code, |                     code, | ||||||
|  | @ -114,6 +115,8 @@ class PythonInterpreterTool(Tool): | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|             return f"Stdout:\n{state['print_outputs']}\nOutput: {output}" |             return f"Stdout:\n{state['print_outputs']}\nOutput: {output}" | ||||||
|  |         except Exception as e: | ||||||
|  |             return f"Error: {str(e)}" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class FinalAnswerTool(Tool): | class FinalAnswerTool(Tool): | ||||||
|  |  | ||||||
|  | @ -66,6 +66,10 @@ tool_role_conversions = { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def get_json_schema(tool: Tool) -> Dict: | def get_json_schema(tool: Tool) -> Dict: | ||||||
|  |     properties = deepcopy(tool.inputs) | ||||||
|  |     for value in properties.values(): | ||||||
|  |         if value["type"] == "any": | ||||||
|  |             value["type"] = "string" | ||||||
|     return { |     return { | ||||||
|         "type": "function", |         "type": "function", | ||||||
|         "function": { |         "function": { | ||||||
|  | @ -73,10 +77,7 @@ def get_json_schema(tool: Tool) -> Dict: | ||||||
|             "description": tool.description, |             "description": tool.description, | ||||||
|             "parameters": { |             "parameters": { | ||||||
|                 "type": "object", |                 "type": "object", | ||||||
|                 "properties": { |                 "properties": properties, | ||||||
|                     k: {k2: v2.replace("any", "object") for k2, v2 in v.items()} |  | ||||||
|                     for k, v in tool.inputs.items() |  | ||||||
|                 }, |  | ||||||
|                 "required": list(tool.inputs.keys()), |                 "required": list(tool.inputs.keys()), | ||||||
|             }, |             }, | ||||||
|         }, |         }, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue