codekingpro/portable-devtools
114k
1"""Tool for the Google Books API."""2 3from typing import Optional, Type4 5from langchain_core.callbacks import CallbackManagerForToolRun6from langchain_core.tools import BaseTool7from pydantic import BaseModel, Field8 9from langchain_community.utilities.google_books import GoogleBooksAPIWrapper10 11 12class GoogleBooksQueryInput(BaseModel):13 """Input for the GoogleBooksQuery tool."""14 15 query: str = Field(description="query to look up on google books")16 17 18class GoogleBooksQueryRun(BaseTool):19 """Tool that searches the Google Books API."""20 21 name: str = "GoogleBooks"22 description: str = (23 "A wrapper around Google Books. "24 "Useful for when you need to answer general inquiries about "25 "books of certain topics and generate recommendation based "26 "off of key words"27 "Input should be a query string"28 )29 api_wrapper: GoogleBooksAPIWrapper30 args_schema: Type[BaseModel] = GoogleBooksQueryInput31 32 def _run(33 self,34 query: str,35 run_manager: Optional[CallbackManagerForToolRun] = None,36 ) -> str:37 """Use the Google Books tool."""38 return self.api_wrapper.run(query)39 