preslaff commited on
Commit
3d5e9b3
·
unverified ·
1 Parent(s): 689f7f1

Reverted to last

Browse files
Files changed (1) hide show
  1. 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" is an authorized type
17
 
18
  def forward(self, position: str, location: str, work_mode: str) -> List[str]:
19
  """
20
- Searches LinkedIn for job postings using SerpAPI.
21
  """
22
- SERPAPI_KEY = "2f660e5a696e7d1d08662085b95f83a61224476ec19558de3c68218baf346e43"
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
- response = requests.get(base_url, params=params)
 
 
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 # Returns an array of strings
47
-
48
- else:
49
- return [f"Error: {response.status_code} - {response.text}"] # Return error as array
 
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)}"]