Skip to content

[BUG] TypeError when instantiating SpeechToTextTool with model argument #1461

@Martin-Labenne

Description

@Martin-Labenne

Describe the bug
When instantiating SpeechToTextTool with a model parameter (e.g. SpeechToTextTool(model="openai/whisper-small")), the class raises a TypeError because the overridden __new__ method incorrectly forwards *args and **kwargs to super().__new__(), which does not expect these arguments.

Code to reproduce the error

from smolagents.default_tools import SpeechToTextTool

speech_to_text_tool = SpeechToTextTool(model="openai/whisper-small")

Error logs (if any)
Traceback (most recent call last):
File "/path/to/project/bug_demo.py", line 3, in
speech_to_text_tool = SpeechToTextTool(model="openai/whisper-small")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/project/venv/lib/python3.12/site-packages/smolagents/default_tools.py", line 499, in new
return super().new(cls, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object.new() takes exactly one argument (the type to instantiate)

Expected behavior
The instance of SpeechToTextTool should be created successfully when passing keyword arguments like model=... or other arguments accepted in PipelineTool.__init__ method without raising a TypeError.

Packages version:
smolagents==1.17.0

Additional context

The issue can be fixed by not forwarding *args and **kwargs in __new__, i.e., changing the return line to:

return super().__new__(cls)

This allows instance initialization with parameters to proceed in __init__ without breaking instance creation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions