File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1+ --- 
2+ ' @e2b/code-interpreter-template ' patch 
3+ --- 
4+ 
5+ Return json on dict
Original file line number Diff line number Diff line change 11import  pandas 
22from  matplotlib .pyplot  import  Figure 
33import  IPython 
4- from  IPython .core .formatters  import  BaseFormatter 
4+ from  IPython .core .formatters  import  BaseFormatter ,  JSONFormatter 
55from  traitlets .traitlets  import  Unicode , ObjectName 
66
77from  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+ 
5161ip  =  IPython .get_ipython ()
5262ip .display_formatter .formatters ["e2b/data" ] =  E2BDataFormatter (
5363    parent = ip .display_formatter 
5464)
5565ip .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+ )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments