Skip to content

Commit c63f49c

Browse files
committed
Return json on dict
1 parent c770965 commit c63f49c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

.changeset/pretty-deers-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@e2b/code-interpreter-template': patch
3+
---
4+
5+
Return json on dict

template/startup_scripts/0002_data.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pandas
22
from matplotlib.pyplot import Figure
33
import IPython
4-
from IPython.core.formatters import BaseFormatter
4+
from IPython.core.formatters import BaseFormatter, JSONFormatter
55
from traitlets.traitlets import Unicode, ObjectName
66

77
from e2b_charts import chart_figure_to_dict
@@ -48,10 +48,24 @@ def __call__(self, obj):
4848
return super().__call__(obj)
4949

5050

51+
class E2BDictFormatter(JSONFormatter):
52+
def __call__(self, obj):
53+
# Figure object is for some reason removed on execution of the cell,
54+
# so it can't be used in type_printers or with top-level import
55+
56+
if isinstance(obj, dict):
57+
return obj, {"expanded": True}
58+
return super().__call__(obj)
59+
60+
5161
ip = IPython.get_ipython()
5262
ip.display_formatter.formatters["e2b/data"] = E2BDataFormatter(
5363
parent=ip.display_formatter
5464
)
5565
ip.display_formatter.formatters["e2b/chart"] = E2BChartFormatter(
5666
parent=ip.display_formatter
5767
)
68+
69+
ip.display_formatter.formatters["application/json"] = E2BDictFormatter(
70+
parent=ip.display_formatter
71+
)

0 commit comments

Comments
 (0)