Skip to content

Commit

Permalink
Fix code output format in IPython
Browse files Browse the repository at this point in the history
In an IPython terminal, using `code` format doesn't copy the code to the
output cell but this works in a JupyterLab cell. Removing the
payload_manager and using the `set_next_input` method directly
fixes this behavior in IPython while maintaining the
functionality in JupyterLab
  • Loading branch information
Divyansh Choudhary committed Dec 18, 2024
1 parent 1cbd853 commit 31ae0f7
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions packages/jupyter-ai-magics/jupyter_ai_magics/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,7 @@ def display_output(self, output, display_format, md):
lang_indicator = r"^```[a-zA-Z0-9]*\n"
output = re.sub(lang_indicator, "", output)
output = re.sub(r"\n```$", "", output)
new_cell_payload = dict(
source="set_next_input",
text=output,
replace=False,
)
ip = self.shell
ip.payload_manager.write_payload(new_cell_payload)
self.shell.set_next_input(output, replace=False)
return HTML(
"AI generated code inserted below ⬇️", metadata=md
)
Expand Down

0 comments on commit 31ae0f7

Please sign in to comment.