File size: 2,069 Bytes
eb3b209
 
6024440
722be32
eb3b209
 
 
 
309b902
eb3b209
309b902
 
 
eb3b209
309b902
3d5e9b3
eb3b209
722be32
eb3b209
3d5e9b3
eb3b209
b3d173d
689f7f1
eb3b209
 
 
 
 
 
 
 
 
3d5e9b3
 
 
eb3b209
 
 
 
3d5e9b3
ee06ab0
722be32
 
 
eb3b209
 
ee06ab0
3d5e9b3
 
 
 
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
from smolagents.tools import Tool
import requests
import json
from typing import List

class LinkedInJobSearchTool(Tool):
    name = "linkedin_job_search"
    description = "Searches for jobs on LinkedIn based on job title, location, and work mode (remote, hybrid, in-office)."
    
    inputs = {
        "position": {"type": "string", "description": "Job title (e.g., Data Scientist)"},
        "location": {"type": "string", "description": "City or country (e.g., New York)"},
        "work_mode": {"type": "string", "description": "remote, hybrid, in-office"}
    }
    
    output_type = "array"  # ✅ Use "array" to return a list

    def forward(self, position: str, location: str, work_mode: str) -> List[str]:
        """
        Fetches job listings from LinkedIn using SerpAPI.
        """
        SERPAPI_KEY = "2f660e5a696e7d1d08662085b95f83a61224476ec19558de3c68218baf346e43"  # 🔹 Replace with your actual API key
        base_url = "https://serpapi.com/search"

        params = {
            "engine": "google_jobs",
            "q": f"{position} {work_mode} jobs",
            "location": location,
            "hl": "en",
            "api_key": SERPAPI_KEY
        }

        try:
            response = requests.get(base_url, params=params)
            response.raise_for_status()  # ✅ Handle HTTP errors

            data = response.json()
            job_results = data.get("jobs_results", [])

            # Convert job results to a list of formatted strings
            formatted_jobs = [
                f"Title: {job['title']}, Company: {job.get('company_name', 'N/A')}, "
                f"Location: {job.get('location', 'N/A')}, Posted: {job.get('detected_extensions', {}).get('posted_at', 'N/A')}, "
                f"Link: {job.get('job_id', 'N/A')}"
                for job in job_results
            ]

            return formatted_jobs if formatted_jobs else ["No jobs found. Try different keywords."]
        
        except requests.exceptions.RequestException as e:
            return [f"Error fetching job listings: {str(e)}"]