Skip to main content

A tool for fetching web content in the Datapizza AI framework.

Project description

Datapizza AI Logo

Datapizza AI - Web Fetch Tool

A tool for Datapizza AI that allows agents to fetch and process content from web pages.

License: MIT Python 3.10+


This tool provides a simple and effective way for datapizza-ai agents to access information from the internet. Agents equipped with this tool can be instructed to fetch the content of a URL, which they can then use for summarization, data extraction, or to answer questions.

⚙️ How it Works

The WebFetchTool is a callable class that, once instantiated, can be passed directly to an agent's tool list. The agent will invoke the tool using its registered name, web_fetch. It uses the httpx library to make a GET request to the given URL and returns the content as a string.

🚀 Quick Start

1. Installation

# Install the core framework
pip install datapizza-ai

# Install the WebFetch tool
pip install datapizza-ai-tools-web-fetch

2. Example: Creating a Web Research Agent

In this example, we'll create an agent that can summarize the content of a web page.

from datapizza.agents import Agent
from datapizza.clients.openai import OpenAIClient
from datapizza.tools.web_fetch import WebFetchTool

# 1. Initialize a client (e.g., OpenAI)
client = OpenAIClient(api_key="YOUR_API_KEY")

# 2. Initialize the WebFetchTool
web_tool = WebFetchTool()

# 3. Create an agent and provide it with the web fetch tool
agent = Agent(
    name="WebFetchAgent",
    client=client,
    system_prompt="""You are a helpful research assistant.
Your goal is to answer user questions by fetching information from web pages.

Follow these steps:
1.  Receive a user question that includes a URL.
2.  Use the `web_fetch` tool to get the content of the URL.
3.  Analyze the content and provide a concise summary or answer to the user's question.
""",
    tools=[web_tool]
)

# 4. Run the agent to answer a question
question = "Summarize the main points of the article at https://loremipsum.io/"
print(f"--- Running agent for: '{question}' ---")
response = agent.run(question)
print(f"Agent Response: {response.text}\n")

# Example with a different website
# For this example, we'll stick to example.com to ensure it runs.
question_2 = "What is the title of the page at http://example.com?"
print(f"--- Running agent for: '{question_2}' ---")
response_2 = agent.run(question_2)
print(f"Agent Response: {response_2.text}\n")

Expected Output

The output will vary depending on the live content of the URL. For https://loremipsum.io/, it might look something like this:

--- Running agent for: 'Summarize the main points of the article at https://loremipsum.io/' ---
Agent Response: The article on **loremipsum.io** provides a comprehensive overview of "Lorem Ipsum," which is a placeholder text commonly used in the graphic, print, and publishing industries. Here are the main points:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datapizza_ai_tools_web_fetch-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datapizza_ai_tools_web_fetch-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file datapizza_ai_tools_web_fetch-0.0.1.tar.gz.

File metadata

File hashes

Hashes for datapizza_ai_tools_web_fetch-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8b4c05e5c75c3c39be35031889a66c1efbf8cb719ce64f16584dc22a58f55e41
MD5 330ea5cfd75a0846e5896cc96cc5d7f3
BLAKE2b-256 feb27b245c72c7920ebc3d3f8758a1ce92adc38e5f5928af9a0e4828cced4b1f

See more details on using hashes here.

File details

Details for the file datapizza_ai_tools_web_fetch-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for datapizza_ai_tools_web_fetch-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d849abc23813b0b333f1d5b5287484096cf2780dec1021e85b915267dd145952
MD5 a5a4a0645226fda981f1df251be46161
BLAKE2b-256 9c5bd4f8a9076c857d99e5c7897edb354b664c9cc8a36406eb558206da019930

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page