Fix installation with data files (#536)

This commit is contained in:
Albert Villanova del Moral 2025-02-07 13:44:42 +01:00 committed by GitHub
parent 932298696c
commit 127a042cfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 9 deletions

View File

@ -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"

View File

@ -25,7 +25,6 @@ from .local_python_executor import *
from .memory import *
from .models import *
from .monitoring import *
from .prompts import *
from .tools import *
from .utils import *
from .cli import *

View File

@ -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
@ -646,9 +646,9 @@ class ToolCallingAgent(MultiStepAgent):
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,
@ -779,9 +779,7 @@ class CodeAgent(MultiStepAgent):
):
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,

View File

@ -4,7 +4,7 @@ import subprocess
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, (