diff --git a/deepanalyze.py b/deepanalyze.py index 3ca82169..ddab7145 100644 --- a/deepanalyze.py +++ b/deepanalyze.py @@ -114,11 +114,18 @@ def generate( response_message.append(ans) - # Check for block - code_match = re.search(r"(.*?)", ans, re.DOTALL) - if not code_match or "" in ans: + # Check for termination: only stop when is present + if "" in ans: break + # Check for block to execute + code_match = re.search(r"(.*?)", ans, re.DOTALL) + if not code_match: + # No and no (e.g. -only response); + # continue the loop so the model can produce the next step. + messages.append({"role": "assistant", "content": ans}) + continue + code_content = code_match.group(1).strip() md_match = re.search(r"```(?:python)?(.*?)```", code_content, re.DOTALL) code_str = md_match.group(1).strip() if md_match else code_content