From 54134ba200ecd8764282984aaacc059936ad88ad Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Tue, 30 Jul 2024 18:48:24 +0200 Subject: [PATCH 01/20] Extract data from dataframe --- python/e2b_code_interpreter/models.py | 3 +++ template/e2b.Dockerfile | 3 +++ template/e2b.toml | 10 +++++----- template/ipython_startup_script.py | 18 ++++++++++++++++++ template/server/api/models/result.py | 2 ++ 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 template/ipython_startup_script.py diff --git a/python/e2b_code_interpreter/models.py b/python/e2b_code_interpreter/models.py index a759b7d..5667a63 100644 --- a/python/e2b_code_interpreter/models.py +++ b/python/e2b_code_interpreter/models.py @@ -88,6 +88,7 @@ def __getitem__(self, item): latex: Optional[str] = None json: Optional[dict] = None javascript: Optional[str] = None + data: Optional[dict] = None is_main_result: bool = False """Whether this data is the result of the cell. Data can be produced by display calls of which can be multiple in a cell.""" extra: Optional[dict] = None @@ -120,6 +121,8 @@ def formats(self) -> Iterable[str]: formats.append("json") if self.javascript: formats.append("javascript") + if self.data: + formats.append("data") if self.extra: for key in self.extra: diff --git a/template/e2b.Dockerfile b/template/e2b.Dockerfile index 3856852..0583b94 100644 --- a/template/e2b.Dockerfile +++ b/template/e2b.Dockerfile @@ -52,5 +52,8 @@ COPY ./jupyter_server_config.py $JUPYTER_CONFIG_PATH/ RUN mkdir -p $IPYTHON_CONFIG_PATH/profile_default COPY ipython_kernel_config.py $IPYTHON_CONFIG_PATH/profile_default/ +RUN mkdir -p $IPYTHON_CONFIG_PATH/profile_default/startup +COPY ./ipython_startup_script.py $IPYTHON_CONFIG_PATH/profile_default/startup/00-startup.py + # Setup entrypoint for local development ENTRYPOINT $JUPYTER_CONFIG_PATH/start-up.sh diff --git a/template/e2b.toml b/template/e2b.toml index 68c8bbf..de9fb67 100644 --- a/template/e2b.toml +++ b/template/e2b.toml @@ -1,16 +1,16 @@ # This is a config for E2B sandbox template. -# You can use 'template_id' (3e4rngfa34txe0gxc1zf) or 'template_name (code-interpreter-beta) from this config to spawn a sandbox: +# You can use 'template_id' (se2g25klhfixqis2b57f) or 'template_name (ci-df) from this config to spawn a sandbox: # Python SDK # from e2b import Sandbox -# sandbox = Sandbox(template='code-interpreter-beta') +# sandbox = Sandbox(template='ci-df') # JS SDK # import { Sandbox } from 'e2b' -# const sandbox = await Sandbox.create({ template: 'code-interpreter-beta' }) +# const sandbox = await Sandbox.create({ template: 'ci-df' }) memory_mb = 1_024 start_cmd = "/root/.jupyter/start-up.sh" dockerfile = "e2b.Dockerfile" -template_name = "code-interpreter-beta" -template_id = "3e4rngfa34txe0gxc1zf" +template_name = "ci-df" +template_id = "se2g25klhfixqis2b57f" diff --git a/template/ipython_startup_script.py b/template/ipython_startup_script.py new file mode 100644 index 0000000..6565d69 --- /dev/null +++ b/template/ipython_startup_script.py @@ -0,0 +1,18 @@ +import pandas as pd + + +def _repr_mimebundle_(self, include=None, exclude=None): + data = { + 'text/html': self.to_html(), + 'text/plain': self.to_string(), + 'e2b/df': self.to_dict(orient='list'), + } + + if include: + data = {k: v for (k, v) in data.items() if k in include} + if exclude: + data = {k: v for (k, v) in data.items() if k not in exclude} + return data + + +setattr(pd.DataFrame, '_repr_mimebundle_', _repr_mimebundle_) diff --git a/template/server/api/models/result.py b/template/server/api/models/result.py index 6e1f833..178f891 100644 --- a/template/server/api/models/result.py +++ b/template/server/api/models/result.py @@ -35,6 +35,7 @@ class Result(BaseModel): latex: Optional[str] = None json: Optional[dict] = None javascript: Optional[str] = None + data: Optional[dict] = None extra: Optional[dict] = None "Extra data that can be included. Not part of the standard types." @@ -58,6 +59,7 @@ def __init__(self, is_main_result: bool, data: [str, str]): self.latex = data.pop("text/latex", None) self.json = data.pop("application/json", None) self.javascript = data.pop("application/javascript", None) + self.data = data.pop("e2b/df", None) self.extra = data def formats(self) -> Iterable[str]: From c596e043ece8a7877657e363641eb895403468b5 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Tue, 30 Jul 2024 19:02:00 +0200 Subject: [PATCH 02/20] Do beta release --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index a06f9b6..f00d669 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11a39" +version = "0.0.11b0" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From e8e1fe427462d6f26ba80688119ecf9fe5d8a6f2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Jul 2024 17:19:41 +0000 Subject: [PATCH 03/20] [skip ci] Release new versions --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index f00d669..d677b0f 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b0" +version = "0.0.11b1" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From 93adec43d6bf1054769afb3bf0d8a7bfe07dd9a7 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Tue, 30 Jul 2024 19:22:38 +0200 Subject: [PATCH 04/20] Implement javascript part --- js/src/messaging.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/src/messaging.ts b/js/src/messaging.ts index 8c22a89..9ce6584 100644 --- a/js/src/messaging.ts +++ b/js/src/messaging.ts @@ -116,6 +116,10 @@ export class Result { * JavaScript representation of the data. */ readonly javascript?: string + /** + * Contains the data from DataFrame. + */ + readonly data: object /** * Extra data that can be included. Not part of the standard types. */ @@ -155,7 +159,8 @@ export class Result { 'pdf', 'latex', 'json', - 'javascript' + 'javascript', + 'data', ].includes(key) ) { this.extra[key] = data[key] @@ -197,6 +202,9 @@ export class Result { if (this.javascript) { formats.push('javascript') } + if (this.data) { + formats.push('data') + } for (const key of Object.keys(this.extra)) { formats.push(key) From cda01a6cf87b8cd5afacd21a7b30e7dba8843c90 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Tue, 30 Jul 2024 19:26:35 +0200 Subject: [PATCH 05/20] Change template name --- js/src/codeInterpreter.ts | 2 +- python/e2b_code_interpreter/constants.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/codeInterpreter.ts b/js/src/codeInterpreter.ts index 38e6a27..f3ef95d 100644 --- a/js/src/codeInterpreter.ts +++ b/js/src/codeInterpreter.ts @@ -245,7 +245,7 @@ export class JupyterExtension { } export class CodeInterpreter extends Sandbox { - protected static override readonly defaultTemplate: string = 'code-interpreter-beta' + protected static override readonly defaultTemplate: string = 'ci-df' protected static readonly jupyterPort = 49999 readonly notebook = new JupyterExtension( diff --git a/python/e2b_code_interpreter/constants.py b/python/e2b_code_interpreter/constants.py index b0f4ec9..267d73a 100644 --- a/python/e2b_code_interpreter/constants.py +++ b/python/e2b_code_interpreter/constants.py @@ -1,3 +1,3 @@ -DEFAULT_TEMPLATE = "code-interpreter-beta" +DEFAULT_TEMPLATE = "ci-df" JUPYTER_PORT = 49999 DEFAULT_KERNEL_ID = "default" From e7dcb231fa58424aff399623b82af3ab5b83d469 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 30 Jul 2024 17:31:09 +0000 Subject: [PATCH 06/20] [skip ci] Release new versions --- js/package.json | 2 +- python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index efdf53e..f0a578e 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "0.0.9-beta.39", + "version": "0.0.9-beta-df.0", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", "license": "MIT", diff --git a/python/pyproject.toml b/python/pyproject.toml index d677b0f..cc03ba4 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b1" +version = "0.0.11b2" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From f5215ec84012c150a42bb167becac21127a01b7a Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Tue, 20 Aug 2024 17:20:27 +0200 Subject: [PATCH 07/20] Bump to release --- python/async_example.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/async_example.py b/python/async_example.py index 5f038b1..76e9ec9 100644 --- a/python/async_example.py +++ b/python/async_example.py @@ -6,7 +6,6 @@ load_dotenv() - code = """ import matplotlib.pyplot as plt import numpy as np From 0e964dd876d0847a5bfca94a4d7c30dc7ab47de3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 20 Aug 2024 15:21:09 +0000 Subject: [PATCH 08/20] [skip ci] Release new versions --- js/package.json | 2 +- python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index f0a578e..e5bc9c4 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "0.0.9-beta-df.0", + "version": "0.0.9-beta-df.1", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", "license": "MIT", diff --git a/python/pyproject.toml b/python/pyproject.toml index cc03ba4..2daa93f 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b2" +version = "0.0.11b3" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From b7713c9a1e73389d9fd1dc2e823b5e67038974ce Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Tue, 20 Aug 2024 17:21:30 +0200 Subject: [PATCH 09/20] Build template --- .github/workflows/template.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/template.yml b/.github/workflows/template.yml index a18b9fd..a5b0554 100644 --- a/.github/workflows/template.yml +++ b/.github/workflows/template.yml @@ -6,7 +6,7 @@ on: - 'template/**' - '.github/workflows/template.yml' branches: - - beta + - beta-df permissions: contents: read @@ -32,19 +32,10 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push to DockerHub - run: | - docker pull ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest || true - docker buildx build \ - --file e2b.Dockerfile \ - --platform linux/amd64 \ - --push \ - --tag ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest . - - name: Install E2B CLI run: npm install -g @e2b/cli - name: Build e2b run: e2b template build env: - E2B_ACCESS_TOKEN: ${{ secrets.E2B_ACCESS_TOKEN }} \ No newline at end of file + E2B_ACCESS_TOKEN: ${{ secrets.E2B_ACCESS_TOKEN }} From c6593e192f674e17238787ec37ecd2f36d0f5719 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 20 Aug 2024 15:22:17 +0000 Subject: [PATCH 10/20] [skip ci] Release new versions --- js/package.json | 2 +- python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index e5bc9c4..fbfcad5 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "0.0.9-beta-df.1", + "version": "0.0.9-beta-df.2", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", "license": "MIT", diff --git a/python/pyproject.toml b/python/pyproject.toml index 2daa93f..d06640f 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b3" +version = "0.0.11b4" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From aaae6cf567af025b32c79f73c808258351616fbe Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:01:34 +0200 Subject: [PATCH 11/20] Fix type and add test --- js/src/messaging.ts | 12 +++++++++--- js/tests/data.test.ts | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 js/tests/data.test.ts diff --git a/js/src/messaging.ts b/js/src/messaging.ts index 9ce6584..960ef66 100644 --- a/js/src/messaging.ts +++ b/js/src/messaging.ts @@ -59,12 +59,16 @@ export class ExecutionError { */ export type MIMEType = string +type Data = { + data: Record +} + /** - * Dictionary that maps MIME types to their corresponding string representations of the data. + * Dictionary that maps MIME types to their corresponding representations of the data. */ export type RawData = { [key: MIMEType]: string -} +} & Data /** * Represents the data to be displayed as a result of executing a cell in a Jupyter notebook. @@ -119,7 +123,7 @@ export class Result { /** * Contains the data from DataFrame. */ - readonly data: object + readonly data?: Record /** * Extra data that can be included. Not part of the standard types. */ @@ -142,6 +146,7 @@ export class Result { this.latex = data['latex'] this.json = data['json'] this.javascript = data['javascript'] + this.data = data['data'] this.isMainResult = isMainResult this.raw = data @@ -161,6 +166,7 @@ export class Result { 'json', 'javascript', 'data', + 'extra' ].includes(key) ) { this.extra[key] = data[key] diff --git a/js/tests/data.test.ts b/js/tests/data.test.ts new file mode 100644 index 0000000..8a638ed --- /dev/null +++ b/js/tests/data.test.ts @@ -0,0 +1,10 @@ +import { expect } from 'vitest' + +import { sandboxTest } from './setup' + +sandboxTest('get data', async ({ sandbox }) => { + const execution = await sandbox.notebook.execCell('pd.DataFrame({"a": [1, 2, 3]})') + + const result = execution.results[0] + expect(result.data).toBeDefined() +}) From 3fa33838bee8e5b4197896221f33406c96fe1102 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 21 Aug 2024 14:08:13 +0000 Subject: [PATCH 12/20] [skip ci] Release new versions --- js/package.json | 2 +- python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index fbfcad5..a6c42b7 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "0.0.9-beta-df.2", + "version": "0.0.9-beta-df.3", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", "license": "MIT", diff --git a/python/pyproject.toml b/python/pyproject.toml index d06640f..a5f7cb9 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b4" +version = "0.0.11b5" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From 5b9f5821e920aca4da04f0838d091b6c4a302619 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:33:17 +0200 Subject: [PATCH 13/20] Revert changes in GitHub action --- .github/workflows/template.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/template.yml b/.github/workflows/template.yml index a5b0554..80a84f5 100644 --- a/.github/workflows/template.yml +++ b/.github/workflows/template.yml @@ -6,7 +6,7 @@ on: - 'template/**' - '.github/workflows/template.yml' branches: - - beta-df + - beta permissions: contents: read @@ -32,6 +32,15 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push to DockerHub + run: | + docker pull ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest || true + docker buildx build \ + --file e2b.Dockerfile \ + --platform linux/amd64 \ + --push \ + --tag ${{ secrets.DOCKERHUB_USERNAME }}/code-interpreter:latest . + - name: Install E2B CLI run: npm install -g @e2b/cli From aa283894a8514347b0805c62290af89d5fb34255 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:39:00 +0200 Subject: [PATCH 14/20] Revert changes --- js/example.mts | 26 +++--------------------- js/src/codeInterpreter.ts | 2 +- python/e2b_code_interpreter/constants.py | 2 +- template/e2b.toml | 10 ++++----- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/js/example.mts b/js/example.mts index 4afc07d..4f185d0 100644 --- a/js/example.mts +++ b/js/example.mts @@ -5,34 +5,14 @@ import { CodeInterpreter } from './dist' dotenv.config() const code = ` -import matplotlib.pyplot as plt -import numpy as np - -x = np.linspace(0, 20, 100) -y = np.sin(x) - -plt.plot(x, y) -plt.show() - -x = np.linspace(0, 10, 100) - -plt.plot(x, y) -plt.show() - -import pandas -pandas.DataFrame({"a": [1, 2, 3]}) +pd.DataFrame({"a": [1, 2, 3]}) ` -const sandbox = await CodeInterpreter.connect("", { debug: true }) +const sandbox = await CodeInterpreter.create("ci-df") console.log(sandbox.sandboxId) const execution = await sandbox.notebook.execCell(code, { - onStdout(msg) { - console.log('stdout', msg) - }, - onStderr(msg) { - console.log('stderr', msg) - }, }) console.log(execution.results[0].formats()) +console.log(execution.results[0].data) console.log(execution.results.length) diff --git a/js/src/codeInterpreter.ts b/js/src/codeInterpreter.ts index f3ef95d..38e6a27 100644 --- a/js/src/codeInterpreter.ts +++ b/js/src/codeInterpreter.ts @@ -245,7 +245,7 @@ export class JupyterExtension { } export class CodeInterpreter extends Sandbox { - protected static override readonly defaultTemplate: string = 'ci-df' + protected static override readonly defaultTemplate: string = 'code-interpreter-beta' protected static readonly jupyterPort = 49999 readonly notebook = new JupyterExtension( diff --git a/python/e2b_code_interpreter/constants.py b/python/e2b_code_interpreter/constants.py index 267d73a..b0f4ec9 100644 --- a/python/e2b_code_interpreter/constants.py +++ b/python/e2b_code_interpreter/constants.py @@ -1,3 +1,3 @@ -DEFAULT_TEMPLATE = "ci-df" +DEFAULT_TEMPLATE = "code-interpreter-beta" JUPYTER_PORT = 49999 DEFAULT_KERNEL_ID = "default" diff --git a/template/e2b.toml b/template/e2b.toml index de9fb67..68c8bbf 100644 --- a/template/e2b.toml +++ b/template/e2b.toml @@ -1,16 +1,16 @@ # This is a config for E2B sandbox template. -# You can use 'template_id' (se2g25klhfixqis2b57f) or 'template_name (ci-df) from this config to spawn a sandbox: +# You can use 'template_id' (3e4rngfa34txe0gxc1zf) or 'template_name (code-interpreter-beta) from this config to spawn a sandbox: # Python SDK # from e2b import Sandbox -# sandbox = Sandbox(template='ci-df') +# sandbox = Sandbox(template='code-interpreter-beta') # JS SDK # import { Sandbox } from 'e2b' -# const sandbox = await Sandbox.create({ template: 'ci-df' }) +# const sandbox = await Sandbox.create({ template: 'code-interpreter-beta' }) memory_mb = 1_024 start_cmd = "/root/.jupyter/start-up.sh" dockerfile = "e2b.Dockerfile" -template_name = "ci-df" -template_id = "se2g25klhfixqis2b57f" +template_name = "code-interpreter-beta" +template_id = "3e4rngfa34txe0gxc1zf" From 9af7869185e895012b661a03b8a85753cfb2690d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 21 Aug 2024 14:44:57 +0000 Subject: [PATCH 15/20] [skip ci] Release new versions --- js/package.json | 2 +- python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index a6c42b7..6ae5870 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "0.0.9-beta-df.3", + "version": "0.0.9-beta-df.4", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", "license": "MIT", diff --git a/python/pyproject.toml b/python/pyproject.toml index a5f7cb9..34deff0 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b5" +version = "0.0.11b6" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0" From 5fa873135534183f2a9f05cf2c8b04bfe768d90e Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:46:08 +0200 Subject: [PATCH 16/20] Add python tests --- js/example.mts | 14 ++++++++++++-- python/async_example.py | 1 + python/tests/async/test_async_data.py | 14 ++++++++++++++ python/tests/sync/test_data.py | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 python/tests/async/test_async_data.py create mode 100644 python/tests/sync/test_data.py diff --git a/js/example.mts b/js/example.mts index 4f185d0..efc7e6f 100644 --- a/js/example.mts +++ b/js/example.mts @@ -5,10 +5,20 @@ import { CodeInterpreter } from './dist' dotenv.config() const code = ` -pd.DataFrame({"a": [1, 2, 3]}) +import matplotlib.pyplot as plt +import numpy as np +x = np.linspace(0, 20, 100) +y = np.sin(x) +plt.plot(x, y) +plt.show() +x = np.linspace(0, 10, 100) +plt.plot(x, y) +plt.show() +import pandas +pandas.DataFrame({"a": [1, 2, 3]}) ` -const sandbox = await CodeInterpreter.create("ci-df") +const sandbox = await CodeInterpreter.create() console.log(sandbox.sandboxId) const execution = await sandbox.notebook.execCell(code, { diff --git a/python/async_example.py b/python/async_example.py index 76e9ec9..5f038b1 100644 --- a/python/async_example.py +++ b/python/async_example.py @@ -6,6 +6,7 @@ load_dotenv() + code = """ import matplotlib.pyplot as plt import numpy as np diff --git a/python/tests/async/test_async_data.py b/python/tests/async/test_async_data.py new file mode 100644 index 0000000..81f508d --- /dev/null +++ b/python/tests/async/test_async_data.py @@ -0,0 +1,14 @@ +from e2b_code_interpreter.code_interpreter_async import AsyncCodeInterpreter + + +async def test_data(async_sandbox: AsyncCodeInterpreter): + # plot random graph + result = await async_sandbox.notebook.exec_cell( + """ + pd.DataFrame({"a": [1, 2, 3]}) + """ + ) + + # there's your image + data = result.results[0] + assert data.data diff --git a/python/tests/sync/test_data.py b/python/tests/sync/test_data.py new file mode 100644 index 0000000..0352de4 --- /dev/null +++ b/python/tests/sync/test_data.py @@ -0,0 +1,16 @@ +from e2b_code_interpreter.code_interpreter_sync import CodeInterpreter + + +def test_data(sandbox: CodeInterpreter): + # plot random graph + result = sandbox.notebook.exec_cell( + """ + pd.DataFrame({"a": [1, 2, 3]}) + """ + ) + + # there's your image + data = result.results[0] + assert data.data + assert "a" in data.data + assert len(data.data["a"]) == 3 From 341705e63f9f538104a3d721be42ec39b18e9d9b Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:47:58 +0200 Subject: [PATCH 17/20] Improve example readability --- js/example.mts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/example.mts b/js/example.mts index efc7e6f..e87708e 100644 --- a/js/example.mts +++ b/js/example.mts @@ -7,13 +7,17 @@ dotenv.config() const code = ` import matplotlib.pyplot as plt import numpy as np + x = np.linspace(0, 20, 100) y = np.sin(x) + plt.plot(x, y) plt.show() + x = np.linspace(0, 10, 100) plt.plot(x, y) plt.show() + import pandas pandas.DataFrame({"a": [1, 2, 3]}) ` @@ -22,6 +26,12 @@ const sandbox = await CodeInterpreter.create() console.log(sandbox.sandboxId) const execution = await sandbox.notebook.execCell(code, { + onStdout(msg) { + console.log('stdout', msg) + }, + onStderr(msg) { + console.log('stderr', msg) + }, }) console.log(execution.results[0].formats()) console.log(execution.results[0].data) From 1cec2acfad5fcd1a9b0fbe8eeb7f72e0e96809c7 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:49:25 +0200 Subject: [PATCH 18/20] Improve test --- python/tests/async/test_async_data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/tests/async/test_async_data.py b/python/tests/async/test_async_data.py index 81f508d..f02d9a6 100644 --- a/python/tests/async/test_async_data.py +++ b/python/tests/async/test_async_data.py @@ -12,3 +12,5 @@ async def test_data(async_sandbox: AsyncCodeInterpreter): # there's your image data = result.results[0] assert data.data + assert "a" in data.data + assert len(data.data["a"]) == 3 From 6244813a85f401bc0edae34719f2bc94d843ca7a Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Wed, 21 Aug 2024 16:49:53 +0200 Subject: [PATCH 19/20] Lint --- js/example.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/example.mts b/js/example.mts index e87708e..3fe5d65 100644 --- a/js/example.mts +++ b/js/example.mts @@ -26,7 +26,7 @@ const sandbox = await CodeInterpreter.create() console.log(sandbox.sandboxId) const execution = await sandbox.notebook.execCell(code, { - onStdout(msg) { + onStdout(msg) { console.log('stdout', msg) }, onStderr(msg) { From d1b4cfa5157fbd0061e569281f5fd4c2065b58b7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 21 Aug 2024 14:52:46 +0000 Subject: [PATCH 20/20] [skip ci] Release new versions --- js/package.json | 2 +- python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/package.json b/js/package.json index 6ae5870..7eb8183 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "@e2b/code-interpreter", - "version": "0.0.9-beta-df.4", + "version": "0.0.9-beta-df.5", "description": "E2B Code Interpreter - Stateful code execution", "homepage": "https://e2b.dev", "license": "MIT", diff --git a/python/pyproject.toml b/python/pyproject.toml index 34deff0..8b070ec 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "e2b-code-interpreter" -version = "0.0.11b6" +version = "0.0.11b7" description = "E2B Code Interpreter - Stateful code execution" authors = ["e2b "] license = "Apache-2.0"