From 7d909bb8828d6ea5e29647e0b4d7cc17de6e8eed Mon Sep 17 00:00:00 2001 From: Sanjiv Das Date: Thu, 19 Dec 2024 16:17:52 -0800 Subject: [PATCH] Update generate.py --- .../jupyter-ai/jupyter_ai/chat_handlers/generate.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/jupyter-ai/jupyter_ai/chat_handlers/generate.py b/packages/jupyter-ai/jupyter_ai/chat_handlers/generate.py index a03540a95..6318e0979 100644 --- a/packages/jupyter-ai/jupyter_ai/chat_handlers/generate.py +++ b/packages/jupyter-ai/jupyter_ai/chat_handlers/generate.py @@ -203,9 +203,9 @@ async def afill_outline(outline, llm, verbose=False): def is_not_python_code(source: str) -> bool: try: ast.parse(source) - return False - except (SyntaxError, ValueError): + except: return True + return False def create_notebook(outline): @@ -237,11 +237,9 @@ def create_notebook(outline): merged_cells.append(cell) # Fix code cells that should be markdown - for j in range(len(merged_cells)): - if merged_cells[j]["cell_type"] == "code" and is_not_python_code( - merged_cells[j]["source"] - ): - merged_cells[j]["cell_type"] = "markdown" + for cell in merged_cells: + if cell["cell_type"] == "code" and is_not_python_code(cell["source"]): + cell["cell_type"] = "markdown" nb["cells"] = merged_cells return nb