File size: 4,685 Bytes
264afdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
        <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)