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

Fix installation with data files #536

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ lint.select = ["E", "F", "I", "W"]
known-first-party = ["smolagents"]
lines-after-imports = 2

[tool.setuptools.package-data]
"smolagents.prompts" = ["*.yaml"]

[project.scripts]
smolagent = "smolagents.cli:main"
webagent = "smolagents.vision_web_browser:main"
1 change: 0 additions & 1 deletion src/smolagents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from .memory import *
from .models import *
from .monitoring import *
from .prompts import *
from .tools import *
from .utils import *
from .cli import *
12 changes: 5 additions & 7 deletions src/smolagents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib.resources
import inspect
import os
import re
import textwrap
import time
Expand Down Expand Up @@ -646,9 +646,9 @@ def __init__(
planning_interval: Optional[int] = None,
**kwargs,
):
yaml_path = os.path.join(os.path.dirname(__file__), "prompts", "toolcalling_agent.yaml")
with open(yaml_path, "r") as f:
self.prompt_templates = yaml.safe_load(f)
self.prompt_templates = yaml.safe_load(
importlib.resources.read_text("smolagents.prompts", "toolcalling_agent.yaml")
)
super().__init__(
tools=tools,
model=model,
Expand Down Expand Up @@ -779,9 +779,7 @@ def __init__(
):
self.additional_authorized_imports = additional_authorized_imports if additional_authorized_imports else []
self.authorized_imports = list(set(BASE_BUILTIN_MODULES) | set(self.additional_authorized_imports))
yaml_path = os.path.join(os.path.dirname(__file__), "prompts", "code_agent.yaml")
with open(yaml_path, "r") as f:
self.prompt_templates = yaml.safe_load(f)
self.prompt_templates = yaml.safe_load(importlib.resources.read_text("smolagents.prompts", "code_agent.yaml"))
super().__init__(
tools=tools,
model=model,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def test_import_smolagents_without_extras():
# Run the import statement in an isolated virtual environment
result = subprocess.run(
["uv", "run", "--isolated", "-"], input="import smolagents", text=True, capture_output=True
["uv", "run", "--isolated", "--no-editable", "-"], input="import smolagents", text=True, capture_output=True
)
# Check if the import was successful
assert result.returncode == 0, (
Expand Down