
    dh0                     R    S r SSKJrJrJr  SSKJr  SSKJrJ	r	J
r
   " S S\5      rg)z&Util that calls Google Scholar Search.    )AnyDictOptional)get_from_dict_or_env)	BaseModel
ConfigDictmodel_validatorc                       \ rS rSr% SrSr\\S'   Sr\	\S'   Sr
\	\S'   S	r\\	   \S
'   S	r\\S'   \" SS9r\" SS9\S\S\4S j5       5       rS\	S\	4S jrSrg	)GoogleScholarAPIWrapper	   ar  Wrapper for Google Scholar API

You can create serpapi key by signing up at: https://serpapi.com/users/sign_up.

The wrapper uses the serpapi python package:
https://serpapi.com/integrations/python#search-google-scholar

To use, you should have the environment variable ``SERP_API_KEY``
set with your API key, or pass `serp_api_key` as a named parameter
to the constructor.

Attributes:
    top_k_results: number of results to return from google-scholar query search.
        By default it returns top 10 results.
    hl: attribute defines the language to use for the Google Scholar search.
        It's a two-letter language code.
        (e.g., en for English, es for Spanish, or fr for French). Head to the
        Google languages page for a full list of supported Google languages:
        https://serpapi.com/google-languages

    lr: attribute defines one or multiple languages to limit the search to.
        It uses lang_{two-letter language code} to specify languages
        and | as a delimiter. (e.g., lang_fr|lang_de will only search French
        and German pages). Head to the Google lr languages for a full
        list of supported languages: https://serpapi.com/google-lr-languages

 Example:
    .. code-block:: python

    from langchain_community.utilities import GoogleScholarAPIWrapper
    google_scholar = GoogleScholarAPIWrapper()
    google_scholar.run('langchain')

   top_k_resultsenhllang_enlrNserp_api_keygoogle_scholar_engineforbid)extrabefore)modevaluesreturnc                 |    [        USS5      nX!S'    SSKJn  X#l        X1S'   U$ ! [         a    [        S5      ef = f)z?Validate that api key and python package exists in environment.r   SERP_API_KEYr   )GoogleScholarSearchzigoogle-search-results is not installed. Please install it with `pip install google-search-results>=2.4.2`r   )r   serpapir   ImportErrorr   )clsr   r   r   s       d/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/google_scholar.pyvalidate_environment,GoogleScholarAPIWrapper.validate_environment6   s[     ,FNNS!-~	3 ,8(*=&'  	 	s   % ;queryc                 f   / nSnU[        U R                  S-
  S5      :  a  U R                  UUU R                  [	        U R                  S5      U R
                  S.5      R                  5       R                  S/ 5      nUR                  U5        U(       d  O$US-  nU[        U R                  S-
  S5      :  a  M  U R                  S-  S:w  at  US:  an  U(       ag  U R                  UUU R                  S-  U R                  U R
                  S.5      R                  5       R                  S/ 5      nUR                  U5        U(       d  gU VVs/ sH  nSUR                  S	S
5       SSR                  UR                  S0 5      R                  S/ 5       Vs/ sH  ofR                  S5      PM     sn5       SUR                  S0 5      R                  SS
5       SUR                  S0 5      R                  S0 5      R                  SS
5       3PM     nnnSR                  U5      $ s  snf s  snnf )z6Run query through GoogleSearchScholar and parse resultr         )qstartr   numr   organic_results)r(   r)   r*   r   r   z'No good Google Scholar Result was foundzTitle: title z

Authors: ,publication_infoauthorsnamez

Summary: summaryz
Total-Citations: inline_linkscited_bytotalz

)
maxr   r   r   minr   get_dictgetextendjoin)selfr$   total_resultspageresultsresultauthordocss           r!   runGoogleScholarAPIWrapper.runK   s7   S$,,r1A66 **"!%"gg" ..  #gg
 &+    )BJD1 S$,,r1A664 #q(TBY= **"!%#11B6"gg"gg &+    )< (

 (	 fjj"-. /6::N`bdCeCiCijsuwCx!yCx**V"4Cx!yz{ |

#5r:>>y"MN O  &

>2 > B B:r R V VW^`b cdf ( 	 
 {{4   "z
s   AH-H(1A#H-(H- )__name__
__module____qualname____firstlineno____doc__r   int__annotations__r   strr   r   r   r   r   r   model_configr	   classmethodr   r"   rC   __static_attributes__rE       r!   r   r   	   s     D M3BNB"&L(3-&!%3%L (#$ 3   $&8! 8! 8!rQ   r   N)rJ   typingr   r   r   langchain_core.utilsr   pydanticr   r   r	   r   rE   rQ   r!   <module>rU      s%    , & & 5 ; ;z!i z!rQ   