toolslm 0.0.7__py3-none-any.whl → 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toolslm/__init__.py +1 -1
- toolslm/download.py +1 -1
- toolslm/xml.py +20 -20
- toolslm-0.1.0.dist-info/METADATA +80 -0
- toolslm-0.1.0.dist-info/RECORD +13 -0
- {toolslm-0.0.7.dist-info → toolslm-0.1.0.dist-info}/WHEEL +1 -1
- toolslm-0.0.7.dist-info/METADATA +0 -154
- toolslm-0.0.7.dist-info/RECORD +0 -13
- {toolslm-0.0.7.dist-info → toolslm-0.1.0.dist-info}/LICENSE +0 -0
- {toolslm-0.0.7.dist-info → toolslm-0.1.0.dist-info}/entry_points.txt +0 -0
- {toolslm-0.0.7.dist-info → toolslm-0.1.0.dist-info}/top_level.txt +0 -0
toolslm/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.0
|
|
1
|
+
__version__ = "0.1.0"
|
toolslm/download.py
CHANGED
|
@@ -100,7 +100,7 @@ def find_docs(url):
|
|
|
100
100
|
if parsed_url.path == '/' or not parsed_url.path: return None
|
|
101
101
|
return find_docs(urljoin(url, '..'))
|
|
102
102
|
|
|
103
|
-
# %% ../03_download.ipynb
|
|
103
|
+
# %% ../03_download.ipynb 22
|
|
104
104
|
def read_docs(url, optional=False, n_workers=None, rm_comments=True, rm_details=True):
|
|
105
105
|
"If available, return LLM-friendly llms.txt context or markdown file response for `url`"
|
|
106
106
|
url = find_docs(url)
|
toolslm/xml.py
CHANGED
|
@@ -10,7 +10,7 @@ from collections import namedtuple
|
|
|
10
10
|
from fastcore.utils import *
|
|
11
11
|
from fastcore.meta import delegates
|
|
12
12
|
from fastcore.xtras import hl_md
|
|
13
|
-
from fastcore.xml import to_xml, Document, Documents, Document_content,
|
|
13
|
+
from fastcore.xml import to_xml, Document, Documents, Document_content, Src
|
|
14
14
|
from fastcore.script import call_parse
|
|
15
15
|
try: from IPython import display
|
|
16
16
|
except: display=None
|
|
@@ -32,7 +32,7 @@ def json_to_xml(d:dict, # JSON dictionary to convert
|
|
|
32
32
|
return ET.tostring(root, encoding='unicode')
|
|
33
33
|
|
|
34
34
|
# %% ../00_xml.ipynb 9
|
|
35
|
-
doctype = namedtuple('doctype', ['
|
|
35
|
+
doctype = namedtuple('doctype', ['src', 'content'])
|
|
36
36
|
|
|
37
37
|
# %% ../00_xml.ipynb 11
|
|
38
38
|
def _add_nls(s):
|
|
@@ -42,40 +42,40 @@ def _add_nls(s):
|
|
|
42
42
|
if s[-1]!='\n': s = s+'\n'
|
|
43
43
|
return s
|
|
44
44
|
|
|
45
|
-
# %% ../00_xml.ipynb
|
|
45
|
+
# %% ../00_xml.ipynb 16
|
|
46
46
|
def mk_doctype(content:str, # The document content
|
|
47
|
-
|
|
47
|
+
src:Optional[str]=None # URL, filename, etc; defaults to `md5(content)` if not provided
|
|
48
48
|
) -> namedtuple:
|
|
49
49
|
"Create a `doctype` named tuple"
|
|
50
|
-
if
|
|
51
|
-
return doctype(_add_nls(str(
|
|
50
|
+
if src is None: src = hashlib.md5(content.encode()).hexdigest()[:8]
|
|
51
|
+
return doctype(_add_nls(str(src).strip()), _add_nls(content.strip()))
|
|
52
52
|
|
|
53
|
-
# %% ../00_xml.ipynb
|
|
53
|
+
# %% ../00_xml.ipynb 19
|
|
54
54
|
def mk_doc(index:int, # The document index
|
|
55
55
|
content:str, # The document content
|
|
56
|
-
|
|
56
|
+
src:Optional[str]=None, # URL, filename, etc; defaults to `md5(content)` if not provided
|
|
57
57
|
**kwargs
|
|
58
58
|
) -> tuple:
|
|
59
59
|
"Create an `ft` format tuple for a single doc in Anthropic's recommended format"
|
|
60
|
-
dt = mk_doctype(content,
|
|
61
|
-
content = Document_content(dt.content)
|
|
62
|
-
|
|
63
|
-
return Document(
|
|
60
|
+
dt = mk_doctype(content, src)
|
|
61
|
+
content = Document_content(NotStr(dt.content))
|
|
62
|
+
src = Src(NotStr(dt.src))
|
|
63
|
+
return Document(src, content, index=index, **kwargs)
|
|
64
64
|
|
|
65
|
-
# %% ../00_xml.ipynb
|
|
65
|
+
# %% ../00_xml.ipynb 22
|
|
66
66
|
def docs_xml(docs:list[str], # The content of each document
|
|
67
|
-
|
|
67
|
+
srcs:Optional[list]=None, # URLs, filenames, etc; each one defaults to `md5(content)` if not provided
|
|
68
68
|
prefix:bool=True, # Include Anthropic's suggested prose intro?
|
|
69
69
|
details:Optional[list]=None # Optional list of dicts with additional attrs for each doc
|
|
70
70
|
)->str:
|
|
71
71
|
"Create an XML string containing `docs` in Anthropic's recommended format"
|
|
72
72
|
pre = 'Here are some documents for you to reference for your task:\n\n' if prefix else ''
|
|
73
|
-
if
|
|
73
|
+
if srcs is None: srcs = [None]*len(docs)
|
|
74
74
|
if details is None: details = [{}]*len(docs)
|
|
75
|
-
docs = (mk_doc(i+1, d, s, **kw) for i,(d,s,kw) in enumerate(zip(docs,
|
|
75
|
+
docs = (mk_doc(i+1, d, s, **kw) for i,(d,s,kw) in enumerate(zip(docs,srcs,details)))
|
|
76
76
|
return pre + to_xml(Documents(docs))
|
|
77
77
|
|
|
78
|
-
# %% ../00_xml.ipynb
|
|
78
|
+
# %% ../00_xml.ipynb 29
|
|
79
79
|
def files2ctx(
|
|
80
80
|
fnames:list[Union[str,Path]], # List of file names to add to context
|
|
81
81
|
prefix:bool=True # Include Anthropic's suggested prose intro?
|
|
@@ -84,7 +84,7 @@ def files2ctx(
|
|
|
84
84
|
contents = [o.read_text() for o in fnames]
|
|
85
85
|
return docs_xml(contents, fnames, prefix=prefix)
|
|
86
86
|
|
|
87
|
-
# %% ../00_xml.ipynb
|
|
87
|
+
# %% ../00_xml.ipynb 32
|
|
88
88
|
@delegates(globtastic)
|
|
89
89
|
def folder2ctx(
|
|
90
90
|
folder:Union[str,Path], # Folder name containing files to add to context
|
|
@@ -94,11 +94,11 @@ def folder2ctx(
|
|
|
94
94
|
fnames = globtastic(folder, **kwargs)
|
|
95
95
|
return files2ctx(fnames, prefix=prefix)
|
|
96
96
|
|
|
97
|
-
# %% ../00_xml.ipynb
|
|
97
|
+
# %% ../00_xml.ipynb 34
|
|
98
98
|
@call_parse
|
|
99
99
|
@delegates(folder2ctx)
|
|
100
100
|
def folder2ctx_cli(
|
|
101
101
|
folder:str, # Folder name containing files to add to context
|
|
102
102
|
**kwargs # Passed to `folder2ctx`
|
|
103
103
|
)->str: # XML for Claude context
|
|
104
|
-
|
|
104
|
+
print(folder2ctx(folder, **kwargs))
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: toolslm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tools to make language models a bit easier to use
|
|
5
|
+
Home-page: https://github.com/AnswerDotAI/toolslm
|
|
6
|
+
Author: Jeremy Howard
|
|
7
|
+
Author-email: j@fast.ai
|
|
8
|
+
License: Apache Software License 2.0
|
|
9
|
+
Keywords: nbdev jupyter notebook python
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: fastcore>=1.5.47
|
|
20
|
+
Requires-Dist: beautifulsoup4
|
|
21
|
+
Requires-Dist: html2text
|
|
22
|
+
Requires-Dist: httpx
|
|
23
|
+
Requires-Dist: llms-txt
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
|
|
26
|
+
# toolslm
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
30
|
+
|
|
31
|
+
This is a work in progress…
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
``` sh
|
|
36
|
+
pip install toolslm
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## How to use
|
|
40
|
+
|
|
41
|
+
### Context creation
|
|
42
|
+
|
|
43
|
+
toolslm has some helpers to make it easier to generate XML context from
|
|
44
|
+
files, for instance
|
|
45
|
+
[`folder2ctx`](https://AnswerDotAI.github.io/toolslm/xml.html#folder2ctx):
|
|
46
|
+
|
|
47
|
+
``` python
|
|
48
|
+
print(folder2ctx('samples', prefix=False, file_glob='*.py'))
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
<documents><document index="1"><src>
|
|
52
|
+
samples/sample_core.py
|
|
53
|
+
</src><document-content>
|
|
54
|
+
import inspect
|
|
55
|
+
empty = inspect.Parameter.empty
|
|
56
|
+
models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'
|
|
57
|
+
</document-content></document></documents>
|
|
58
|
+
|
|
59
|
+
JSON doesn’t map as nicely to XML as the `ft` data structure from
|
|
60
|
+
`fastcore.xml`, but for simple XML trees it can be convenient. The
|
|
61
|
+
[`json_to_xml`](https://AnswerDotAI.github.io/toolslm/xml.html#json_to_xml)
|
|
62
|
+
function handles that conversion:
|
|
63
|
+
|
|
64
|
+
``` python
|
|
65
|
+
a = dict(surname='Howard', firstnames=['Jeremy','Peter'],
|
|
66
|
+
address=dict(state='Queensland',country='Australia'))
|
|
67
|
+
print(json_to_xml(a, 'person'))
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
<person>
|
|
71
|
+
<surname>Howard</surname>
|
|
72
|
+
<firstnames>
|
|
73
|
+
<item>Jeremy</item>
|
|
74
|
+
<item>Peter</item>
|
|
75
|
+
</firstnames>
|
|
76
|
+
<address>
|
|
77
|
+
<state>Queensland</state>
|
|
78
|
+
<country>Australia</country>
|
|
79
|
+
</address>
|
|
80
|
+
</person>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
toolslm/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
2
|
+
toolslm/_modidx.py,sha256=EIl2FBWhcZUS46r1AU0wURYg2O6Z3aXTPUr3p8Smrqk,3882
|
|
3
|
+
toolslm/download.py,sha256=tXhq77GCqwVFDzTtzjcSAjxUWRiyPsjlXzkMjleH3dQ,4378
|
|
4
|
+
toolslm/funccall.py,sha256=hSvBvfMv-YcBSUUs4-NrYu1f8jg4gfu2s82cPyIHVkU,6534
|
|
5
|
+
toolslm/md_hier.py,sha256=hkCjuOfIFWuMEiM2_XCoD9QIBjy9huLOSvpX_bMdn0Y,4645
|
|
6
|
+
toolslm/shell.py,sha256=GVqfL74NHw66zzZ7jvGVLjE55ZNJGBPvEb8kLz4aoYc,1576
|
|
7
|
+
toolslm/xml.py,sha256=QNwUavoMkFK84D7dMwnBjqlYJwN-pJ7u3BxOeDuNAmk,4088
|
|
8
|
+
toolslm-0.1.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
toolslm-0.1.0.dist-info/METADATA,sha256=tQBydygSCJdH_wQaIbzC8Z8rZanQTJOdmpe1nEETkdE,2205
|
|
10
|
+
toolslm-0.1.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
11
|
+
toolslm-0.1.0.dist-info/entry_points.txt,sha256=xFz0Eymlo5X7BGpaO6DI9gMxvN5A7faebzrlr8ctp5I,95
|
|
12
|
+
toolslm-0.1.0.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
13
|
+
toolslm-0.1.0.dist-info/RECORD,,
|
toolslm-0.0.7.dist-info/METADATA
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: toolslm
|
|
3
|
-
Version: 0.0.7
|
|
4
|
-
Summary: Tools to make language models a bit easier to use
|
|
5
|
-
Home-page: https://github.com/AnswerDotAI/toolslm
|
|
6
|
-
Author: Jeremy Howard
|
|
7
|
-
Author-email: j@fast.ai
|
|
8
|
-
License: Apache Software License 2.0
|
|
9
|
-
Keywords: nbdev jupyter notebook python
|
|
10
|
-
Classifier: Development Status :: 4 - Beta
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: Natural Language :: English
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
-
Requires-Python: >=3.9
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
License-File: LICENSE
|
|
19
|
-
Requires-Dist: fastcore >=1.5.47
|
|
20
|
-
Requires-Dist: beautifulsoup4
|
|
21
|
-
Requires-Dist: html2text
|
|
22
|
-
Requires-Dist: httpx
|
|
23
|
-
Requires-Dist: llms-txt
|
|
24
|
-
Provides-Extra: dev
|
|
25
|
-
|
|
26
|
-
# toolslm
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
30
|
-
|
|
31
|
-
This is a work in progress…
|
|
32
|
-
|
|
33
|
-
## Install
|
|
34
|
-
|
|
35
|
-
``` sh
|
|
36
|
-
pip install toolslm
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## How to use
|
|
40
|
-
|
|
41
|
-
### Context creation
|
|
42
|
-
|
|
43
|
-
toolslm has some helpers to make it easier to generate XML context from
|
|
44
|
-
files, for instance `folder2ctx`:
|
|
45
|
-
|
|
46
|
-
``` python
|
|
47
|
-
print(folder2ctx('samples', prefix=False, file_glob='*.py'))
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
<documents>
|
|
51
|
-
<document index="1">
|
|
52
|
-
<source>
|
|
53
|
-
samples/sample_core.py
|
|
54
|
-
</source>
|
|
55
|
-
<document_content>
|
|
56
|
-
import inspect
|
|
57
|
-
empty = inspect.Parameter.empty
|
|
58
|
-
models = 'claude-3-opus-20240229','claude-3-sonnet-20240229','claude-3-haiku-20240307'
|
|
59
|
-
</document_content>
|
|
60
|
-
</document>
|
|
61
|
-
</documents>
|
|
62
|
-
|
|
63
|
-
### XML helpers
|
|
64
|
-
|
|
65
|
-
Many language models work well with XML inputs, but XML can be a bit
|
|
66
|
-
clunky to work with manually. Therefore, toolslm includes a couple of
|
|
67
|
-
more streamlined approaches for XML generation.
|
|
68
|
-
|
|
69
|
-
An XML node contains a tag, optional children, and optional attributes.
|
|
70
|
-
`xt` creates a tuple of these three things, which we will use to general
|
|
71
|
-
XML shortly. Attributes are passed as kwargs; since these might conflict
|
|
72
|
-
with reserved words in Python, you can optionally add a `_` prefix and
|
|
73
|
-
it’ll be stripped off.
|
|
74
|
-
|
|
75
|
-
``` python
|
|
76
|
-
xt('x-custom', ['hi'], _class='bar')
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
('x-custom', ['hi'], {'class': 'bar'})
|
|
80
|
-
|
|
81
|
-
Claudette has functions defined for some common HTML elements to create
|
|
82
|
-
`xt` tuples more easily, including these:
|
|
83
|
-
|
|
84
|
-
``` python
|
|
85
|
-
from toolslm.xml import div,img,h1,h2,p,hr,html
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
``` python
|
|
89
|
-
a = html([
|
|
90
|
-
p('This is a paragraph'),
|
|
91
|
-
hr(),
|
|
92
|
-
img(src='http://example.prg'),
|
|
93
|
-
div([
|
|
94
|
-
h1('This is a header'),
|
|
95
|
-
h2('This is a sub-header', style='k:v'),
|
|
96
|
-
], _class='foo')
|
|
97
|
-
])
|
|
98
|
-
a
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
('html',
|
|
102
|
-
[('p', 'This is a paragraph', {}),
|
|
103
|
-
('hr', None, {}),
|
|
104
|
-
('img', None, {'src': 'http://example.prg'}),
|
|
105
|
-
('div',
|
|
106
|
-
[('h1', 'This is a header', {}),
|
|
107
|
-
('h2', 'This is a sub-header', {'style': 'k:v'})],
|
|
108
|
-
{'class': 'foo'})],
|
|
109
|
-
{})
|
|
110
|
-
|
|
111
|
-
To convert a tuple data structure created with `xt` and friends into
|
|
112
|
-
XML, use `to_xml`, adding the `hl` parameter to optionally add syntax
|
|
113
|
-
highlighting:
|
|
114
|
-
|
|
115
|
-
``` python
|
|
116
|
-
to_xml(a, hl=True)
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
``` xml
|
|
120
|
-
<html>
|
|
121
|
-
<p>This is a paragraph</p>
|
|
122
|
-
<hr />
|
|
123
|
-
<img src="http://example.prg" />
|
|
124
|
-
<div class="foo">
|
|
125
|
-
<h1>This is a header</h1>
|
|
126
|
-
<h2 style="k:v">This is a sub-header</h2>
|
|
127
|
-
</div>
|
|
128
|
-
</html>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
JSON doesn’t map as nicely to XML as the `xt` data structure, but for
|
|
132
|
-
simple XML trees it can be convenient. The `json_to_xml` function
|
|
133
|
-
handles that conversion:
|
|
134
|
-
|
|
135
|
-
``` python
|
|
136
|
-
a = dict(surname='Howard', firstnames=['Jeremy','Peter'],
|
|
137
|
-
address=dict(state='Queensland',country='Australia'))
|
|
138
|
-
print(json_to_xml(a, 'person'))
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
<person>
|
|
142
|
-
<surname>Howard</surname>
|
|
143
|
-
<firstnames>
|
|
144
|
-
<item>Jeremy</item>
|
|
145
|
-
<item>Peter</item>
|
|
146
|
-
</firstnames>
|
|
147
|
-
<address>
|
|
148
|
-
<state>Queensland</state>
|
|
149
|
-
<country>Australia</country>
|
|
150
|
-
</address>
|
|
151
|
-
</person>
|
|
152
|
-
|
|
153
|
-
See the `xml source` section for a walkthru of XML and document context
|
|
154
|
-
generation functionality.
|
toolslm-0.0.7.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
toolslm/__init__.py,sha256=R9xOYoYrWKcfO5zvTeGC3m_eDNOvxMd8CocQs2tLufo,22
|
|
2
|
-
toolslm/_modidx.py,sha256=EIl2FBWhcZUS46r1AU0wURYg2O6Z3aXTPUr3p8Smrqk,3882
|
|
3
|
-
toolslm/download.py,sha256=tf0TGFzJ6qbxCjjuG9iRC2i6lutcF9GviWY0fJc_lSU,4378
|
|
4
|
-
toolslm/funccall.py,sha256=hSvBvfMv-YcBSUUs4-NrYu1f8jg4gfu2s82cPyIHVkU,6534
|
|
5
|
-
toolslm/md_hier.py,sha256=hkCjuOfIFWuMEiM2_XCoD9QIBjy9huLOSvpX_bMdn0Y,4645
|
|
6
|
-
toolslm/shell.py,sha256=GVqfL74NHw66zzZ7jvGVLjE55ZNJGBPvEb8kLz4aoYc,1576
|
|
7
|
-
toolslm/xml.py,sha256=Alcd96KfNO8LklVefyc51LbXBoVLRSgifrpMVZPqYsc,4120
|
|
8
|
-
toolslm-0.0.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
-
toolslm-0.0.7.dist-info/METADATA,sha256=sdRs3kCMl1xI8Z1if4xsGWuGaX9hbYGB0zs0BbRhQp0,3882
|
|
10
|
-
toolslm-0.0.7.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
11
|
-
toolslm-0.0.7.dist-info/entry_points.txt,sha256=xFz0Eymlo5X7BGpaO6DI9gMxvN5A7faebzrlr8ctp5I,95
|
|
12
|
-
toolslm-0.0.7.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
13
|
-
toolslm-0.0.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|