| from smolagents import Tool |
| from my_base_libretexts_api import MyLibreTextsAPI |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| 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 |
| <code> |
| bookshelves = _my_tool_libretexts_bookshelves() |
| </code> |
| """ |
|
|
| 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 |
| <code> |
| books = _my_tool_libretexts_books(bookshelf_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry') |
| </code> |
| """ |
|
|
| 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 |
| <code> |
| sections = _my_tool_libretexts_book_sections(book_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)') |
| </code> |
| """ |
|
|
| 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 |
| <code> |
| paragraphs = _my_tool_libretexts_book_section_paragraphs(section_url='https://chem.libretexts.org/Bookshelves/Inorganic_Chemistry/Inorganic_Chemistry_(Saito)/03%3A_Reactions') |
| </code> |
| """ |
|
|
| 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 |
| <code> |
| 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') |
| </code> |
| """ |
|
|
| 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) |
|
|