Repository: huggingface/smolagents

Issue:
[BUG] CI test fails: TypeError: LlavaProcessor: got multiple values for keyword argument 'images'
**Describe the bug**
CI test fails: TypeError: LlavaProcessor: got multiple values for keyword argument 'images'
> FAILED tests/test_models.py::ModelTests::test_transformers_message_vl_no_tool - TypeError: LlavaProcessor:
> ...
>  got multiple values for keyword argument 'images'


**Error logs (if any)**
```python
 E           {
E             "image_token": "<image>",
E             "num_additional_image_tokens": 0,
E             "patch_size": 14,
E             "processor_class": "LlavaProcessor",
E             "vision_feature_select_strategy": "full"
E           }
E            got multiple values for keyword argument 'images'

.venv/lib/python3.10/site-packages/transformers/processing_utils.py:1383: TypeError
```



Discussion:

Patch:
diff --git a/docs/source/en/conceptual_guides/intro_agents.md b/docs/source/en/conceptual_guides/intro_agents.mdx
similarity index 100%
rename from docs/source/en/conceptual_guides/intro_agents.md
rename to docs/source/en/conceptual_guides/intro_agents.mdx
diff --git a/docs/source/en/conceptual_guides/react.md b/docs/source/en/conceptual_guides/react.mdx
similarity index 100%
rename from docs/source/en/conceptual_guides/react.md
rename to docs/source/en/conceptual_guides/react.mdx
diff --git a/docs/source/en/examples/multiagents.md b/docs/source/en/examples/multiagents.mdx
similarity index 100%
rename from docs/source/en/examples/multiagents.md
rename to docs/source/en/examples/multiagents.mdx
diff --git a/docs/source/en/examples/rag.md b/docs/source/en/examples/rag.mdx
similarity index 100%
rename from docs/source/en/examples/rag.md
rename to docs/source/en/examples/rag.mdx
diff --git a/docs/source/en/examples/text_to_sql.md b/docs/source/en/examples/text_to_sql.mdx
similarity index 100%
rename from docs/source/en/examples/text_to_sql.md
rename to docs/source/en/examples/text_to_sql.mdx
diff --git a/docs/source/en/examples/web_browser.md b/docs/source/en/examples/web_browser.mdx
similarity index 100%
rename from docs/source/en/examples/web_browser.md
rename to docs/source/en/examples/web_browser.mdx
diff --git a/docs/source/en/guided_tour.md b/docs/source/en/guided_tour.mdx
similarity index 100%
rename from docs/source/en/guided_tour.md
rename to docs/source/en/guided_tour.mdx
diff --git a/docs/source/en/index.md b/docs/source/en/index.mdx
similarity index 100%
rename from docs/source/en/index.md
rename to docs/source/en/index.mdx
diff --git a/docs/source/en/reference/agents.md b/docs/source/en/reference/agents.mdx
similarity index 100%
rename from docs/source/en/reference/agents.md
rename to docs/source/en/reference/agents.mdx
diff --git a/docs/source/en/reference/models.md b/docs/source/en/reference/models.mdx
similarity index 100%
rename from docs/source/en/reference/models.md
rename to docs/source/en/reference/models.mdx
diff --git a/docs/source/en/reference/tools.md b/docs/source/en/reference/tools.mdx
similarity index 100%
rename from docs/source/en/reference/tools.md
rename to docs/source/en/reference/tools.mdx
diff --git a/docs/source/en/tutorials/building_good_agents.md b/docs/source/en/tutorials/building_good_agents.mdx
similarity index 100%
rename from docs/source/en/tutorials/building_good_agents.md
rename to docs/source/en/tutorials/building_good_agents.mdx
diff --git a/docs/source/en/tutorials/inspect_runs.md b/docs/source/en/tutorials/inspect_runs.mdx
similarity index 100%
rename from docs/source/en/tutorials/inspect_runs.md
rename to docs/source/en/tutorials/inspect_runs.mdx
diff --git a/docs/source/en/tutorials/memory.md b/docs/source/en/tutorials/memory.mdx
similarity index 100%
rename from docs/source/en/tutorials/memory.md
rename to docs/source/en/tutorials/memory.mdx
diff --git a/docs/source/en/tutorials/secure_code_execution.md b/docs/source/en/tutorials/secure_code_execution.mdx
similarity index 100%
rename from docs/source/en/tutorials/secure_code_execution.md
rename to docs/source/en/tutorials/secure_code_execution.mdx
diff --git a/docs/source/en/tutorials/tools.md b/docs/source/en/tutorials/tools.mdx
similarity index 100%
rename from docs/source/en/tutorials/tools.md
rename to docs/source/en/tutorials/tools.mdx
diff --git a/docs/source/hi/conceptual_guides/intro_agents.md b/docs/source/hi/conceptual_guides/intro_agents.mdx
similarity index 100%
rename from docs/source/hi/conceptual_guides/intro_agents.md
rename to docs/source/hi/conceptual_guides/intro_agents.mdx
diff --git a/docs/source/hi/conceptual_guides/react.md b/docs/source/hi/conceptual_guides/react.mdx
similarity index 100%
rename from docs/source/hi/conceptual_guides/react.md
rename to docs/source/hi/conceptual_guides/react.mdx
diff --git a/docs/source/hi/examples/multiagents.md b/docs/source/hi/examples/multiagents.mdx
similarity index 100%
rename from docs/source/hi/examples/multiagents.md
rename to docs/source/hi/examples/multiagents.mdx
diff --git a/docs/source/hi/examples/rag.md b/docs/source/hi/examples/rag.mdx
similarity index 100%
rename from docs/source/hi/examples/rag.md
rename to docs/source/hi/examples/rag.mdx
diff --git a/docs/source/hi/examples/text_to_sql.md b/docs/source/hi/examples/text_to_sql.mdx
similarity index 100%
rename from docs/source/hi/examples/text_to_sql.md
rename to docs/source/hi/examples/text_to_sql.mdx
diff --git a/docs/source/hi/guided_tour.md b/docs/source/hi/guided_tour.mdx
similarity index 100%
rename from docs/source/hi/guided_tour.md
rename to docs/source/hi/guided_tour.mdx
diff --git a/docs/source/hi/index.md b/docs/source/hi/index.mdx
similarity index 100%
rename from docs/source/hi/index.md
rename to docs/source/hi/index.mdx
diff --git a/docs/source/hi/reference/agents.md b/docs/source/hi/reference/agents.mdx
similarity index 100%
rename from docs/source/hi/reference/agents.md
rename to docs/source/hi/reference/agents.mdx
diff --git a/docs/source/hi/reference/tools.md b/docs/source/hi/reference/tools.mdx
similarity index 100%
rename from docs/source/hi/reference/tools.md
rename to docs/source/hi/reference/tools.mdx
diff --git a/docs/source/hi/tutorials/building_good_agents.md b/docs/source/hi/tutorials/building_good_agents.mdx
similarity index 100%
rename from docs/source/hi/tutorials/building_good_agents.md
rename to docs/source/hi/tutorials/building_good_agents.mdx
diff --git a/docs/source/hi/tutorials/inspect_runs.md b/docs/source/hi/tutorials/inspect_runs.mdx
similarity index 100%
rename from docs/source/hi/tutorials/inspect_runs.md
rename to docs/source/hi/tutorials/inspect_runs.mdx
diff --git a/docs/source/hi/tutorials/secure_code_execution.md b/docs/source/hi/tutorials/secure_code_execution.mdx
similarity index 100%
rename from docs/source/hi/tutorials/secure_code_execution.md
rename to docs/source/hi/tutorials/secure_code_execution.mdx
diff --git a/docs/source/hi/tutorials/tools.md b/docs/source/hi/tutorials/tools.mdx
similarity index 100%
rename from docs/source/hi/tutorials/tools.md
rename to docs/source/hi/tutorials/tools.mdx
diff --git a/docs/source/zh/conceptual_guides/intro_agents.md b/docs/source/zh/conceptual_guides/intro_agents.mdx
similarity index 100%
rename from docs/source/zh/conceptual_guides/intro_agents.md
rename to docs/source/zh/conceptual_guides/intro_agents.mdx
diff --git a/docs/source/zh/conceptual_guides/react.md b/docs/source/zh/conceptual_guides/react.mdx
similarity index 100%
rename from docs/source/zh/conceptual_guides/react.md
rename to docs/source/zh/conceptual_guides/react.mdx
diff --git a/docs/source/zh/examples/multiagents.md b/docs/source/zh/examples/multiagents.mdx
similarity index 100%
rename from docs/source/zh/examples/multiagents.md
rename to docs/source/zh/examples/multiagents.mdx
diff --git a/docs/source/zh/examples/rag.md b/docs/source/zh/examples/rag.mdx
similarity index 100%
rename from docs/source/zh/examples/rag.md
rename to docs/source/zh/examples/rag.mdx
diff --git a/docs/source/zh/examples/text_to_sql.md b/docs/source/zh/examples/text_to_sql.mdx
similarity index 100%
rename from docs/source/zh/examples/text_to_sql.md
rename to docs/source/zh/examples/text_to_sql.mdx
diff --git a/docs/source/zh/guided_tour.md b/docs/source/zh/guided_tour.mdx
similarity index 100%
rename from docs/source/zh/guided_tour.md
rename to docs/source/zh/guided_tour.mdx
diff --git a/docs/source/zh/index.md b/docs/source/zh/index.mdx
similarity index 100%
rename from docs/source/zh/index.md
rename to docs/source/zh/index.mdx
diff --git a/docs/source/zh/reference/agents.md b/docs/source/zh/reference/agents.mdx
similarity index 100%
rename from docs/source/zh/reference/agents.md
rename to docs/source/zh/reference/agents.mdx
diff --git a/docs/source/zh/reference/models.md b/docs/source/zh/reference/models.mdx
similarity index 100%
rename from docs/source/zh/reference/models.md
rename to docs/source/zh/reference/models.mdx
diff --git a/docs/source/zh/reference/tools.md b/docs/source/zh/reference/tools.mdx
similarity index 100%
rename from docs/source/zh/reference/tools.md
rename to docs/source/zh/reference/tools.mdx
diff --git a/docs/source/zh/tutorials/building_good_agents.md b/docs/source/zh/tutorials/building_good_agents.mdx
similarity index 100%
rename from docs/source/zh/tutorials/building_good_agents.md
rename to docs/source/zh/tutorials/building_good_agents.mdx
diff --git a/docs/source/zh/tutorials/secure_code_execution.md b/docs/source/zh/tutorials/secure_code_execution.mdx
similarity index 100%
rename from docs/source/zh/tutorials/secure_code_execution.md
rename to docs/source/zh/tutorials/secure_code_execution.mdx
diff --git a/docs/source/zh/tutorials/tools.md b/docs/source/zh/tutorials/tools.mdx
similarity index 100%
rename from docs/source/zh/tutorials/tools.md
rename to docs/source/zh/tutorials/tools.mdx
diff --git a/pyproject.toml b/pyproject.toml
index db2365a..ab323f8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -60,7 +60,7 @@ telemetry = [
 ]
 transformers = [
   "accelerate",
-  "transformers>=4.0.0",
+  "transformers>=4.0.0,<4.49.0",
   "smolagents[torch]",
 ]
 all = [
diff --git a/src/smolagents/local_python_executor.py b/src/smolagents/local_python_executor.py
index a7b2fb3..e2df293 100644
--- a/src/smolagents/local_python_executor.py
+++ b/src/smolagents/local_python_executor.py
@@ -114,6 +114,26 @@ BASE_PYTHON_TOOLS = {
     "complex": complex,
 }
 
+DANGEROUS_PATTERNS = (
+    "_os",
+    "os",
+    "subprocess",
+    "_subprocess",
+    "pty",
+    "system",
+    "popen",
+    "spawn",
+    "shutil",
+    "sys",
+    "pathlib",
+    "io",
+    "socket",
+    "compile",
+    "eval",
+    "exec",
+    "multiprocessing",
+)
+
 
 class PrintContainer:
     def __init__(self):
@@ -954,7 +974,7 @@ def evaluate_with(
             context.__exit__(None, None, None)
 
 
-def get_safe_module(raw_module, dangerous_patterns, authorized_imports, visited=None):
+def get_safe_module(raw_module, authorized_imports, visited=None):
     """Creates a safe copy of a module or returns the original if it's a function"""
     # If it's a function or non-module object, return it directly
     if not isinstance(raw_module, ModuleType):
@@ -978,8 +998,8 @@ def get_safe_module(raw_module, dangerous_patterns, authorized_imports, visited=
         # Skip dangerous patterns at any level
         if any(
             pattern in raw_module.__name__.split(".") + [attr_name]
-            and not check_module_authorized(pattern, authorized_imports, dangerous_patterns)
-            for pattern in dangerous_patterns
+            and not check_module_authorized(pattern, authorized_imports)
+            for pattern in DANGEROUS_PATTERNS
         ):
             logger.info(f"Skipping dangerous attribute {raw_module.__name__}.{attr_name}")
             continue
@@ -994,19 +1014,19 @@ def get_safe_module(raw_module, dangerous_patterns, authorized_imports, visited=
             continue
         # Recursively process nested modules, passing visited set
         if isinstance(attr_value, ModuleType):
-            attr_value = get_safe_module(attr_value, dangerous_patterns, authorized_imports, visited=visited)
+            attr_value = get_safe_module(attr_value, authorized_imports, visited=visited)
 
         setattr(safe_module, attr_name, attr_value)
 
     return safe_module
 
 
-def check_module_authorized(module_name, authorized_imports, dangerous_patterns):
+def check_module_authorized(module_name, authorized_imports):
     if "*" in authorized_imports:
         return True
     else:
         module_path = module_name.split(".")
-        if any([module in dangerous_patterns and module not in authorized_imports for module in module_path]):
+        if any([module in DANGEROUS_PATTERNS and module not in authorized_imports for module in module_path]):
             return False
         # ["A", "B", "C"] -> ["A", "A.B", "A.B.C"]
         module_subpaths = [".".join(module_path[:i]) for i in range(1, len(module_path) + 1)]
@@ -1014,40 +1034,20 @@ def check_module_authorized(module_name, authorized_imports, dangerous_patterns)
 
 
 def import_modules(expression, state, authorized_imports):
-    dangerous_patterns = (
-        "_os",
-        "os",
-        "subprocess",
-        "_subprocess",
-        "pty",
-        "system",
-        "popen",
-        "spawn",
-        "shutil",
-        "sys",
-        "pathlib",
-        "io",
-        "socket",
-        "compile",
-        "eval",
-        "exec",
-        "multiprocessing",
-    )
-
     if isinstance(expression, ast.Import):
         for alias in expression.names:
-            if check_module_authorized(alias.name, authorized_imports, dangerous_patterns):
+            if check_module_authorized(alias.name, authorized_imports):
                 raw_module = import_module(alias.name)
-                state[alias.asname or alias.name] = get_safe_module(raw_module, dangerous_patterns, authorized_imports)
+                state[alias.asname or alias.name] = get_safe_module(raw_module, authorized_imports)
             else:
                 raise InterpreterError(
                     f"Import of {alias.name} is not allowed. Authorized imports are: {str(authorized_imports)}"
                 )
         return None
     elif isinstance(expression, ast.ImportFrom):
-        if check_module_authorized(expression.module, authorized_imports, dangerous_patterns):
+        if check_module_authorized(expression.module, authorized_imports):
             raw_module = __import__(expression.module, fromlist=[alias.name for alias in expression.names])
-            module = get_safe_module(raw_module, dangerous_patterns, authorized_imports)
+            module = get_safe_module(raw_module, authorized_imports)
             if expression.names[0].name == "*":  # Handle "from module import *"
                 if hasattr(module, "__all__"):  # If module has __all__, import only those names
                     for name in module.__all__:


Test patch:
diff --git a/tests/test_local_python_executor.py b/tests/test_local_python_executor.py
index f7ecc91..7777631 100644
--- a/tests/test_local_python_executor.py
+++ b/tests/test_local_python_executor.py
@@ -1302,7 +1302,7 @@ def test_get_safe_module_handle_lazy_imports():
             return super().__dir__() + ["lazy_attribute"]
 
     fake_module = FakeModule("fake_module")
-    safe_module = get_safe_module(fake_module, dangerous_patterns=[], authorized_imports=set())
+    safe_module = get_safe_module(fake_module, authorized_imports=set())
     assert not hasattr(safe_module, "lazy_attribute")
     assert getattr(safe_module, "non_lazy_attribute") == "ok"
 
@@ -1377,23 +1377,4 @@ class TestPrintContainer:
     ],
 )
 def test_check_module_authorized(module: str, authorized_imports: list[str], expected: bool):
-    dangerous_patterns = (
-        "_os",
-        "os",
-        "subprocess",
-        "_subprocess",
-        "pty",
-        "system",
-        "popen",
-        "spawn",
-        "shutil",
-        "sys",
-        "pathlib",
-        "io",
-        "socket",
-        "compile",
-        "eval",
-        "exec",
-        "multiprocessing",
-    )
-    assert check_module_authorized(module, authorized_imports, dangerous_patterns) == expected
+    assert check_module_authorized(module, authorized_imports) == expected