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

Support push_to_hub in marimo notebooks #980

Open
kazemihabib opened this issue Mar 14, 2025 · 0 comments
Open

Support push_to_hub in marimo notebooks #980

kazemihabib opened this issue Mar 14, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@kazemihabib
Copy link

kazemihabib commented Mar 14, 2025

Is your feature request related to a problem? Please describe.
In marimo notebooks (https://marimo.io/) the push_to_hub function fails because get_source function
can 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 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.

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:

file_path = inspect.getabsfile(obj)
app = marimo._ast.codegen.get_app(file_path)
app._maybe_initialize()
all_cells = "\n".join([app._graph.cells[cell_id].code for cell_id in app._execution_order]).strip()

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.

@kazemihabib kazemihabib added the enhancement New feature or request label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant