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.2.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.2-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.2.tar.gz.

File metadata

File hashes

Hashes for datapizza_ai_tools_web_fetch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 547ebea319800d5f04bf2c3f44e79684e094b8ab35887d6d87a18fe2c764e5f3
MD5 ee7c8d57a0232a064f9512e7b7ec11d9
BLAKE2b-256 2a88c004fd65cb1bf597b22f0f096c17f67f7f56883e24737aaf7d1d54a0c84b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datapizza_ai_tools_web_fetch-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b47138f9354318099021dfae57f0f7ff8f62bfde99e18b7c48e9da2e4c95c5c
MD5 95c15bbf787e0c2a218f65b97d846291
BLAKE2b-256 29d45b1a5bd7bc15e0bbb31c793153829bbbc5aa3fb302f9a34d98386e6ecb12

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