gpt_engineer.tools.custom_steps.self_heal

gpt_engineer.tools.custom_steps.self_heal(ai: AI, execution_env: BaseExecutionEnv, files_dict: FilesDict, prompt: Prompt = None, preprompts_holder: PrepromptsHolder = None, memory: MutableMapping[str | Path, str] = None, diff_timeout=3) FilesDict[source]

Attempts to execute the code from the entrypoint and if it fails, sends the error output back to the AI with instructions to fix.

Parameters:
  • ai (AI) – An instance of the AI model.

  • execution_env (BaseExecutionEnv) – The execution environment where the code is run.

  • files_dict (FilesDict) – A dictionary of file names to their contents.

  • preprompts_holder (PrepromptsHolder, optional) – A holder for preprompt messages.

Returns:

The updated files dictionary after self-healing attempts.

Return type:

FilesDict

Raises:
  • FileNotFoundError – If the required entrypoint file does not exist in the code.

  • AssertionError – If the preprompts_holder is None.

Notes

This code will make MAX_SELF_HEAL_ATTEMPTS to try and fix the code before giving up. This makes the assuption that the previous step was gen_entrypoint, this code could work with simple_gen, or gen_clarified_code as well.