Add timeout while searching for git diffs in LLMs response
diff --git a/gpt_engineer/core/chat_to_files.py b/gpt_engineer/core/chat_to_files.py
index 7fd5097844..12590c051a 100644
--- a/gpt_engineer/core/chat_to_files.py
+++ b/gpt_engineer/core/chat_to_files.py
@@ -26,6 +26,8 @@
 
 from typing import Dict, Tuple
 
+from regex import regex
+
 from gpt_engineer.core.diff import ADD, REMOVE, RETAIN, Diff, Hunk
 from gpt_engineer.core.files_dict import FilesDict, file_to_lines_dict
 
@@ -134,17 +136,20 @@ def parse_diffs(diff_string: str) -> dict:
     - dict: A dictionary of Diff objects keyed by filename.
     """
     # Regex to match individual diff blocks
-    diff_block_pattern = re.compile(
+    diff_block_pattern = regex.compile(
         r"```.*?\n\s*?--- .*?\n\s*?\+\+\+ .*?\n(?:@@ .*? @@\n(?:[-+ ].*?\n)*?)*?```",
         re.DOTALL,
     )
 
     diffs = {}
-    for block in diff_block_pattern.finditer(diff_string):
-        diff_block = block.group()
-
-        # Parse individual diff blocks and update the diffs dictionary
-        diffs.update(parse_diff_block(diff_block))
+    try:
+        for block in diff_block_pattern.finditer(diff_string, timeout=1):
+            diff_block = block.group()
+
+            # Parse individual diff blocks and update the diffs dictionary
+            diffs.update(parse_diff_block(diff_block))
+    except TimeoutError:
+        print("gpt-engineer timed out while parsing git diff")
 
     if not diffs:
         print(
diff --git a/poetry.lock b/poetry.lock
index fc3603f758..f28ce55140 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -4272,4 +4272,4 @@ test = []
 [metadata]
 lock-version = "2.0"
 python-versions = ">=3.10,<3.13"
-content-hash = "b5e12ad6250bdc25ba945bdfe8d67c216127dacefbb3977def0546061f5be3df"
+content-hash = "455d13a418ad9dcba9e59303a5d6396b5081e87bbe9bc3e59cfce6c6ae435fff"
diff --git a/pyproject.toml b/pyproject.toml
index 8e70d18939..bc96694a7c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -32,6 +32,7 @@ langchain_openai = "*"
 toml = ">=0.10.2"
 pyperclip = "^1.8.2"
 langchain-anthropic = "^0.1.1"
+regex = "^2023.12.25"
 
 [tool.poetry.group.dev.dependencies]
 pytest = ">=7.3.1"

- Add `regex` dependency