Reverted to last
Browse files- tools/linkedin_job_search.py +11 -9
tools/linkedin_job_search.py
CHANGED
@@ -13,13 +13,13 @@ class LinkedInJobSearchTool(Tool):
|
|
13 |
"work_mode": {"type": "string", "description": "remote, hybrid, in-office"}
|
14 |
}
|
15 |
|
16 |
-
output_type = "array" # ✅ "array"
|
17 |
|
18 |
def forward(self, position: str, location: str, work_mode: str) -> List[str]:
|
19 |
"""
|
20 |
-
|
21 |
"""
|
22 |
-
SERPAPI_KEY = "
|
23 |
base_url = "https://serpapi.com/search"
|
24 |
|
25 |
params = {
|
@@ -30,12 +30,14 @@ class LinkedInJobSearchTool(Tool):
|
|
30 |
"api_key": SERPAPI_KEY
|
31 |
}
|
32 |
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
if response.status_code == 200:
|
36 |
data = response.json()
|
37 |
job_results = data.get("jobs_results", [])
|
38 |
|
|
|
39 |
formatted_jobs = [
|
40 |
f"Title: {job['title']}, Company: {job.get('company_name', 'N/A')}, "
|
41 |
f"Location: {job.get('location', 'N/A')}, Posted: {job.get('detected_extensions', {}).get('posted_at', 'N/A')}, "
|
@@ -43,7 +45,7 @@ class LinkedInJobSearchTool(Tool):
|
|
43 |
for job in job_results
|
44 |
]
|
45 |
|
46 |
-
return formatted_jobs
|
47 |
-
|
48 |
-
|
49 |
-
return [f"Error
|
|
|
13 |
"work_mode": {"type": "string", "description": "remote, hybrid, in-office"}
|
14 |
}
|
15 |
|
16 |
+
output_type = "array" # ✅ Use "array" to return a list
|
17 |
|
18 |
def forward(self, position: str, location: str, work_mode: str) -> List[str]:
|
19 |
"""
|
20 |
+
Fetches job listings from LinkedIn using SerpAPI.
|
21 |
"""
|
22 |
+
SERPAPI_KEY = "YOUR_SERPAPI_KEY" # 🔹 Replace with your actual API key
|
23 |
base_url = "https://serpapi.com/search"
|
24 |
|
25 |
params = {
|
|
|
30 |
"api_key": SERPAPI_KEY
|
31 |
}
|
32 |
|
33 |
+
try:
|
34 |
+
response = requests.get(base_url, params=params)
|
35 |
+
response.raise_for_status() # ✅ Handle HTTP errors
|
36 |
|
|
|
37 |
data = response.json()
|
38 |
job_results = data.get("jobs_results", [])
|
39 |
|
40 |
+
# Convert job results to a list of formatted strings
|
41 |
formatted_jobs = [
|
42 |
f"Title: {job['title']}, Company: {job.get('company_name', 'N/A')}, "
|
43 |
f"Location: {job.get('location', 'N/A')}, Posted: {job.get('detected_extensions', {}).get('posted_at', 'N/A')}, "
|
|
|
45 |
for job in job_results
|
46 |
]
|
47 |
|
48 |
+
return formatted_jobs if formatted_jobs else ["No jobs found. Try different keywords."]
|
49 |
+
|
50 |
+
except requests.exceptions.RequestException as e:
|
51 |
+
return [f"Error fetching job listings: {str(e)}"]
|