from smolagents import Tool from my_base_libretexts_api import MyLibreTextsAPI #AUTHORIZED_TYPES = [ # "string", # "boolean", # "integer", # "number", # "image", # "audio", # "array", # "object", # "any", # "null", #] class MyLibreTextsBase(Tool): is_initialized = True def __init__(self): print(f"***KS*** LibreTexts Base Tool initializing ...") self.api = MyLibreTextsAPI() class MyLibreTextsBookshelvesTool(MyLibreTextsBase): name = "_my_tool_libretexts_bookshelves" description = """ Get a list of bookshelves in LibreTexts library of chemistry materials Returns an array with dictionary items containing 'title' and 'url' of a bookshelf bookshelves = _my_tool_libretexts_bookshelves() """ inputs = { } output_type = "array" is_initialized = True def __init__(self): MyLibreTextsBase.__init__(self) print(f"***KS*** LibreTexts Bookshelves Tool initializing ...") def forward(self): return self.api.get_bookshelves() class MyLibreTextsBooksTool(MyLibreTextsBase): name = "_my_tool_libretexts_books" description = """ Get a list of books in LibreTexts bookshelf Returns an array with dictionary items containing 'title' and 'url' of a book books = _my_tool_libretexts_books(bookshelf_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry') """ inputs = { "bookshelf_url": { "type": "string", "description": "Bookshelf URL", }, } output_type = "array" is_initialized = True def __init__(self): MyLibreTextsBase.__init__(self) print(f"***KS*** LibreTexts Books Tool initializing ...") def forward(self, bookshelf_url): return self.api.get_books(bookshelf_url) class MyLibreTextsBookSectionsTool(MyLibreTextsBase): name = "_my_tool_libretexts_book_sections" description = """ Get a list of sections in a book in LibreTexts materials Returns an array with dictionary items containing 'title' and 'url' of a section sections = _my_tool_libretexts_book_sections(book_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)') """ inputs = { "book_url": { "type": "string", "description": "Book URL", }, } output_type = "array" is_initialized = True def __init__(self): MyLibreTextsBase.__init__(self) print(f"***KS*** LibreTexts Book Sections Tool initializing ...") def forward(self, book_url): return self.api.get_book_sections(book_url) class MyLibreTextsBookSectionParagraphsTool(MyLibreTextsBase): name = "_my_tool_libretexts_book_section_paragraphs" description = """ Get a list of section paragraphs in a book in LibreTexts materials Returns an array with dictionary items containing 'title' and 'url' of a paragraph paragraphs = _my_tool_libretexts_book_section_paragraphs(section_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)/03%3A_Reactions') """ inputs = { "section_url": { "type": "string", "description": "Book section URL", }, } output_type = "array" is_initialized = True def __init__(self): MyLibreTextsBase.__init__(self) print(f"***KS*** LibreTexts Book Section Paragraphs Tool initializing ...") def forward(self, section_url): return self.api.get_book_section_paragraphs(section_url) class MyLibreTextsParagraphContentsTool(MyLibreTextsBase): name = "_my_tool_libretexts_paragraph_contents" description = """ Get contents of a paragraph in a book in LibreTexts materials Returns contents in Markdown format markdown = _my_tool_libretexts_paragraph_contents(paragraph_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)/03%3A_Reactions/3.01%3A_Thermodynamics') """ inputs = { "paragraph_url": { "type": "string", "description": "Paragraph URL", }, } output_type = "string" is_initialized = True def __init__(self): MyLibreTextsBase.__init__(self) print(f"***KS*** LibreTexts Paragraph Contents Tool initializing ...") def forward(self, paragraph_url): return self.api.get_paragraph_contents(paragraph_url)