File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
python/e2b_code_interpreter Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 11import copy
22from typing import List , Optional , Iterable , Dict
3- from pydantic import BaseModel
3+ from pydantic import BaseModel , field_serializer
44
55
66class Error (BaseModel ):
@@ -234,6 +234,25 @@ def text(self) -> Optional[str]:
234234 if d .is_main_result :
235235 return d .text
236236
237+ def to_json (self ) -> str :
238+ """
239+ Returns the JSON representation of the Execution object.
240+ """
241+ return self .model_dump_json (exclude_none = True )
242+
243+ @field_serializer ("results" , when_used = "json" )
244+ def serialize_results (results : List [Result ]) -> List [Dict [str , str ]]:
245+ """
246+ Serializes the results to JSON.
247+ This method is used by the Pydantic JSON encoder.
248+ """
249+ serialized = []
250+ for result in results :
251+ serialized_dict = {key : result [key ] for key in result .formats ()}
252+ serialized_dict ['text' ] = result .text
253+ serialized .append (serialized_dict )
254+ return serialized
255+
237256
238257class KernelException (Exception ):
239258 """
You can’t perform that action at this time.
0 commit comments