Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump: code interpreter v1 #469

Merged
merged 18 commits into from
Dec 26, 2024
Merged

bump: code interpreter v1 #469

merged 18 commits into from
Dec 26, 2024

Conversation

thucpn
Copy link
Collaborator

@thucpn thucpn commented Dec 23, 2024

Changes:

  • CodeInterpreter class is removed
  • code-interpreter-multilang template is used as default
  • change the way write/get sandbox files

Summary by CodeRabbit

  • New Features

    • Enhanced sandbox functionality with support for specific sandbox files in code generation.
    • Introduced constants for supported templates and output directory in sandbox handling.
  • Bug Fixes

    • Improved error handling and logging consistency across sandbox operations.
  • Documentation

    • Updated method signatures to reflect changes in sandbox and code execution methods.
  • Chores

    • Updated dependency versions for @e2b/code-interpreter across multiple projects.
    • Updated dependency versions for e2b_code_interpreter in relevant tools.

Copy link

changeset-bot bot commented Dec 23, 2024

⚠️ No Changeset found

Latest commit: 0119546

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@thucpn thucpn requested review from marcusschiesser and leehuwuj and removed request for marcusschiesser December 23, 2024 11:22
Copy link

coderabbitai bot commented Dec 23, 2024

Walkthrough

This pull request introduces updates to the version numbers of dependencies for the "Code Interpreter" and "Artifact Code Generator" tools, changing the e2b_code_interpreter from 0.0.11b38 to 1.0.3. Additionally, it transitions from the CodeInterpreter class to the Sandbox class across various files, modifying how code execution is handled. The changes affect both TypeScript and Python files, streamlining the functionality and management of code execution in the respective components.

Changes

File Change Summary
helpers/tools.ts Updated e2b_code_interpreter dependency version to 1.0.3 for Code Interpreter and Artifact Code Generator tools.
templates/components/engines/python/agent/tools/interpreter.py Replaced CodeInterpreter with Sandbox, updated code execution method from notebook.exec_cell() to run_code().
templates/components/engines/typescript/agent/tools/code-generator.ts Added sandboxFiles and attachments parameters to enhance code generation with file context.
templates/components/engines/typescript/agent/tools/interpreter.ts Migrated from CodeInterpreter to Sandbox, updated method calls and property types.
templates/components/routers/python/sandbox.py Simplified sandbox creation, added SUPPORTED_TEMPLATES, removed CodeInterpreter handling.
templates/types/streaming/*/package.json Updated @e2b/code-interpreter dependency to version 1.0.4.
templates/types/streaming/*/sandbox controllers Replaced CodeInterpreter with Sandbox, updated code execution and sandbox management methods.

Possibly Related PRs

  • feat: implement interpreter tool #94: The main PR updates the version numbers of dependencies for the "Code Interpreter" and "Artifact Code Generator" tools, which is related to the changes in the helpers/tools.ts file in this PR that also involves modifications to the "Artifact Code Generator" tool's dependencies.
  • upload file to sandbox #355: This PR updates the version of the e2b_code_interpreter dependency for both the "Code Interpreter" and "Artifact Code Generator" tools, aligning with the version updates made in the main PR.
  • Refactor query engine tool code and use auto_routed mode for LlamaCloudIndex #450: The changes in this PR involve the integration of the query engine tool, which may relate to the overall functionality of the tools mentioned in the main PR, particularly in how they interact with dependencies.
  • Bump llamacloud index and fix issues #456: This PR updates the LlamaCloud library and addresses breaking changes, which could impact the functionality of the tools updated in the main PR, particularly if they rely on LlamaCloud for their operations.

Poem

🐰 Hopping through code with glee,
Sandbox upgrades, version three!
From beta to stable, we leap so high,
Interpreters dancing 'neath the sky 🚀
CodeRabbit's magic, smooth and light! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0119546 and 2555faf.

