Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions deepanalyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ def generate(

response_message.append(ans)

# Check for <Code> block
code_match = re.search(r"<Code>(.*?)</Code>", ans, re.DOTALL)
if not code_match or "<Answer>" in ans:
# Check for termination: only stop when <Answer> is present
if "<Answer>" in ans:
break

# Check for <Code> block to execute
code_match = re.search(r"<Code>(.*?)</Code>", ans, re.DOTALL)
if not code_match:
# No <Code> and no <Answer> (e.g. <Analyze>-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
Expand Down