
    7|h
                     ^    d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
mZmZmZ  G d de
      Zy)z&Util that calls Google Scholar Search.    )AnyDictOptionalcast)convert_to_secret_strget_from_dict_or_env)	BaseModel
ConfigDict	SecretStrmodel_validatorc                       e Zd ZU dZdZeed<   dZee	   ed<    e
d      Z ed      ed	ed
efd              Zded
efdZy)GoogleJobsAPIWrapperaU  Wrapper for SerpApi's Google Scholar API

    You can create SerpApi.com key by signing up at: https://serpapi.com/users/sign_up.
    The wrapper uses the SerpApi.com python package:
    https://serpapi.com/integrations/python
    To use, you should have the environment variable ``SERPAPI_API_KEY``
    set with your API key, or pass `serp_api_key` as a named parameter
    to the constructor.
     Example:
        .. code-block:: python
        from langchain_community.utilities import GoogleJobsAPIWrapper
        google_Jobs = GoogleJobsAPIWrapper()
        google_Jobs.run('langchain')
    Nserp_search_engineserp_api_keyforbid)extrabefore)modevaluesreturnc                     t        t        |dd            |d<   	 ddlm} |}||d<   |S # t        $ r t	        d      w xY w)z?Validate that api key and python package exists in environment.r   SERPAPI_API_KEYr   )SerpApiClientzigoogle-search-results is not installed. Please install it with `pip install google-search-results>=2.4.2`r   )r   r   serpapir   ImportError)clsr   r   r   s       h/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/utilities/google_jobs.pyvalidate_environmentz)GoogleJobsAPIWrapper.validate_environment    sc     "7 9JK"
~	- +'9#$  	 	s   * ?queryc                 @   t        t        | j                        }d|j                         |d}g }| j	                  |      }|j                         d   }d}t        d      D ]6  }||   }|dd|d    d	z   d
|d    d	z   d|d    d	z   d|d    z   dz   z  }8 |d	z   S )z,Run query through Google Trends with Serpapigoogle_jobs)engineapi_keyqjobs_results    z0
_______________________________________________z
Job Title: title
zCompany Name: company_namez
Location: locationzDescription: descriptionz1
_______________________________________________
)r   r   r   get_secret_valuer   get_dictrange)	selfr   serpapi_api_keyparamstotal_resultsclientres_strijobs	            r   runzGoogleJobsAPIWrapper.run6   s     y$*;*;<#&779
 ((0).9 q 		A"CC!#g,r23"3~#6"7r:; s:/r23 "#m"4!56	7
 HHG		 ~    )__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r
   model_configr   classmethodr   r   strr8    r9   r   r   r   	   sr     #"(,L(9%,L (#$ 3   $(  r9   r   N)r=   typingr   r   r   r   langchain_core.utilsr   r   pydanticr	   r
   r   r   r   rB   r9   r   <module>rF      s%    , , , L F FI9 Ir9   