-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
44 lines (35 loc) · 1.11 KB
/
tools.py
File metadata and controls
44 lines (35 loc) · 1.11 KB
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
import os
import requests
import json
from dotenv import load_dotenv
from crewai.tools import tool
from pypdf import PdfReader
load_dotenv()
# 1. Custom Stable Search Tool (Replaces SerperDevTool)
@tool("search_tool")
def search_tool(search_query: str):
"""Search the internet for real-time market news and financial data."""
url = "https://google.serper.dev/search"
payload = json.dumps({"q": search_query})
headers = {
'X-API-KEY': os.getenv("SERPER_API_KEY"),
'Content-Type': 'application/json'
}
try:
response = requests.request("POST", url, headers=headers, data=payload)
return response.text
except Exception as e:
return f"Search failed: {str(e)}"
@tool("pdf_tool")
def pdf_tool(file_path: str):
"""Reads the full text content of a financial PDF file."""
try:
reader = PdfReader(file_path)
text = ""
for page in reader.pages:
content = page.extract_text()
if content:
text += content + "\n"
return text
except Exception as e:
return f"Error reading PDF: {str(e)}"