Skip to content

Commit

Permalink
Update generate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
srdas committed Dec 20, 2024
1 parent 3dbc1dc commit 7d909bb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7d909bb

Please sign in to comment.