Pass tests
This commit is contained in:
parent
c880f2f5b6
commit
d5a036d3f2
|
@ -25,10 +25,10 @@ limitations under the License.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 align="center">
|
<h3 align="center">
|
||||||
<p>🤗 Smolagents - a smol library to build great agents!</p>
|
<p>🤗 `smolagents` - a smol library to build great agents!</p>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
Smolagents is a library that enables you to run powerful agents in a few lines of code. It offers:
|
`smolagents` is a library that enables you to run powerful agents in a few lines of code. It offers:
|
||||||
|
|
||||||
✨ **Simplicity**: the logic for agents fits in ~thousand lines of code. We kept abstractions to their minimal shape above raw code!
|
✨ **Simplicity**: the logic for agents fits in ~thousand lines of code. We kept abstractions to their minimal shape above raw code!
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ https://github.com/user-attachments/assets/cd0226e2-7479-4102-aea0-57c22ca47884
|
||||||
## Code agents?
|
## Code agents?
|
||||||
|
|
||||||
We built agents where the LLM engine writes its actions in code. This approach is demonstrated to work better than the current industry practice of letting the LLM output a dictionary of the tools it wants to calls: [uses 30% fewer steps](https://huggingface.co/papers/2402.01030) (thus 30% fewer LLM calls)
|
We built agents where the LLM engine writes its actions in code. This approach is demonstrated to work better than the current industry practice of letting the LLM output a dictionary of the tools it wants to calls: [uses 30% fewer steps](https://huggingface.co/papers/2402.01030) (thus 30% fewer LLM calls)
|
||||||
and [reaches higher performance on difficult benchmarks](https://huggingface.co/papers/2411.01747). Head to [./conceptual_guides/intro_agents.md] to learn more on that.
|
and [reaches higher performance on difficult benchmarks](https://huggingface.co/papers/2411.01747). Head to [https://huggingface.co/docs/smolagents/conceptual_guides/intro_agents] to learn more on that.
|
||||||
|
|
||||||
Especially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:
|
Especially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:
|
||||||
- a secure python interpreter to run code more safely in your environment
|
- a secure python interpreter to run code more safely in your environment
|
||||||
|
@ -76,7 +76,7 @@ If you use `smolagents` in your publication, please cite it by using the followi
|
||||||
|
|
||||||
```bibtex
|
```bibtex
|
||||||
@Misc{accelerate,
|
@Misc{accelerate,
|
||||||
title = {Smolagents: The easiest way to build efficient agentic systems.},
|
title = {`smolagents`: The easiest way to build efficient agentic systems.},
|
||||||
author = {Aymeric Roucher and Thomas Wolf and Leandro von Werra and Erik Kaunismäki},
|
author = {Aymeric Roucher and Thomas Wolf and Leandro von Werra and Erik Kaunismäki},
|
||||||
howpublished = {\url{https://github.com/huggingface/smolagents}},
|
howpublished = {\url{https://github.com/huggingface/smolagents}},
|
||||||
year = {2024}
|
year = {2024}
|
||||||
|
|
|
@ -78,7 +78,7 @@ Actually, most real-life tasks do not fit in a pre-determined workflow. This is
|
||||||
|
|
||||||
Agentic systems are a great way to introduce the vast world of real-world tasks to programs!
|
Agentic systems are a great way to introduce the vast world of real-world tasks to programs!
|
||||||
|
|
||||||
### Why Smolagents?
|
### Why `smolagents`?
|
||||||
|
|
||||||
For some low-level agentic use cases, like chains or routers, you can write all the code yourself. You'll be much better that way, since it will let you control and understand your system better.
|
For some low-level agentic use cases, like chains or routers, you can write all the code yourself. You'll be much better that way, since it will let you control and understand your system better.
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,11 @@ Run the line below to install required dependencies:
|
||||||
```bash
|
```bash
|
||||||
!pip install smolagents pandas langchain langchain-community sentence-transformers faiss-cpu --upgrade -q
|
!pip install smolagents pandas langchain langchain-community sentence-transformers faiss-cpu --upgrade -q
|
||||||
```
|
```
|
||||||
Let's login in order to call the HF Inference API:
|
To call the HF Inference API, you will need a valid token as your environment variable `HF_TOKEN`.
|
||||||
|
We use python-dotenv to load it.
|
||||||
```py
|
```py
|
||||||
from huggingface_hub import login
|
from python_dotenv import load_dotenv
|
||||||
|
load_dotenv()
|
||||||
login()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
We first load a knowledge base on which we want to perform RAG: this dataset is a compilation of the documentation pages for many Hugging Face libraries, stored as markdown. We will keep only the documentation for the `transformers` library.
|
We first load a knowledge base on which we want to perform RAG: this dataset is a compilation of the documentation pages for many Hugging Face libraries, stored as markdown. We will keep only the documentation for the `transformers` library.
|
||||||
|
|
|
@ -13,7 +13,7 @@ specific language governing permissions and limitations under the License.
|
||||||
rendered properly in your Markdown viewer.
|
rendered properly in your Markdown viewer.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
# Smolagents
|
# `smolagents`
|
||||||
|
|
||||||
This library is the simplest framework out there to build powerful agents! By the way, wtf are "agents"? We provide our definition [in this page](conceptual_guides/intro_agents), whe're you'll also find tips for when to use them or not (spoilers: you'll often be better off without agents).
|
This library is the simplest framework out there to build powerful agents! By the way, wtf are "agents"? We provide our definition [in this page](conceptual_guides/intro_agents), whe're you'll also find tips for when to use them or not (spoilers: you'll often be better off without agents).
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
|
||||||
[project]
|
[project]
|
||||||
name = "smolagents"
|
name = "smolagents"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
description = "🤗 Smolagents: a barebones library for agents. Agents just write python code to call/orchestrate tools."
|
description = "🤗 `smolagents`: a barebones library for agents. Agents just write python code to call/orchestrate tools."
|
||||||
authors = [
|
authors = [
|
||||||
{ name="Aymeric Roucher", email="aymeric@hf.co" }, { name="Thomas Wolf"},
|
{ name="Aymeric Roucher", email="aymeric@hf.co" }, { name="Thomas Wolf"},
|
||||||
]
|
]
|
||||||
|
|
|
@ -184,7 +184,7 @@ class AgentTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
output = agent.run("What is 2 multiplied by 3.6452?", single_step=True)
|
output = agent.run("What is 2 multiplied by 3.6452?", single_step=True)
|
||||||
assert isinstance(output, str)
|
assert isinstance(output, str)
|
||||||
assert output == "7.2904"
|
assert "7.2904" in output
|
||||||
|
|
||||||
def test_fake_toolcalling_agent(self):
|
def test_fake_toolcalling_agent(self):
|
||||||
agent = ToolCallingAgent(
|
agent = ToolCallingAgent(
|
||||||
|
@ -192,9 +192,9 @@ class AgentTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
output = agent.run("What is 2 multiplied by 3.6452?")
|
output = agent.run("What is 2 multiplied by 3.6452?")
|
||||||
assert isinstance(output, str)
|
assert isinstance(output, str)
|
||||||
assert output == "7.2904"
|
assert "7.2904" in output
|
||||||
assert agent.logs[1].task == "What is 2 multiplied by 3.6452?"
|
assert agent.logs[1].task == "What is 2 multiplied by 3.6452?"
|
||||||
assert agent.logs[2].observations == "7.2904"
|
assert "7.2904" in agent.logs[2].observations
|
||||||
assert agent.logs[3].llm_output is None
|
assert agent.logs[3].llm_output is None
|
||||||
|
|
||||||
def test_toolcalling_agent_handles_image_tool_outputs(self):
|
def test_toolcalling_agent_handles_image_tool_outputs(self):
|
||||||
|
@ -229,7 +229,8 @@ class AgentTests(unittest.TestCase):
|
||||||
def test_additional_args_added_to_task(self):
|
def test_additional_args_added_to_task(self):
|
||||||
agent = CodeAgent(tools=[], model=fake_code_model)
|
agent = CodeAgent(tools=[], model=fake_code_model)
|
||||||
agent.run(
|
agent.run(
|
||||||
"What is 2 multiplied by 3.6452?", additional_instruction="Remember this."
|
"What is 2 multiplied by 3.6452?",
|
||||||
|
additional_args={"instruction": "Remember this."},
|
||||||
)
|
)
|
||||||
assert "Remember this" in agent.task
|
assert "Remember this" in agent.task
|
||||||
assert "Remember this" in str(agent.input_messages)
|
assert "Remember this" in str(agent.input_messages)
|
||||||
|
|
Loading…
Reference in New Issue