Step by Step Information to Construct an AI Analysis Assistant with Hugging Face SmolAgents: Automating Net Search and Article Summarization Utilizing LLM-Powered Autonomous Brokers


Hugging Face’s SmolAgents framework offers a light-weight and environment friendly option to construct AI brokers that leverage instruments like internet search and code execution. On this tutorial, we reveal easy methods to construct an AI-powered analysis assistant that may autonomously search the net and summarize articles utilizing SmolAgents. This implementation runs seamlessly, requiring minimal setup, and showcases the facility of AI brokers in automating real-world duties equivalent to analysis, summarization, and data retrieval.

!pip set up smolagents beautifulsoup4

First, we set up smolagents beautifulsoup4, which permits AI brokers to make use of instruments like internet search and code execution, and BeautifulSoup4, a Python library for parsing HTML and extracting textual content from internet pages.

import os
from getpass import getpass


# Securely enter and retailer the Hugging Face API token
os.environ["HUGGINGFACEHUB_API_TOKEN"] = getpass("Enter your Hugging Face API token: ")

Now, we securely enter and retailer the Hugging Face API token as an atmosphere variable. It makes use of getpass() to immediate customers to enter their token with out displaying it for safety. The token is then saved in os.environ[“HUGGINGFACEHUB_API_TOKEN”], permitting authenticated entry to Hugging Face’s Inference API for working AI fashions.

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel


# Initialize the mannequin WITHOUT passing hf_token immediately
mannequin = HfApiModel()


# Outline instruments (DuckDuckGo for internet search)
instruments = [DuckDuckGoSearchTool()]


# Create the agent
agent = CodeAgent(instruments=instruments, mannequin=mannequin, additional_authorized_imports=["requests", "bs4"])

Now, we initialize an AI-powered agent utilizing the SmolAgents framework. It units up HfApiModel() to load a Hugging Face API-based language mannequin, mechanically detecting the saved API token for authentication. The agent is supplied with DuckDuckGoSearchTool() to carry out internet searches. Additionally, CodeAgent() is instantiated with software entry and approved imports, equivalent to requests for making internet requests and bs4 for parsing HTML content material.

# Instance question to the agent:
question = "Summarize the details of the Wikipedia article on Hugging Face (the corporate)."


# Run the agent with the question
consequence = agent.run(question)


print("nAgent's closing reply:n", consequence)

Lastly, we ship a question to the AI agent, asking it to summarize the details of the Wikipedia article on Hugging Face. The agent.run(question) command triggers the agent to carry out an internet search, retrieve related content material, and generate a abstract utilizing the language mannequin. Lastly, the print() operate shows the agent’s closing reply, concisely summarizing the requested matter.

Pattern Output

Following this tutorial, we have now efficiently constructed an AI-powered analysis assistant utilizing Hugging Face SmolAgents that may autonomously search the net and summarize articles. This implementation highlights the facility of AI brokers in automating analysis duties, making it simpler to retrieve and course of massive quantities of knowledge effectively. Past internet search and summarization, SmolAgents could be prolonged to numerous real-world functions, together with automated coding assistants, private activity managers, and AI-driven chatbots.


Right here is the Colab Notebook for the above undertaking. Additionally, don’t overlook to comply with us on Twitter and be part of our Telegram Channel and LinkedIn Group. Don’t Neglect to hitch our 80k+ ML SubReddit.

🚨 Really useful Learn- LG AI Analysis Releases NEXUS: An Superior System Integrating Agent AI System and Knowledge Compliance Requirements to Handle Authorized Issues in AI Datasets


Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is dedicated to harnessing the potential of Synthetic Intelligence for social good. His most up-to-date endeavor is the launch of an Synthetic Intelligence Media Platform, Marktechpost, which stands out for its in-depth protection of machine studying and deep studying information that’s each technically sound and simply comprehensible by a large viewers. The platform boasts of over 2 million month-to-month views, illustrating its reputation amongst audiences.

Leave a Reply

Your email address will not be published. Required fields are marked *