toolslm 0.3.2__tar.gz → 0.3.3__tar.gz
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-0.3.2/toolslm.egg-info → toolslm-0.3.3}/PKG-INFO +1 -1
- {toolslm-0.3.2 → toolslm-0.3.3}/settings.ini +1 -1
- toolslm-0.3.3/toolslm/__init__.py +1 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm/_modidx.py +6 -1
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm/funccall.py +3 -1
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm/xml.py +46 -4
- {toolslm-0.3.2 → toolslm-0.3.3/toolslm.egg-info}/PKG-INFO +1 -1
- toolslm-0.3.2/toolslm/__init__.py +0 -1
- {toolslm-0.3.2 → toolslm-0.3.3}/LICENSE +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/MANIFEST.in +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/README.md +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/pyproject.toml +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/setup.cfg +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/setup.py +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm/download.py +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm/md_hier.py +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm/shell.py +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm.egg-info/SOURCES.txt +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm.egg-info/dependency_links.txt +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm.egg-info/entry_points.txt +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm.egg-info/not-zip-safe +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm.egg-info/requires.txt +0 -0
- {toolslm-0.3.2 → toolslm-0.3.3}/toolslm.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.3"
|
|
@@ -35,10 +35,15 @@ d = { 'settings': { 'branch': 'main',
|
|
|
35
35
|
'toolslm/shell.py'),
|
|
36
36
|
'toolslm.shell.get_shell': ('shell.html#get_shell', 'toolslm/shell.py')},
|
|
37
37
|
'toolslm.xml': { 'toolslm.xml._add_nls': ('xml.html#_add_nls', 'toolslm/xml.py'),
|
|
38
|
+
'toolslm.xml.cell2out': ('xml.html#cell2out', 'toolslm/xml.py'),
|
|
39
|
+
'toolslm.xml.cell2xml': ('xml.html#cell2xml', 'toolslm/xml.py'),
|
|
38
40
|
'toolslm.xml.docs_xml': ('xml.html#docs_xml', 'toolslm/xml.py'),
|
|
39
41
|
'toolslm.xml.files2ctx': ('xml.html#files2ctx', 'toolslm/xml.py'),
|
|
40
42
|
'toolslm.xml.folder2ctx': ('xml.html#folder2ctx', 'toolslm/xml.py'),
|
|
41
43
|
'toolslm.xml.folder2ctx_cli': ('xml.html#folder2ctx_cli', 'toolslm/xml.py'),
|
|
44
|
+
'toolslm.xml.get_mime_text': ('xml.html#get_mime_text', 'toolslm/xml.py'),
|
|
42
45
|
'toolslm.xml.json_to_xml': ('xml.html#json_to_xml', 'toolslm/xml.py'),
|
|
43
46
|
'toolslm.xml.mk_doc': ('xml.html#mk_doc', 'toolslm/xml.py'),
|
|
44
|
-
'toolslm.xml.mk_doctype': ('xml.html#mk_doctype', 'toolslm/xml.py')
|
|
47
|
+
'toolslm.xml.mk_doctype': ('xml.html#mk_doctype', 'toolslm/xml.py'),
|
|
48
|
+
'toolslm.xml.nb2xml': ('xml.html#nb2xml', 'toolslm/xml.py'),
|
|
49
|
+
'toolslm.xml.read_file': ('xml.html#read_file', 'toolslm/xml.py')}}}
|
|
@@ -107,7 +107,9 @@ def _get_nested_schema(obj):
|
|
|
107
107
|
if n != 'return' and n != 'self':
|
|
108
108
|
_process_property(n, o, props, req, defs)
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
tkw = {}
|
|
111
|
+
if isinstance(obj, type): tkw['title']=obj.__name__
|
|
112
|
+
schema = dict(type='object', properties=props, **tkw)
|
|
111
113
|
if req: schema['required'] = list(req)
|
|
112
114
|
if defs: schema['$defs'] = defs
|
|
113
115
|
return schema
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../00_xml.ipynb.
|
|
2
2
|
|
|
3
3
|
# %% auto 0
|
|
4
|
-
__all__ = ['doctype', 'json_to_xml', '
|
|
4
|
+
__all__ = ['doctype', 'json_to_xml', 'get_mime_text', 'cell2out', 'cell2xml', 'nb2xml', 'mk_doctype', 'mk_doc', 'docs_xml',
|
|
5
|
+
'read_file', 'files2ctx', 'folder2ctx', 'folder2ctx_cli']
|
|
5
6
|
|
|
6
7
|
# %% ../00_xml.ipynb
|
|
7
8
|
import hashlib,xml.etree.ElementTree as ET
|
|
@@ -10,7 +11,7 @@ from collections import namedtuple
|
|
|
10
11
|
from fastcore.utils import *
|
|
11
12
|
from fastcore.meta import delegates
|
|
12
13
|
from fastcore.xtras import hl_md
|
|
13
|
-
from fastcore.xml import to_xml, Document, Documents, Document_content, Src
|
|
14
|
+
from fastcore.xml import to_xml, Document, Documents, Document_content, Src, Source,Out,Outs,Cell
|
|
14
15
|
from fastcore.script import call_parse
|
|
15
16
|
try: from IPython import display
|
|
16
17
|
except: display=None
|
|
@@ -31,6 +32,39 @@ def json_to_xml(d:dict, # JSON dictionary to convert
|
|
|
31
32
|
ET.indent(root)
|
|
32
33
|
return ET.tostring(root, encoding='unicode')
|
|
33
34
|
|
|
35
|
+
# %% ../00_xml.ipynb
|
|
36
|
+
def get_mime_text(data):
|
|
37
|
+
"Get text from MIME bundle, preferring markdown over plain"
|
|
38
|
+
if 'text/markdown' in data: return ''.join(list(data['text/markdown']))
|
|
39
|
+
if 'text/plain' in data: return ''.join(list(data['text/plain']))
|
|
40
|
+
|
|
41
|
+
# %% ../00_xml.ipynb
|
|
42
|
+
def cell2out(o):
|
|
43
|
+
"Convert single notebook output to XML format"
|
|
44
|
+
if hasattr(o, 'data'):
|
|
45
|
+
txt = get_mime_text(o.data)
|
|
46
|
+
if txt: return Out(txt, mime='markdown' if 'text/markdown' in o.data else 'plain')
|
|
47
|
+
if hasattr(o, 'text'):
|
|
48
|
+
txt = o.text if isinstance(o.text, str) else ''.join(o.text)
|
|
49
|
+
return Out(txt, type='stream', name=o.get('name', 'stdout'))
|
|
50
|
+
if hasattr(o, 'ename'): return Out(f"{o.ename}: {o.evalue}", type='error')
|
|
51
|
+
|
|
52
|
+
# %% ../00_xml.ipynb
|
|
53
|
+
def cell2xml(cell):
|
|
54
|
+
"Convert notebook cell to concise XML format"
|
|
55
|
+
cts = Source(''.join(cell.source)) if hasattr(cell, 'source') and cell.source else None
|
|
56
|
+
out_items = L(getattr(cell,'outputs',[])).map(cell2out).filter()
|
|
57
|
+
outs = []
|
|
58
|
+
if out_items: outs = Outs(*out_items)
|
|
59
|
+
parts = [p for p in [cts, outs] if p]
|
|
60
|
+
return Cell(*parts, type=cell.cell_type)
|
|
61
|
+
|
|
62
|
+
# %% ../00_xml.ipynb
|
|
63
|
+
def nb2xml(fname):
|
|
64
|
+
nb = dict2obj(fname.read_json())
|
|
65
|
+
cells_xml = [to_xml(cell2xml(c), do_escape=False) for c in nb.cells if c.cell_type in ('code','markdown')]
|
|
66
|
+
return '\n'.join(cells_xml)
|
|
67
|
+
|
|
34
68
|
# %% ../00_xml.ipynb
|
|
35
69
|
doctype = namedtuple('doctype', ['src', 'content'])
|
|
36
70
|
|
|
@@ -73,15 +107,23 @@ def docs_xml(docs:list[str], # The content of each document
|
|
|
73
107
|
if srcs is None: srcs = [None]*len(docs)
|
|
74
108
|
if details is None: details = [{}]*len(docs)
|
|
75
109
|
docs = (mk_doc(i+1, d, s, **kw) for i,(d,s,kw) in enumerate(zip(docs,srcs,details)))
|
|
76
|
-
return pre + to_xml(Documents(docs))
|
|
110
|
+
return pre + to_xml(Documents(docs), do_escape=False)
|
|
111
|
+
|
|
112
|
+
# %% ../00_xml.ipynb
|
|
113
|
+
def read_file(fname):
|
|
114
|
+
"Read file content, converting notebooks to XML if needed"
|
|
115
|
+
fname = Path(fname)
|
|
116
|
+
if fname.suffix == '.ipynb': return nb2xml(fname)
|
|
117
|
+
return fname.read_text()
|
|
77
118
|
|
|
78
119
|
# %% ../00_xml.ipynb
|
|
79
120
|
def files2ctx(
|
|
80
121
|
fnames:list[Union[str,Path]], # List of file names to add to context
|
|
81
122
|
prefix:bool=True # Include Anthropic's suggested prose intro?
|
|
82
123
|
)->str: # XML for LM context
|
|
124
|
+
"Convert files to XML context, handling notebooks"
|
|
83
125
|
fnames = [Path(o) for o in fnames]
|
|
84
|
-
contents = [o
|
|
126
|
+
contents = [read_file(o) for o in fnames]
|
|
85
127
|
return docs_xml(contents, fnames, prefix=prefix)
|
|
86
128
|
|
|
87
129
|
# %% ../00_xml.ipynb
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|