Ë
    µŒjŽ  ã                   ób   — d Z ddlmZmZmZ ddlZddlmZ ddlm	Z	m
Z
mZ dZdZ G d„ d	e	«      Zy)
zUtil that calls Google Books.é    )ÚDictÚListÚOptionalN©Úget_from_dict_or_env)Ú	BaseModelÚ
ConfigDictÚmodel_validatoré   z+https://www.googleapis.com/books/v1/volumesc                   ó¬   — e Zd ZU dZdZee   ed<   eZ	e
ed<    ed¬«      Z ed¬«      ed	ed
efd„«       «       Zded
efd„Zdeded
efd„Zded
efd„Zy)ÚGoogleBooksAPIWrappera�  Wrapper around Google Books API.

    To use, you should have a Google Books API key available.
    This wrapper will use the Google Books API to conduct searches and
    fetch books based on a query passed in by the agents. By default,
    it will return the top-k results.

    The response for each book will contain the book title, author name, summary, and
    a source link.
    NÚgoogle_books_api_keyÚtop_k_resultsÚforbid)ÚextraÚbefore)ÚmodeÚvaluesÚreturnc                 ó*   — t        |dd«      }||d<   |S )z,Validate that api key exists in environment.r   ÚGOOGLE_BOOKS_API_KEYr   )Úclsr   r   s      út/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/utilities/google_books.pyÚvalidate_environmentz*GoogleBooksAPIWrapper.validate_environment    s*   € ô  4ØÐ*Ð,Bó 
Ðð *>ˆÐ%Ñ&àˆó    Úqueryc                 ód  — d|fd| j                   fd| j                  ff}t        j                  t        |¬«      }|j                  «       }|j                  dk7  r6|j                  }|j                  di «      j                  dd«      }d	|› d
|› �S | j                  ||j                  dg «      «      S )NÚqÚ
maxResultsÚkey)ÚparamséÈ   ÚerrorÚmessagezInternal failurez)Unable to retrieve books got status code ú: Úitems)r   r   ÚrequestsÚgetÚGOOGLE_BOOKS_API_URLÚjsonÚstatus_codeÚ_format)Úselfr   r!   Úresponser*   Úcoder#   s          r   ÚrunzGoogleBooksAPIWrapper.run+   s¶   € ð �%ˆLØ˜4×-Ñ-Ð.Ø�D×-Ñ-Ð.ð
ˆô —<‘<Ô 4¸VÔDˆØ�}‰}‹ˆð ×Ñ 3Ò&Ø×'Ñ'ˆDØ—H‘H˜W bÓ)×-Ñ-¨iÐ9KÓLˆEØ>¸t¸fÀBÀuÀgÐNÐNð �|‰|˜E 4§8¡8¨G°RÓ#8Ó9Ð9r   Úbooksc           	      ó6  — |sd|› �S dt        |«      › d|› d�}g }|j                  |«       d}|D ]V  }|d   }|d   }| j                  |d   «      }	|d	   }
|d
   }|› d|› d|	› d|
› d�}|d|› �z  }|j                  |«       |dz  }ŒX dj                  |«      S )Nz.Sorry no books could be found for your query: z	Here are z" suggestions for books related to Ú:é   Ú
volumeInfoÚtitleÚauthorsÚdescriptionÚinfoLinkz. "z" by r%   Ú
zYou can read more at z

)ÚlenÚappendÚ_format_authorsÚjoin)r-   r   r1   ÚstartÚresultsÚiÚbookÚinfor6   r7   ÚsummaryÚsourceÚdescs                r   r,   zGoogleBooksAPIWrapper._format@   sÝ   € ÙØCÀEÀ7ÐKÐKàœC ›J˜<Ð'IÈ%ÈÐPQÐRˆàˆØ�‰�uÔØˆãˆDØ˜Ñ%ˆDØ˜‘MˆEØ×*Ñ*¨4°	©?Ó;ˆGØ˜=Ñ)ˆGØ˜*Ñ%ˆFà�S˜˜E˜7 %¨ y°°7°)¸2Ð>ˆDØÐ+¨F¨8Ð4Ñ4ˆDØ�N‰N˜4Ô à�‰F‰Að ð �{‰{˜7Ó#Ð#r   r7   c                 óv   — t        |«      dk(  r|d   S dj                  dj                  |d d «      |d   «      S )Nr4   r   z	{} and {}z, éÿÿÿÿ)r;   Úformatr>   )r-   r7   s     r   r=   z%GoogleBooksAPIWrapper._format_authorsY   s>   € Üˆw‹<˜1ÒØ˜1‘:ÐØ×!Ñ! $§)¡)¨G°C°R¨LÓ"9¸7À2¹;ÓGÐGr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚstrÚ__annotations__ÚGOOGLE_BOOKS_MAX_ITEM_SIZEr   Úintr	   Úmodel_configr
   Úclassmethodr   r   r0   r   r,   r=   © r   r   r   r      s¡   … ñ	ð +/Ð˜( 3™-Ó.Ø3€M�3Ó3áØô€Lñ ˜(Ô#Øð¨$ð °4ò ó ó $ðð:˜ð : ó :ð*$˜Sð $¨ð $°#ó $ð2H tð H°ô Hr   r   )rM   Útypingr   r   r   r'   Úlangchain_core.utilsr   Úpydanticr   r	   r
   rP   r)   r   rT   r   r   Ú<module>rX      s6   ðÙ #ç 'Ñ 'ã Ý 5ß ;Ñ ;àÐ ØDÐ ôOH˜Iõ OHr   