You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is this not possible with the current options.
Current get_source function of smolagents, can fetch the source of function tools that are not prefixed by underscore but fails with classes.
The reason is the following:
1)If obj is a Class, inspect.getsource(obj) will raise an error
2) If obj is a function, inspect.getsource(obj) will return the source code
3) If obj is a Class, in marimo inspect.getfile(obj) will return the path of the file
4) If obj is a function, in marimo inspect.getfile(obj) will return a non-useful path
5) If obj is local to cell (_ prefixed) obj.__name__ will return _cell_{cell_id}{obj orig name} so if obj is a function, the smolagents to_dict function
(https://github.com/huggingface/smolagents/blob/main/src/smolagents/tools.py#L243)
attempts to replace the function name with forward in the source code, but fails because it can't
find the prefixed name pattern. As a result, the uploaded tool lacks a forward function
and will fail when executed on the server.
Is your feature request related to a problem? Please describe.
In marimo notebooks (https://marimo.io/) the
push_to_hub
function fails becauseget_source
functioncan not fetch the source.
Describe the solution you'd like
I have already written a patch https://github.com/kazemihabib/Huggingface-Agents-Course-Marimo-Edition/blob/marimo/patches/smolagents_patches.py that fixes this problem.
Is this not possible with the current options.
Current
get_source
function of smolagents, can fetch the source of function tools that are not prefixed by underscore but fails with classes.The reason is the following:
1)If obj is a Class,
inspect.getsource(obj)
will raise an error2) If obj is a function,
inspect.getsource(obj)
will return the source code3) If obj is a Class, in marimo
inspect.getfile(obj)
will return the path of the file4) If obj is a function, in marimo
inspect.getfile(obj)
will return a non-useful path5) If obj is local to cell (_ prefixed)
obj.__name__
will return_cell_{cell_id}{obj orig name}
so if obj is a function, the smolagentsto_dict
function(https://github.com/huggingface/smolagents/blob/main/src/smolagents/tools.py#L243)
attempts to replace the function name with
forward
in the source code, but fails because it can'tfind the prefixed name pattern. As a result, the uploaded tool lacks a
forward
functionand will fail when executed on the server.
Additional context
My patch fixes this problem (https://github.com/kazemihabib/Huggingface-Agents-Course-Marimo-Edition/blob/marimo/patches/smolagents_patches.py)
To fetch source I am doing the following:
because of the way I am fetching the source, writing tests for that is not easy, so I have not created a PR for this issue yet.
The text was updated successfully, but these errors were encountered: