Skip to content

Commit 1f8fd72

Browse files
authored
Clean makefile, pyproject.toml and CI (#229)
* Clean makefile / pyproject.toml / .github * new tests after * add back sqlalchemy * disable docs tests in CI * continue on error * correct continue on error * Remove all_docs test
1 parent fabc59a commit 1f8fd72

15 files changed

+203
-113
lines changed

.github/workflows/quality.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@ jobs:
1616
python-version: "3.12"
1717

1818
# Setup venv
19-
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
2019
- name: Setup venv + uv
2120
run: |
2221
pip install --upgrade uv
2322
uv venv
2423
2524
- name: Install dependencies
26-
run: uv pip install "smolagents[test] @ ."
27-
- run: uv run ruff check tests src # linter
28-
- run: uv run ruff format --check tests src # formatter
25+
run: uv pip install "smolagents[quality] @ ."
2926

30-
# Run type checking at least on smolagents root file to check all modules
31-
# that can be lazy-loaded actually exist.
32-
# - run: uv run mypy src/smolagents/__init__.py --follow-imports=silent --show-traceback
33-
34-
# Run mypy on full package
35-
# - run: uv run mypy src
27+
# Equivalent of "make quality" but step by step
28+
- run: uv run ruff check examples src tests utils # linter
29+
- run: uv run ruff format --check examples src tests utils # formatter
30+
- run: uv run python utils/check_tests_in_ci.py

.github/workflows/tests.yml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ jobs:
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222

23-
2423
# Setup venv
25-
# TODO: revisit when https://github.com/astral-sh/uv/issues/1526 is addressed.
2624
- name: Setup venv + uv
2725
run: |
2826
pip install --upgrade uv
@@ -33,33 +31,59 @@ jobs:
3331
run: |
3432
uv pip install "smolagents[test] @ ."
3533
34+
# Run all tests separately for individual feedback
35+
# Use 'if success() || failure()' so that all tests are run even if one failed
36+
# See https://stackoverflow.com/a/62112985
3637
- name: Agent tests
3738
run: |
38-
uv run pytest -sv ./tests/test_agents.py
39+
uv run pytest ./tests/test_agents.py
40+
if: ${{ success() || failure() }}
41+
3942
- name: Default tools tests
4043
run: |
41-
uv run pytest -sv ./tests/test_default_tools.py
44+
uv run pytest ./tests/test_default_tools.py
45+
if: ${{ success() || failure() }}
46+
47+
# - name: Docs tests # Disabled for now (slow test + requires API keys)
48+
# run: |
49+
# uv run pytest ./tests/test_all_docs.py
50+
4251
- name: Final answer tests
4352
run: |
44-
uv run pytest -sv ./tests/test_final_answer.py
53+
uv run pytest ./tests/test_final_answer.py
54+
if: ${{ success() || failure() }}
55+
4556
- name: Models tests
4657
run: |
47-
uv run pytest -sv ./tests/test_models.py
58+
uv run pytest ./tests/test_models.py
59+
if: ${{ success() || failure() }}
60+
4861
- name: Monitoring tests
4962
run: |
50-
uv run pytest -sv ./tests/test_monitoring.py
63+
uv run pytest ./tests/test_monitoring.py
64+
if: ${{ success() || failure() }}
65+
5166
- name: Python interpreter tests
5267
run: |
53-
uv run pytest -sv ./tests/test_python_interpreter.py
68+
uv run pytest ./tests/test_python_interpreter.py
69+
if: ${{ success() || failure() }}
70+
5471
- name: Search tests
5572
run: |
56-
uv run pytest -sv ./tests/test_search.py
73+
uv run pytest ./tests/test_search.py
74+
if: ${{ success() || failure() }}
75+
5776
- name: Tools tests
5877
run: |
59-
uv run pytest -sv ./tests/test_tools.py
78+
uv run pytest ./tests/test_tools.py
79+
if: ${{ success() || failure() }}
80+
6081
- name: Types tests
6182
run: |
62-
uv run pytest -sv ./tests/test_types.py
83+
uv run pytest ./tests/test_types.py
84+
if: ${{ success() || failure() }}
85+
6386
- name: Utils tests
6487
run: |
65-
uv run pytest -sv ./tests/test_utils.py
88+
uv run pytest ./tests/test_utils.py
89+
if: ${{ success() || failure() }}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ happy to make the changes or help you make a contribution if you're interested!
9191

9292
## I want to become a maintainer of the project. How do I get there?
9393

94-
smolagents is a project led and managed by Hugging Face. We are more than
94+
smolagents is a project led and managed by Hugging Face. We are more than
9595
happy to have motivated individuals from other organizations join us as maintainers with the goal of helping smolagents
9696
make a dent in the world of Agents.
9797

Makefile

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,18 @@
11
.PHONY: quality style test docs utils
22

3-
check_dirs := .
3+
check_dirs := examples src tests utils
44

5-
# Check that source code meets quality standards
6-
7-
extra_quality_checks:
8-
python utils/check_copies.py
9-
python utils/check_dummies.py
10-
python utils/check_repo.py
11-
doc-builder style smolagents docs/source --max_len 119
12-
13-
# this target runs checks on all files
5+
# Check code quality of the source code
146
quality:
157
ruff check $(check_dirs)
168
ruff format --check $(check_dirs)
17-
doc-builder style smolagents docs/source --max_len 119 --check_only
9+
python utils/check_tests_in_ci.py
1810

19-
# Format source code automatically and check is there are any problems left that need manual fixing
11+
# Format source code automatically
2012
style:
2113
ruff check $(check_dirs) --fix
2214
ruff format $(check_dirs)
23-
doc-builder style smolagents docs/source --max_len 119
2415

25-
# Run tests for the library
26-
test_big_modeling:
27-
python -m pytest -s -v ./tests/test_big_modeling.py ./tests/test_modeling_utils.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_big_modeling.log",)
28-
29-
test_core:
30-
python -m pytest -s -v ./tests/ --ignore=./tests/test_examples.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_core.log",)
31-
32-
test_cli:
33-
python -m pytest -s -v ./tests/test_cli.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_cli.log",)
34-
35-
36-
# Since the new version of pytest will *change* how things are collected, we need `deepspeed` to
37-
# run after test_core and test_cli
16+
# Run smolagents tests
3817
test:
39-
$(MAKE) test_core
40-
$(MAKE) test_cli
41-
$(MAKE) test_big_modeling
42-
$(MAKE) test_deepspeed
43-
$(MAKE) test_fsdp
44-
45-
test_examples:
46-
python -m pytest -s -v ./tests/test_examples.py $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_examples.log",)
47-
48-
# Same as test but used to install only the base dependencies
49-
test_prod:
50-
$(MAKE) test_core
51-
52-
test_rest:
53-
python -m pytest -s -v ./tests/test_examples.py::FeatureExamplesTests $(if $(IS_GITHUB_CI),--report-log "$(PYTORCH_VERSION)_rest.log",)
18+
pytest ./tests/

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,27 @@ To contribute, follow our [contribution guide](https://github.com/huggingface/sm
9898
At any moment, feel welcome to open an issue, citing your exact error traces and package versions if it's a bug.
9999
It's often even better to open a PR with your proposed fixes/changes!
100100

101+
To install dev dependencies, run:
102+
```
103+
pip install -e ".[dev]"
104+
```
105+
106+
When making changes to the codebase, please check that it follows the repo's code quality requirements by running:
107+
To check code quality of the source code:
108+
```
109+
make quality
110+
```
111+
112+
If the checks fail, you can run the formatter with:
113+
```
114+
make style
115+
```
116+
117+
And commit the changes.
118+
101119
To run tests locally, run this command:
102120
```bash
103-
pytest -sv .
121+
pytest .
104122
```
105123

106124
## Citing smolagents

examples/benchmark.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@
254254
" if is_vanilla_llm:\n",
255255
" llm = agent\n",
256256
" answer = str(llm([{\"role\": \"user\", \"content\": question}]).content)\n",
257-
" token_count = {\"input\": llm.last_input_token_count, \"output\": llm.last_output_token_count}\n",
257+
" token_count = {\n",
258+
" \"input\": llm.last_input_token_count,\n",
259+
" \"output\": llm.last_output_token_count,\n",
260+
" }\n",
258261
" intermediate_steps = str([])\n",
259262
" else:\n",
260263
" answer = str(agent.run(question))\n",
@@ -983,7 +986,7 @@
983986
},
984987
{
985988
"cell_type": "code",
986-
"execution_count": 12,
989+
"execution_count": null,
987990
"metadata": {},
988991
"outputs": [
989992
{
@@ -1043,8 +1046,8 @@
10431046
"\n",
10441047
"\n",
10451048
"# Usage (after running your previous data processing code):\n",
1046-
"mathjax_table = create_mathjax_table(pivot_df, formatted_df)\n",
1047-
"print(mathjax_table)"
1049+
"# mathjax_table = create_mathjax_table(pivot_df, formatted_df)\n",
1050+
"# print(mathjax_table)"
10481051
]
10491052
}
10501053
],

examples/e2b_example.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
load_dotenv()
66

7+
78
class GetCatImageTool(Tool):
8-
name="get_cat_image"
9+
name = "get_cat_image"
910
description = "Get a cat image"
1011
inputs = {}
1112
output_type = "image"
@@ -27,17 +28,22 @@ def forward(self):
2728
get_cat_image = GetCatImageTool()
2829

2930
agent = CodeAgent(
30-
tools = [get_cat_image, VisitWebpageTool()],
31+
tools=[get_cat_image, VisitWebpageTool()],
3132
model=HfApiModel(),
32-
additional_authorized_imports=["Pillow", "requests", "markdownify"], # "duckduckgo-search",
33-
use_e2b_executor=True
33+
additional_authorized_imports=[
34+
"Pillow",
35+
"requests",
36+
"markdownify",
37+
], # "duckduckgo-search",
38+
use_e2b_executor=True,
3439
)
3540

3641
agent.run(
37-
"Return me an image of a cat. Directly use the image provided in your state.", additional_args={"cat_image":get_cat_image()}
38-
) # Asking to directly return the image from state tests that additional_args are properly sent to server.
42+
"Return me an image of a cat. Directly use the image provided in your state.",
43+
additional_args={"cat_image": get_cat_image()},
44+
) # Asking to directly return the image from state tests that additional_args are properly sent to server.
3945

4046
# Try the agent in a Gradio UI
4147
from smolagents import GradioUI
4248

43-
GradioUI(agent).launch()
49+
GradioUI(agent).launch()

examples/gradio_upload.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
from smolagents import (
2-
CodeAgent,
3-
HfApiModel,
4-
GradioUI
5-
)
1+
from smolagents import CodeAgent, HfApiModel, GradioUI
62

7-
agent = CodeAgent(
8-
tools=[], model=HfApiModel(), max_steps=4, verbosity_level=1
9-
)
3+
agent = CodeAgent(tools=[], model=HfApiModel(), max_steps=4, verbosity_level=1)
104

11-
GradioUI(agent, file_upload_folder='./data').launch()
5+
GradioUI(agent, file_upload_folder="./data").launch()

examples/inspect_runs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# Let's setup the instrumentation first
1717

1818
trace_provider = TracerProvider()
19-
trace_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter("http://0.0.0.0:6006/v1/traces")))
19+
trace_provider.add_span_processor(
20+
SimpleSpanProcessor(OTLPSpanExporter("http://0.0.0.0:6006/v1/traces"))
21+
)
2022

2123
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider, skip_dep_check=True)
2224

examples/rag.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99

1010
knowledge_base = datasets.load_dataset("m-ric/huggingface_doc", split="train")
11-
knowledge_base = knowledge_base.filter(lambda row: row["source"].startswith("huggingface/transformers"))
11+
knowledge_base = knowledge_base.filter(
12+
lambda row: row["source"].startswith("huggingface/transformers")
13+
)
1214

