Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Improve the interpretation example

Jakub Novak57a9382bc353
diff --git a/apps/docs/src/app/code-interpreter/execution/page.mdx b/apps/docs/src/app/code-interpreter/execution/page.mdx
index 7eb5ba139..f08cc0508 100644
--- a/apps/docs/src/app/code-interpreter/execution/page.mdx
+++ b/apps/docs/src/app/code-interpreter/execution/page.mdx
@@ -73,23 +73,26 @@ Here's an example how to return the results to LLM:
const code = '<CODE GENERATED BY LLM>'
const execution = await sandbox.notebook.execCell(code)
-// There was an error during execution, ruturn the error and its traceback
+// There was an error during execution, return the error and its traceback
if (execution.error) {
- return `There was an error during execution: ${execution.error.name}: ${execution.error.value}. Here's the traceback: ${execution.error.traceback}`
+ return `There was an error during execution: ${execution.error.name}: ${execution.error.value}.\n
+ ${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 message = 'These are results of the execution:\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`
+ message += `[Main result]: ${result.text}\n`
} else {
- message += `Display call: ${result.text}\n`
+ message += `[Display data]: ${result.text}\n`
+ }
+ if (result.formats().length > 0) {
+ message += `It has following formats: ${result.formats()}\n`
}
- message += `It has following formats: ${result.formats()}\n`
}
return message
@@ -100,7 +103,7 @@ if (
execution.logs.stdout.length > 0 ||
execution.logs.stderr.length > 0
) {
- let message = 'There are logs during execution:\n'
+ let message = 'There was no result of the execution, but here are the logs:\n'
if (execution.logs.stdout.length > 0) {
message += `Stdout: ${execution.logs.stdout.join('\n')}\n`
}
@@ -118,32 +121,36 @@ return 'There was no output of the execution.'
code = "<CODE GENERATED BY LLM>"
execution = sandbox.notebook.exec_cell(code)
-# There was an error during execution, ruturn the error and its traceback
+# There was an error during execution, return 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}"
+ return (
+ f"There was an error during execution: {execution.error.name}: {execution.error.value}.\n"
+ f"{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"
+ message = "These are results of the execution:\n"
for i, result in enumerate(execution.results):
- message += f"Result {counter}:\n"
+ message += f"Result {i + 1}:\n"
if result.is_main_result:
- message += f"Main result of the cell is: {result.text}\n"
+ message += f"[Main result]: {result.text}\n"
else:
- message += f"Display call: {result.text}\n"
+ message += f"[Display data]: {result.text}\n"
- message += f"It has following formats: {result.formats()}\n"
+ if result.formats():
+ message += f"It has also 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"
+ message = "There was no result of the execution, but here are the logs:\n"
+ if execution.logs.stdout:
+ message += "Stdout: " + "\n".join(execution.logs.stdout) + "\n"
- if execution.logs.stderr:
- message += f"Stderr: {'\n'.join(execution.logs.stderr)}\n"
+ if execution.logs.stderr:
+ message += "Stderr: " + "\n".join(execution.logs.stderr) + "\n"
return message