Make e2b optional dependency (#292)

* Make e2b optional dependency with extra

* Make e2b imports optional

* Update e2b docs
This commit is contained in:
Albert Villanova del Moral 2025-01-21 12:17:24 +01:00 committed by GitHub
parent 257c1fe33b
commit 16f7910df8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 7 deletions

View File

@ -60,7 +60,7 @@ For maximum security, you can use our integration with E2B to run code in a sand
For this, you will need to setup your E2B account and set your `E2B_API_KEY` in your environment variables. Head to [E2B's quickstart documentation](https://e2b.dev/docs/quickstart) for more information. For this, you will need to setup your E2B account and set your `E2B_API_KEY` in your environment variables. Head to [E2B's quickstart documentation](https://e2b.dev/docs/quickstart) for more information.
Then you can install it with `pip install e2b-code-interpreter python-dotenv`. Then you can install it with `pip install "smolagents[e2b]"`.
Now you're set! Now you're set!

View File

@ -20,8 +20,6 @@ dependencies = [
"pillow>=11.0.0", "pillow>=11.0.0",
"markdownify>=0.14.1", "markdownify>=0.14.1",
"duckduckgo-search>=6.3.7", "duckduckgo-search>=6.3.7",
"python-dotenv>=1.0.1",
"e2b-code-interpreter>=1.0.3",
"torchvision" "torchvision"
] ]
@ -38,6 +36,10 @@ transformers = [
"transformers>=4.0.0", "transformers>=4.0.0",
"smolagents[torch]", "smolagents[torch]",
] ]
e2b = [
"e2b-code-interpreter>=1.0.3",
"python-dotenv>=1.0.1",
]
gradio = [ gradio = [
"gradio>=5.8.0", "gradio>=5.8.0",
] ]
@ -55,10 +57,11 @@ quality = [
"ruff>=0.9.0", "ruff>=0.9.0",
] ]
all = [ all = [
"smolagents[accelerate,audio,gradio,litellm,mcp,openai,transformers]", "smolagents[accelerate,audio,e2b,gradio,litellm,mcp,openai,transformers]",
] ]
test = [ test = [
"pytest>=8.1.0", "pytest>=8.1.0",
"python-dotenv>=1.0.1", # For test_all_docs
"smolagents[all]", "smolagents[all]",
] ]
dev = [ dev = [

View File

@ -20,8 +20,6 @@ import textwrap
from io import BytesIO from io import BytesIO
from typing import Any, List, Tuple from typing import Any, List, Tuple
from dotenv import load_dotenv
from e2b_code_interpreter import Sandbox
from PIL import Image from PIL import Image
from .tool_validation import validate_tool_attributes from .tool_validation import validate_tool_attributes
@ -29,11 +27,23 @@ from .tools import Tool
from .utils import BASE_BUILTIN_MODULES, instance_to_source from .utils import BASE_BUILTIN_MODULES, instance_to_source
load_dotenv() try:
from dotenv import load_dotenv
load_dotenv()
except ModuleNotFoundError:
pass
class E2BExecutor: class E2BExecutor:
def __init__(self, additional_imports: List[str], tools: List[Tool], logger): def __init__(self, additional_imports: List[str], tools: List[Tool], logger):
try:
from e2b_code_interpreter import Sandbox
except ModuleNotFoundError:
raise ModuleNotFoundError(
"""Please install 'e2b' extra to use E2BExecutor: `pip install "smolagents[e2b]"`"""
)
self.custom_tools = {} self.custom_tools = {}
self.sbx = Sandbox() # "qywp2ctmu2q7jzprcf4j") self.sbx = Sandbox() # "qywp2ctmu2q7jzprcf4j")
# TODO: validate installing agents package or not # TODO: validate installing agents package or not