File size: 1,907 Bytes
f1acfc4 30d98fa f1acfc4 30d98fa f1acfc4 30d98fa 4f43fb0 f1acfc4 30d98fa f1acfc4 30d98fa f1acfc4 30d98fa f1acfc4 30d98fa f1acfc4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import importlib
__all__ = ['GoogleSearchTool']
class GoogleSearchTool():
dependencies = ["googlesearch-python==1.3.0"]
inputSchema = {
"name": "GoogleSearchTool",
"description": "Provides a list of URLs from google search results based on a query string. Use the urls then to get the content of the page.",
"parameters": {
"type": "object",
"properties": {
"website": {
"type": "string",
"description": "The website domain to search in (e.g., 'stackoverflow.com').",
},
"query": {
"type": "string",
"description": "The query string to search for on the website.",
}
},
"required": ["query"],
}
}
def run(self, **kwargs):
print("Running web search")
website = kwargs.get("website")
query = kwargs.get("query")
if not query:
return {
"status": "error",
"message": "Missing required parameters: 'query'",
"output": None
}
search_query = query
if website:
search_query = f"site:{website} {query}"
results = []
googlesearch = importlib.import_module("googlesearch")
try:
for result in googlesearch.search(search_query, num_results=10):
if "/search?num=" not in result:
results.append(result)
return {
"status": "success",
"message": "Search completed successfully",
"output": results,
}
except Exception as e:
return {
"status": "error",
"message": f"Search failed: {str(e)}",
"output": None,
}
|