📒 Files selected for processing (1)
  • .changeset/stale-berries-hear.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/stale-berries-hear.md

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@thucpn thucpn marked this pull request as ready for review December 25, 2024 08:58
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (11)
templates/types/streaming/express/src/controllers/sandbox.controller.ts (3)

38-39: Consider centralizing output directory configuration.
If you find yourself repeating OUTPUT_DIR across multiple files, you could export it from a shared config module to reduce duplication.


49-56: Avoid repetition of SUPPORTED_TEMPLATES.
The SUPPORTED_TEMPLATES array appears in multiple files. Centralizing these constants in a shared configuration or constants file can improve maintainability.


74-77: Check error handling for dependency installation.
If install_dependencies_command fails, the system may appear to succeed. Consider adding a try/catch or error check to handle this possibility.

templates/types/streaming/nextjs/app/api/sandbox/route.ts (3)

39-40: Consolidate OUTPUT_DIR if reused in multiple files.
Consider maintaining a single source for this path to avoid scattering output directory definitions.


50-56: Centralize SUPPORTED_TEMPLATES definition.
Like in other files, SUPPORTED_TEMPLATES is duplicated; moving it to a shared location could reduce maintenance overhead.


75-78: Add error handling for dependency installation.
Currently, no error capture is in place. Users could benefit from logging or returning a warning if the installation fails.

templates/components/engines/typescript/agent/tools/interpreter.ts (2)

107-127: Create sandbox and upload extra files if needed.

  1. The Sandbox.create call is straightforward.
  2. Uploading files in a loop is riskier if anything fails mid-upload (you might want a try/catch for each file).
  3. Logging confirms file writes, which is helpful for debugging.

177-177: Graceful sandbox cleanup.
The kill() method ensures resource release. Confirm if you need any final logs or post-run steps.

templates/components/routers/python/sandbox.py (2)

63-69: Add a comment clarifying template purposes.
Defining SUPPORTED_TEMPLATES here is consistent with the rest of the codebase, but watch for duplication. Consider a shared constants module.


102-105: Dependencies installed without error check.
Running sbx.commands.run(...) can fail silently if not monitored. Consider returning logs or verifying installation success.

templates/components/engines/python/agent/tools/interpreter.py (1)

166-166: Avoid overshadowing the built-in exec
Currently, the variable is named exec, which can overshadow Python’s built-in exec statement. Consider renaming it for clarity.

- exec = self.interpreter.run_code(code)
+ exec_result = self.interpreter.run_code(code)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 765d2c4 and 0e5a47a.

📒 Files selected for processing (9)
  • helpers/tools.ts (2 hunks)
  • templates/components/engines/python/agent/tools/interpreter.py (3 hunks)
  • templates/components/engines/typescript/agent/tools/code-generator.ts (2 hunks)
  • templates/components/engines/typescript/agent/tools/interpreter.ts (5 hunks)
  • templates/components/routers/python/sandbox.py (5 hunks)
  • templates/types/streaming/express/package.json (1 hunks)
  • templates/types/streaming/express/src/controllers/sandbox.controller.ts (4 hunks)
  • templates/types/streaming/nextjs/app/api/sandbox/route.ts (5 hunks)
  • templates/types/streaming/nextjs/package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
