A tool for fetching web content in the Datapizza AI framework.
Project description
Datapizza AI - Web Fetch Tool
A tool for Datapizza AI that allows agents to fetch and process content from web pages.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datapizza_ai_tools_web_fetch-0.0.3.tar.gz.
File metadata
- Download URL: datapizza_ai_tools_web_fetch-0.0.3.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18bb81d0a0c91e344e5cb4b48a46f6a95fa045d55e7fa6581568b28cde4de490
|
|
| MD5 |
111185aac21240c5e367cb88694cd841
|
|
| BLAKE2b-256 |
dfe21daf9d77fdd072aa0d7d1daa606f0a067d371b3e6e4c8b2b027d4c31a185
|
File details
Details for the file datapizza_ai_tools_web_fetch-0.0.3-py3-none-any.whl.
File metadata
- Download URL: datapizza_ai_tools_web_fetch-0.0.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e00170918a1e775e9991e0bd62d35e141738646f189fe575da468925a274f828
|
|
| MD5 |
9dafd001fc6f3d03021bcf6d1c1c1b64
|
|
| BLAKE2b-256 |
1003c9c0d3c1ccdb17883eb8e352dcfd94a2e01196847988cdd5fad7f4032d02
|