Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update /generate to not split classes & functions across cells #1158

Merged
merged 8 commits into from
Dec 20, 2024
9 changes: 9 additions & 0 deletions packages/jupyter-ai/jupyter_ai/chat_handlers/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ def create_notebook(outline):
nb["cells"].append(nbf.new_markdown_cell("## " + section["title"]))
for code_block in section["code"].split("\n\n"):
nb["cells"].append(nbf.new_code_cell(code_block))

# Post process notebook for hanging cells: merge hanging cell with the previous cell
nb_cells = []
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
for cell in nb["cells"]:
if (cell["cell_type"] == "code") and (cell["source"][0] == " "):
dlqqq marked this conversation as resolved.
Show resolved Hide resolved
nb_cells[-1]["source"] = nb_cells[-1]["source"] + "\n\n" + cell["source"]
else:
nb_cells.append(cell)
nb["cells"] = nb_cells
return nb


Expand Down
Loading