(
self,
commands: list,
project_path: str,
project_name: str,
conversation: list,
code_markdown: str,
system_os: str
)
| 68 | |
| 69 | @retry_wrapper |
| 70 | def run_code( |
| 71 | self, |
| 72 | commands: list, |
| 73 | project_path: str, |
| 74 | project_name: str, |
| 75 | conversation: list, |
| 76 | code_markdown: str, |
| 77 | system_os: str |
| 78 | ): |
| 79 | retries = 0 |
| 80 | |
| 81 | for command in commands: |
| 82 | command_set = command.split(" ") |
| 83 | command_failed = False |
| 84 | |
| 85 | process = subprocess.run( |
| 86 | command_set, |
| 87 | stdout=subprocess.PIPE, |
| 88 | stderr=subprocess.PIPE, |
| 89 | cwd=project_path |
| 90 | ) |
| 91 | command_output = process.stdout.decode('utf-8') |
| 92 | command_failed = process.returncode != 0 |
| 93 | |
| 94 | new_state = AgentState().new_state() |
| 95 | new_state["internal_monologue"] = "Running code..." |
| 96 | new_state["terminal_session"]["title"] = "Terminal" |
| 97 | new_state["terminal_session"]["command"] = command |
| 98 | new_state["terminal_session"]["output"] = command_output |
| 99 | AgentState().add_to_current_state(project_name, new_state) |
| 100 | time.sleep(1) |
| 101 | |
| 102 | while command_failed and retries < 2: |
| 103 | new_state = AgentState().new_state() |
| 104 | new_state["internal_monologue"] = "Oh seems like there is some error... :(" |
| 105 | new_state["terminal_session"]["title"] = "Terminal" |
| 106 | new_state["terminal_session"]["command"] = command |
| 107 | new_state["terminal_session"]["output"] = command_output |
| 108 | AgentState().add_to_current_state(project_name, new_state) |
| 109 | time.sleep(1) |
| 110 | |
| 111 | prompt = self.render_rerunner( |
| 112 | conversation=conversation, |
| 113 | code_markdown=code_markdown, |
| 114 | system_os=system_os, |
| 115 | commands=commands, |
| 116 | error=command_output |
| 117 | ) |
| 118 | |
| 119 | response = self.llm.inference(prompt, project_name) |
| 120 | |
| 121 | valid_response = self.validate_rerunner_response(response) |
| 122 | |
| 123 | if not valid_response: |
| 124 | return False |
| 125 | |
| 126 | action = valid_response["action"] |
| 127 |
no test coverage detected