diff --git a/pilot/const/common.py b/pilot/const/common.py index a8ae4e3e12..9a5b18cc53 100644 --- a/pilot/const/common.py +++ b/pilot/const/common.py @@ -29,6 +29,7 @@ DEFAULT_IGNORE_PATHS = [ '.next', '.DS_Store', '__pycache__', + "site-packages", 'node_modules', 'package-lock.json', 'venv', diff --git a/pilot/helpers/AgentConvo.py b/pilot/helpers/AgentConvo.py index e3a0c111f2..327b633191 100644 --- a/pilot/helpers/AgentConvo.py +++ b/pilot/helpers/AgentConvo.py @@ -68,7 +68,7 @@ class AgentConvo: function_calls=function_calls, prompt_data=prompt_data, temperature=self.temperature) except TokenLimitError as e: - save_development_step(self.agent.project, prompt_path, prompt_data, self.messages, '', str(e)) + save_development_step(self.agent.project, prompt_path, prompt_data, self.messages, {"text": ""}, str(e)) raise e # TODO: move this code to Developer agent - https://github.com/Pythagora-io/gpt-pilot/issues/91#issuecomment-1751964079 diff --git a/pilot/helpers/Project.py b/pilot/helpers/Project.py index 438eaca353..305d0294cf 100644 --- a/pilot/helpers/Project.py +++ b/pilot/helpers/Project.py @@ -475,7 +475,7 @@ class Project: # - /pilot -> /pilot/ # - \pilot\server.js -> \pilot\server.js # - \pilot -> \pilot\ - KNOWN_FILES = ["makefile", "dockerfile", "procfile", "readme", "license"] # known exceptions that break the heuristic + KNOWN_FILES = ["makefile", "dockerfile", "procfile", "readme", "license", "podfile"] # known exceptions that break the heuristic KNOWN_DIRS = [] # known exceptions that break the heuristic base = os.path.basename(path) if ( @@ -560,7 +560,10 @@ class Project: clear_directory(self.root_path, ignore=self.files) for file_snapshot in file_snapshots: - update_file(file_snapshot.file.full_path, file_snapshot.content, project=self) + try: + update_file(file_snapshot.file.full_path, file_snapshot.content, project=self) + except (PermissionError, NotADirectoryError) as err: # noqa + print(f"Error restoring file {file_snapshot.file.full_path}: {err}") if file_snapshot.file.full_path not in self.files: self.files.append(file_snapshot.file.full_path) diff --git a/pilot/helpers/agents/Developer.py b/pilot/helpers/agents/Developer.py index 06b3e0ce9e..3b7fbb56f2 100644 --- a/pilot/helpers/agents/Developer.py +++ b/pilot/helpers/agents/Developer.py @@ -866,7 +866,13 @@ class Developer(Agent): dep_text = dependency['name'] logger.info('Checking %s', dependency) - llm_response = self.check_system_dependency(dependency) + try: + llm_response = self.check_system_dependency(dependency) + except Exception as err: + # This catches weird errors like people removing or renaming the workspace + # folder while we're trying to run system commands. Since these commands don't + # care about folders they run in, we don't want to crash just because of that. + llm_response = str(err) if llm_response == 'DONE': print(color_green_bold(f"✅ {dep_text} is available.")) diff --git a/pilot/helpers/files.py b/pilot/helpers/files.py index 9b8a86101f..22572bfe03 100644 --- a/pilot/helpers/files.py +++ b/pilot/helpers/files.py @@ -145,10 +145,18 @@ def clear_directory(directory: str, ignore: Optional[list[str]] = None): if matcher.ignore(full_path): continue - os.remove(full_path) + try: + os.remove(full_path) + except: # noqa + # Gracefully handle some weird edge cases instead of crashing + pass # Delete empty subdirectories not in ignore list for d in dirs: - subdir_path = os.path.join(dpath, d) - if not os.listdir(subdir_path): - os.rmdir(subdir_path) + try: + subdir_path = os.path.join(dpath, d) + if not os.listdir(subdir_path): + os.rmdir(subdir_path) + except: # noqa + # Gracefully handle some weird edge cases instead of crashing + pass diff --git a/pilot/helpers/ipc.py b/pilot/helpers/ipc.py index 46b954ddb3..2f6203e96c 100644 --- a/pilot/helpers/ipc.py +++ b/pilot/helpers/ipc.py @@ -28,8 +28,17 @@ class IPCClient: return while True: - data = self.client.recv(65536) - message = json.loads(data) + + data = b'' + while True: + data = data + self.client.recv(512 * 1024) + try: + message = json.loads(data) + break + except json.JSONDecodeError: + # This means we still got an incomplete message, so + # we should continue to receive more data. + continue if message['type'] == 'response': # self.client.close() diff --git a/pilot/main.py b/pilot/main.py index e881f4e4e8..78c303a78a 100644 --- a/pilot/main.py +++ b/pilot/main.py @@ -111,6 +111,14 @@ if __name__ == "__main__": telemetry.record_crash(err, end_result="failure:api-error") telemetry.send() run_exit_fn = False + if isinstance(err, TokenLimitError): + print('', type='verbose', category='error') + print(color_red( + "We sent too large request to the LLM, resulting in an error. " + "This is usually caused by including framework files in an LLM request. " + "Here's how you can get GPT Pilot to ignore those extra files: " + "https://bit.ly/faq-token-limit-error" + )) print('Exit', type='exit') except KeyboardInterrupt: diff --git a/pilot/templates/__init__.py b/pilot/templates/__init__.py index ef6f351ed5..abed50ffb9 100644 --- a/pilot/templates/__init__.py +++ b/pilot/templates/__init__.py @@ -75,7 +75,9 @@ def apply_project_template( print(color_green_bold(f"Applying project template {template['description']}...\n")) logger.info(f"Applying project template {template_name}...") - project.save_files_snapshot(project.checkpoints['last_development_step']['id']) + last_development_step = project.checkpoints.get('last_development_step') + if last_development_step: + project.save_files_snapshot(last_development_step['id']) try: if install_hook: