Source code for langchain_community.tools.google_books
"""Tool for the Google Books API."""fromtypingimportOptional,Typefromlangchain_core.callbacksimportCallbackManagerForToolRunfromlangchain_core.toolsimportBaseToolfrompydanticimportBaseModel,Fieldfromlangchain_community.utilities.google_booksimportGoogleBooksAPIWrapper
[docs]classGoogleBooksQueryInput(BaseModel):"""Input for the GoogleBooksQuery tool."""query:str=Field(description="query to look up on google books")
[docs]classGoogleBooksQueryRun(BaseTool):# type: ignore[override]"""Tool that searches the Google Books API."""name:str="GoogleBooks"description:str=("A wrapper around Google Books. ""Useful for when you need to answer general inquiries about ""books of certain topics and generate recommendation based ""off of key words""Input should be a query string")api_wrapper:GoogleBooksAPIWrapperargs_schema:Type[BaseModel]=GoogleBooksQueryInputdef_run(self,query:str,run_manager:Optional[CallbackManagerForToolRun]=None,)->str:"""Use the Google Books tool."""returnself.api_wrapper.run(query)