(
node: Type[BaseNode],
parser_result: Dict[str, str],
)
| 130 | |
| 131 | |
| 132 | def code_execution( |
| 133 | node: Type[BaseNode], |
| 134 | parser_result: Dict[str, str], |
| 135 | ) -> str: |
| 136 | |
| 137 | @timeout(TIMEOUT_SECONDS, exception_message=TIMEOUT_MESSAGE) |
| 138 | def _code_execution(node: Type[BaseNode], parser_result: Dict[str, str]) -> str: |
| 139 | # Define tool |
| 140 | action = parser_result["action"] |
| 141 | tool_func = tools[action] |
| 142 | |
| 143 | # Preventing variable update between different children |
| 144 | # For each child, we re-run the historical code snippets with the same action (tool). |
| 145 | history_action_inputs = collect_action_inputs(node, action) |
| 146 | for history_ai in history_action_inputs: |
| 147 | _ = tool_func(history_ai) |
| 148 | |
| 149 | # then, we execute current code snippets |
| 150 | action_input = parser_result["action_input"] |
| 151 | observation = str(tool_func(action_input)).strip() |
| 152 | del tool_func |
| 153 | return observation |
| 154 | |
| 155 | try: |
| 156 | observation = _code_execution(node, parser_result) |
| 157 | except Exception as e: |
| 158 | observation = "{}: {}".format(type(e).__name__, str(e)) |
| 159 | |
| 160 | return observation |
| 161 | |
| 162 | |
| 163 | def collect_action_inputs( |
no test coverage detected