Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion python/e2b_code_interpreter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,16 @@ def serialize_results(results: List[Result]) -> List[Dict[str, str]]:
"""
serialized = []
for result in results:
serialized_dict = {key: result[key] for key in result.formats()}
serialized_dict = {}
for key in result.formats():
if key == "chart":
serialized_dict[key] = result.chart.to_dict()
else:
serialized_dict[key] = result[key]

serialized_dict["text"] = result.text
serialized.append(serialized_dict)

return serialized


Expand Down
27 changes: 27 additions & 0 deletions python/tests/charts/test_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json

from e2b_code_interpreter.code_interpreter_async import AsyncSandbox

code = """
import matplotlib.pyplot as plt
import numpy as np

# Create data
N = 5
x = np.random.rand(N)
y = np.random.rand(N)

plt.xlabel("A")

plt.scatter(x, y, c='blue', label='Dataset')

plt.show()
"""


async def test_scatter_chart(async_sandbox: AsyncSandbox):
result = await async_sandbox.run_code(code)
serialized = result.to_json()
assert isinstance(serialized, str)

assert json.loads(serialized)["results"][0]["chart"]["type"] == "scatter"