1315
source_docs = [
1416
Document(page_content=doc["text"], metadata={"source": doc["source"].split("/")[1]})
@@ -26,6 +28,7 @@
2628

2729
from smolagents import Tool
2830

31+
2932
class RetrieverTool(Tool):
3033
name = "retriever"
3134
description = "Uses semantic search to retrieve the parts of transformers documentation that could be most relevant to answer your query."
@@ -39,9 +42,7 @@ class RetrieverTool(Tool):
3942

4043
def __init__(self, docs, **kwargs):
4144
super().__init__(**kwargs)
42-
self.retriever = BM25Retriever.from_documents(
43-
docs, k=10
44-
)
45+
self.retriever = BM25Retriever.from_documents(docs, k=10)
4546

4647
def forward(self, query: str) -> str:
4748
assert isinstance(query, str), "Your search query must be a string"
@@ -56,14 +57,20 @@ def forward(self, query: str) -> str:
5657
]
5758
)
5859

60+
5961
from smolagents import HfApiModel, CodeAgent
6062

6163
retriever_tool = RetrieverTool(docs_processed)
6264
agent = CodeAgent(
63-
tools=[retriever_tool], model=HfApiModel("meta-llama/Llama-3.3-70B-Instruct"), max_steps=4, verbosity_level=2
65+
tools=[retriever_tool],
66+
model=HfApiModel("meta-llama/Llama-3.3-70B-Instruct"),
67+
max_steps=4,
68+
verbosity_level=2,
6469
)
6570

66-
agent_output = agent.run("For a transformers model training, which is slower, the forward or the backward pass?")
71+
agent_output = agent.run(
72+
"For a transformers model training, which is slower, the forward or the backward pass?"
73+
)
6774

6875
print("Final output:")
6976
print(agent_output)

0 commit comments

Comments
 (0)