Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Improve the example

Jakub Novak23d8c3b7bbba
diff --git a/apps/docs/src/app/code-interpreter/execution/page.mdx b/apps/docs/src/app/code-interpreter/execution/page.mdx
index 2dadae534..1e843da1f 100644
--- a/apps/docs/src/app/code-interpreter/execution/page.mdx
+++ b/apps/docs/src/app/code-interpreter/execution/page.mdx
@@ -57,38 +57,83 @@ Here's an example how to return the results to LLM:
<CodeGroup isRunnable={false}>
```js
-const code = `<CODE GENERATED BY LLM>`
+const code = '<CODE GENERATED BY LLM>'
const execution = await sandbox.notebook.execCell(code)
-const message = ""
+// There was an error during execution, ruturn the error and its traceback
if (execution.error) {
- message = `There was an error during execution: ${execution.error.name}: ${execution.error.value}. Here's the traceback: ${execution.error.traceback}`
-} else if (execution.results.length > 0) {
- message = "There are results of the cell:\n"
+ return `There was an error during execution: ${execution.error.name}: ${execution.error.value}. Here's the traceback: ${execution.error.traceback}`
+}
+
+// The execution has some result, summarize to LLM, what are the results
+if (execution.results.length > 0) {
+ let message = 'There are results of the cell:\n'
let counter = 1
for (const result of execution.results) {
message += `Result ${counter++}:\n`
if (result.isMainResult) {
message += `Main result of the cell is: ${result.text}\n`
- } else {
+ } else {
message += `Display call: ${result.text}\n`
- }
- message += `It has following formats: ${result.formats()}\n`
- } else if (execution.logs.stdout.length > 0 || execution.logs.stderr.length > 0) {
- message = "There are logs during execution:\n"
- if (execution.logs.stdout.length > 0) {
- message += `Stdout: ${execution.logs.stdout.join("\n")}\n`
- }
- if (execution.logs.stderr.length > 0) {
- message += `Stderr: ${execution.logs.stderr.join("\n")}\n`
- }
}
+ message += `It has following formats: ${result.formats()}\n`
+ }
+ return message
}
+// There were no results, check if there was something is stdout/err
+if (
+ execution.logs.stdout.length > 0 ||
+ execution.logs.stderr.length > 0
+) {
+ let message = 'There are logs during execution:\n'
+ if (execution.logs.stdout.length > 0) {
+ message += `Stdout: ${execution.logs.stdout.join('\n')}\n`
+ }
+ if (execution.logs.stderr.length > 0) {
+ message += `Stderr: ${execution.logs.stderr.join('\n')}\n`
+ }
+
+ return message
+}
+
+return 'There was no output of the execution.'
```
```python
-pip install e2b
+code = "<CODE GENERATED BY LLM>"
+execution = sandbox.notebook.exec_cell(code)
+
+# There was an error during execution, ruturn the error and its traceback
+if execution.error:
+ return f"There was an error during execution: {execution.error.name}: {execution.error.value}. Here's the traceback: {execution.error.traceback}"
+
+# The execution has some result, summarize to LLM, what are the results
+if execution.results:
+ message = "There are results of the cell:\n"
+ for i, result in enumerate(execution.results):
+ message += f"Result {counter}:\n"
+ if result.is_main_result:
+ message += f"Main result of the cell is: {result.text}\n"
+ else:
+ message += f"Display call: {result.text}\n"
+
+ message += f"It has following formats: {result.formats()}\n"
+
+ return message
+
+# There were no results, check if there was something is stdout/err
+if execution.logs.stdout or execution.logs.stderr:
+ message = "There are logs during execution:\n"
+ if execution.logs.stdout:
+ message += f"Stdout: {'\n'.join(execution.logs.stdout)}\n"
+
+ if execution.logs.stderr:
+ message += f"Stderr: {'\n'.join(execution.logs.stderr)}\n"
+
+ return message
+
+return "There was no output of the execution."
```
</CodeGroup>