Spaces:
Runtime error
Runtime error
+web_downloader_tool
Browse files
helper.py
CHANGED
|
@@ -91,4 +91,31 @@ def get_travily_api_search_tool(tavily_api_key: str) -> Tool:
|
|
| 91 |
search results including titles, URLs, and snippets.
|
| 92 |
""",
|
| 93 |
func=tavily_search.run,
|
| 94 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
search results including titles, URLs, and snippets.
|
| 92 |
""",
|
| 93 |
func=tavily_search.run,
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
import requests
|
| 97 |
+
from langchain.tools import Tool
|
| 98 |
+
|
| 99 |
+
# Your web_downloader tool function
|
| 100 |
+
def download_url_content(url: str) -> str:
|
| 101 |
+
"""Downloads the content from a given URL as a string."""
|
| 102 |
+
try:
|
| 103 |
+
response = requests.get(url, timeout=10)
|
| 104 |
+
response.raise_for_status()
|
| 105 |
+
return response.text # For text files like Python code
|
| 106 |
+
# For binary files like audio, you'd handle it differently, e.g.,
|
| 107 |
+
# return response.content # if the audio transcriber accepts bytes
|
| 108 |
+
# or save to a temp file and pass path, or stream directly
|
| 109 |
+
except requests.exceptions.RequestException as e:
|
| 110 |
+
return f"Error downloading content from {url}: {e}"
|
| 111 |
+
|
| 112 |
+
# Get your web_downloader tool
|
| 113 |
+
web_downloader_tool = Tool(
|
| 114 |
+
name="web_downloader",
|
| 115 |
+
description="""
|
| 116 |
+
Downloads the content of a given URL as a string.
|
| 117 |
+
Useful for accessing information directly from web pages or online files.
|
| 118 |
+
Input should be a single, valid URL (e.g., 'https://www.example.com').
|
| 119 |
+
""",
|
| 120 |
+
func=download_url_content,
|
| 121 |
+
)
|