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

Exception during agent creation on Windows #572

Open
Bilokin opened this issue Feb 9, 2025 · 5 comments
Open

Exception during agent creation on Windows #572

Bilokin opened this issue Feb 9, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@Bilokin
Copy link
Contributor

Bilokin commented Feb 9, 2025

Hello,

I must confess that I use Anaconda on Windows PC to run smolagents, and version 1.7.0 was running fine, but I cannot run version 1.8.0 and higher because the following line crashes the agent creation:

importlib.resources.files("smolagents.prompts").joinpath("toolcalling_agent.yaml").read_text()

I can confirm that I can run these versions on Linux environments, but on Windows it throws the following exception:

FileNotFoundError: [Errno 2] No such file or directory: '[D:\\Documents\\anaconda3\\envs\\new_sandbox\\Lib\\site-packages\\smolagents\\code_agent.yaml](file:///D://Documents//anaconda3//envs//new_sandbox//Lib//site-packages//smolagents//code_agent.yaml)'

My version of python on Windows is 3.12.3

So, somehow, prompts is a resource on Linux and not a resource on Windows. As a private workaround I created __init__.py file in the prompts directory and it worked.

Could you please tell me where this should be fixed?
If this is a problem with importlib, then I would like to report it, because I need GitHub points really badly...

@Bilokin Bilokin added the bug Something isn't working label Feb 9, 2025
@sysradium
Copy link
Contributor

@Bilokin which python version are you using?

@Bilokin
Copy link
Contributor Author

Bilokin commented Feb 9, 2025

It is 3.12.3 on Windows, I just added that to the description

@sysradium
Copy link
Contributor

sysradium commented Feb 9, 2025

Should then work without __init__.py ...
Out of curiosity can you try replacing that with:

import os
prompt_templates = prompt_templates or yaml.safe_load(
    open(os.path.join(os.path.dirname(__file__), "prompts", "toolcalling_agent.yaml")).read()
)

and another option

import pkgutil
prompt_templates = prompt_templates or yaml.safe_load(
    pkgutil.get_data("smolagents", os.path.join("prompts", "toolcalling_agent.yaml"))
)

@Bilokin
Copy link
Contributor Author

Bilokin commented Feb 9, 2025

I tried the first option on clean reinstall and it works as well, thanks!

@sysradium
Copy link
Contributor

@Bilokin can you try the second one as well? So to figure out which way to go. Because the first one is by far not the best one. The second one is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants