fixed job links format
Browse files
tools/linkedin_job_search.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from smolagents.tools import Tool
|
2 |
import requests
|
3 |
-
import json
|
4 |
from typing import List, Dict
|
5 |
|
6 |
class LinkedInJobSearchTool(Tool):
|
@@ -9,17 +8,17 @@ class LinkedInJobSearchTool(Tool):
|
|
9 |
|
10 |
inputs = {
|
11 |
"position": {"type": "string", "description": "Job title (e.g., Data Scientist)"},
|
12 |
-
"location": {"type": "string", "description": "City or country (e.g.,
|
13 |
"work_mode": {"type": "string", "description": "remote, hybrid, in-office"}
|
14 |
}
|
15 |
|
16 |
-
output_type = "array"
|
17 |
|
18 |
def forward(self, position: str, location: str, work_mode: str) -> List[Dict]:
|
19 |
"""
|
20 |
Fetches job listings from LinkedIn using SerpAPI and returns structured JSON.
|
21 |
"""
|
22 |
-
SERPAPI_KEY = "2f660e5a696e7d1d08662085b95f83a61224476ec19558de3c68218baf346e43" # Replace with
|
23 |
base_url = "https://serpapi.com/search"
|
24 |
|
25 |
params = {
|
@@ -37,14 +36,14 @@ class LinkedInJobSearchTool(Tool):
|
|
37 |
data = response.json()
|
38 |
job_results = data.get("jobs_results", [])
|
39 |
|
40 |
-
# ✅
|
41 |
return [
|
42 |
{
|
43 |
"Title": job["title"],
|
44 |
"Company": job.get("company_name", "N/A"),
|
45 |
"Location": job.get("location", "N/A"),
|
46 |
"Posted": job.get("detected_extensions", {}).get("posted_at", "N/A"),
|
47 |
-
"Link": job
|
48 |
}
|
49 |
for job in job_results
|
50 |
] if job_results else [{"Error": "No jobs found. Try different keywords."}]
|
|
|
1 |
from smolagents.tools import Tool
|
2 |
import requests
|
|
|
3 |
from typing import List, Dict
|
4 |
|
5 |
class LinkedInJobSearchTool(Tool):
|
|
|
8 |
|
9 |
inputs = {
|
10 |
"position": {"type": "string", "description": "Job title (e.g., Data Scientist)"},
|
11 |
+
"location": {"type": "string", "description": "City or country (e.g., Germany)"},
|
12 |
"work_mode": {"type": "string", "description": "remote, hybrid, in-office"}
|
13 |
}
|
14 |
|
15 |
+
output_type = "array"
|
16 |
|
17 |
def forward(self, position: str, location: str, work_mode: str) -> List[Dict]:
|
18 |
"""
|
19 |
Fetches job listings from LinkedIn using SerpAPI and returns structured JSON.
|
20 |
"""
|
21 |
+
SERPAPI_KEY = "2f660e5a696e7d1d08662085b95f83a61224476ec19558de3c68218baf346e43" # Replace with actual key
|
22 |
base_url = "https://serpapi.com/search"
|
23 |
|
24 |
params = {
|
|
|
36 |
data = response.json()
|
37 |
job_results = data.get("jobs_results", [])
|
38 |
|
39 |
+
# ✅ Properly format job URLs
|
40 |
return [
|
41 |
{
|
42 |
"Title": job["title"],
|
43 |
"Company": job.get("company_name", "N/A"),
|
44 |
"Location": job.get("location", "N/A"),
|
45 |
"Posted": job.get("detected_extensions", {}).get("posted_at", "N/A"),
|
46 |
+
"Link": f"https://www.linkedin.com/jobs/view/{job['job_id']}" if "job_id" in job else "N/A"
|
47 |
}
|
48 |
for job in job_results
|
49 |
] if job_results else [{"Error": "No jobs found. Try different keywords."}]
|