templates/types/streaming/nextjs/package.json (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/types/streaming/express/package.json (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/engines/python/agent/tools/interpreter.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/types/streaming/nextjs/app/api/sandbox/route.ts (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/engines/typescript/agent/tools/code-generator.ts (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/engines/typescript/agent/tools/interpreter.ts (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/components/routers/python/sandbox.py (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

templates/types/streaming/express/src/controllers/sandbox.controller.ts (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

🔇 Additional comments (29)
templates/types/streaming/express/src/controllers/sandbox.controller.ts (5)

16-18: Imports look consistent with the project's needs.
No issues found with the new imports from @e2b/code-interpreter and path.


60-70: Validate and handle unknown templates more explicitly.
When an unsupported template is given, a generic sandbox is created. Ensure it is intentional by verifying that the user is aware of this fallback and that no tasks rely on custom logic for an unknown template.


84-84: File copying looks fine.
The log statement provides sufficient visibility. No further issues noted.


88-88: File copying for single file approach is correct.
The approach and logging are clear. No additional suggestions.


93-94: Ensure sandbox termination timing aligns with business logic.
Killing the sandbox may be desired for short-lived tasks, but verify there are no subsequent calls that need the same sandbox instance.

templates/types/streaming/nextjs/app/api/sandbox/route.ts (7)

16-16: Imports for sandbox functionality.
All necessary imports look properly referenced.


61-69: Evaluate fallback behavior when template is not supported.
As with the Express controller, ensure that using await Sandbox.create(sandboxOpts) for an unsupported template is intentional.


90-90: File copying approach.
Reading from local paths and writing to sandbox files is straightforward. Consider additional logs for file size or success/fail checks if needed.


98-102: Single file code copying is handled effectively.
The approach is consistent with multi-file copying, and the logging is clear.


107-108: Confirm that immediate sandbox termination is intended.
Double-check whether subsequent interactions are needed before calling kill().


133-133: Returns empty array for no cell results.
This is a sensible default, ensuring no null references downstream.


138-149: Filtering final formats for multi-output results is correct.
Restricting to ["png", "svg", "jpeg", "pdf"] is practical. The rest is processed as textual content or ignored.

templates/components/engines/typescript/agent/tools/interpreter.ts (3)

1-1: Imports for basic sandbox execution.
Replacing or including Sandbox in these imports directly aligns with the current PR’s objective.


85-85: Property update from CodeInterpreter to Sandbox.
Switching codeInterpreter to Sandbox is consistent with the removal of the CodeInterpreter class.


158-158: Execution method changed to runCode.
Matches the updated API. No issues found.

templates/components/engines/typescript/agent/tools/code-generator.ts (3)

106-106: Passing sandbox file paths to artifact generation.
Allowing the code-generation logic to reference additional files is a good extension for more complex tasks.


121-121: New attachments parameter in generateArtifact.
Helps incorporate relevant files or references into the user message. This is a sound design choice for more contextual generation.


126-126: Attaching file references in userMessage.
Including the file references in the user message can improve artifact accuracy if the code depends on external resources.

templates/components/routers/python/sandbox.py (5)

20-20: Typing import usage check.
Using typing.List and similar references is consistent with Python best practices.


24-24: Sandbox import.
Aligns with the migration away from the CodeInterpreter. No further issues noted here.


90-98: Sandbox instantiation.

  1. Creating a sandbox with None for unsupported templates is a practical fallback.
  2. Double-check logs for seat-of-the-pants debugging to confirm the fallback template is used.

122-122: Switch to run_code from exec_cell.
Consolidates the approach for executing code. Good alignment with the revised Sandbox API.


145-145: _upload_files restricted to Sandbox type.
Removes the union type, simplifying the interface. No issues found, as CodeInterpreter is deprecated.

templates/components/engines/python/agent/tools/interpreter.py (3)

8-8: Use of Sandbox instead of CodeInterpreter
This aligns with the PR objective of removing CodeInterpreter. The import statement correctly references the new Sandbox class from e2b_code_interpreter.


64-64: Proper initialization of the new sandbox environment
Instantiating Sandbox(api_key=self.api_key) looks good. Ensure that any additional environment or configuration parameters required by the new sandbox environment are handled elsewhere if necessary.


162-162: Valid interpreter check
This if-statement gating is consistent with lazy initialization logic. No issues found.

helpers/tools.ts (1)

127-127: Dependency version bump to 1.0.3
Upgrading from 0.0.11b38 to 1.0.3 for e2b_code_interpreter aligns with the overall PR goal of switching to the sandbox-based approach. This is consistent with changes in other files.

Also applies to: 158-158

templates/types/streaming/express/package.json (1)

27-27: Updated @e2b/code-interpreter version to 1.0.4
Verifying that the new version is compatible and stable is recommended.

✅ Verification successful

Version 1.0.4 of @e2b/code-interpreter is consistently used across the codebase

The verification shows that the package version 1.0.4 is consistently used in both Express and NextJS template configurations. The package is properly imported and used in the following files:

  • templates/components/engines/typescript/agent/tools/interpreter.ts
  • templates/types/streaming/nextjs/app/api/sandbox/route.ts
  • templates/types/streaming/express/src/controllers/sandbox.controller.ts

Let me verify if there are any breaking changes or compatibility issues by checking the package's version history.


Let me check the actual usage of the code interpreter to ensure there are no breaking changes in error handling or API usage.


Version 1.0.4 of @e2b/code-interpreter is safely integrated

The verification shows that:

  • The package version is consistently used across all templates
  • The imports and type usage (ExecutionError, Result, Sandbox) are uniform across the codebase
  • Error handling patterns are properly implemented in both Express and NextJS templates
  • No breaking changes in the API usage pattern are detected
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for references to @e2b/code-interpreter across the repo to confirm usage is updated
rg -A 5 '@e2b/code-interpreter'

Length of output: 2913


Script:

#!/bin/bash
# Check package.json files for any peer dependencies or version constraints
rg -g 'package.json' -A 10 '"dependencies":'

# Check for any error handling patterns that might need updates
ast-grep --pattern 'catch (error) { $$$  }'

Length of output: 2274


Script:

#!/bin/bash
# Check for Sandbox usage patterns
ast-grep --pattern 'new Sandbox($$$)'

# Check for specific Result and ExecutionError usage
ast-grep --pattern 'import { $$$, Result, $$$} from "@e2b/code-interpreter"'

# Look for any error handling specific to code-interpreter
rg -g '*.ts' -A 5 'ExecutionError'

Length of output: 2958

templates/types/streaming/nextjs/package.json (1)

14-14: Dependency bump for @e2b/code-interpreter
Upgrading to 1.0.4 aligns with the PR’s transition to the sandbox environment. No immediate issues found.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
templates/components/engines/typescript/agent/tools/interpreter.ts (2)

154-155: Consider structured error handling instead of console.error.

The error logging could be improved to use a proper logging framework and include more context.

Consider this enhancement:

-    const exec = await interpreter.runCode(input.code);
-    if (exec.error) console.error("[Code Interpreter error]", exec.error);
+    const exec = await interpreter.runCode(input.code);
+    if (exec.error) {
+      // Use your application's logger here
+      logger.error("[Code Interpreter error]", {
+        error: exec.error,
+        code: input.code,
+        retryCount: input.retryCount
+      });
+    }

173-173: Add error handling for sandbox cleanup.

The kill operation should include error handling to ensure proper cleanup.

Consider this enhancement:

-    await this.codeInterpreter?.kill();
+    try {
+      await this.codeInterpreter?.kill();
+    } catch (error) {
+      // Use your application's logger here
+      logger.error("Failed to kill sandbox", { error });
+    }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e5a47a and ecaec22.

📒 Files selected for processing (1)
  • templates/components/engines/typescript/agent/tools/interpreter.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
templates/components/engines/typescript/agent/tools/interpreter.ts (1)

Pattern templates/**: For files under the templates folder, do not report 'Missing Dependencies Detected' errors.

🔇 Additional comments (1)
templates/components/engines/typescript/agent/tools/interpreter.ts (1)

1-1: LGTM: Import and type changes align with migration to Sandbox.

The changes correctly implement the transition from CodeInterpreter to Sandbox class as mentioned in the PR objectives.

Also applies to: 85-85

@thucpn thucpn requested a review from leehuwuj December 26, 2024 02:34
@marcusschiesser marcusschiesser merged commit fc5e56e into main Dec 26, 2024
46 checks passed
@marcusschiesser marcusschiesser deleted the feat/bump-code-interpreter branch December 26, 2024 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants