toolslm 0.3.14__tar.gz → 0.3.17__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolslm
3
- Version: 0.3.14
3
+ Version: 0.3.17
4
4
  Summary: Tools to make language models a bit easier to use
5
5
  Home-page: https://github.com/AnswerDotAI/toolslm
6
6
  Author: Jeremy Howard
@@ -18,6 +18,7 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: fastcore>=1.9.7
20
20
  Requires-Dist: httpx
21
+ Requires-Dist: ghapi
21
22
  Provides-Extra: dev
22
23
  Dynamic: author
23
24
  Dynamic: author-email
@@ -1,11 +1,11 @@
1
1
  [DEFAULT]
2
2
  repo = toolslm
3
3
  lib_name = toolslm
4
- version = 0.3.14
4
+ version = 0.3.17
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
8
- requirements = fastcore>=1.9.7 httpx
8
+ requirements = fastcore>=1.9.7 httpx ghapi
9
9
  doc_path = _docs
10
10
  lib_path = toolslm
11
11
  nbs_path = .
@@ -0,0 +1 @@
1
+ __version__ = "0.3.17"
@@ -50,22 +50,23 @@ def cell2out(o):
50
50
  if hasattr(o, 'ename'): return Out(f"{o.ename}: {o.evalue}", type='error')
51
51
 
52
52
  # %% ../00_xml.ipynb
53
- def cell2xml(cell, out=True):
53
+ def cell2xml(cell, out=True, ids=True):
54
54
  "Convert notebook cell to concise XML format"
55
55
  src = ''.join(getattr(cell, 'source', ''))
56
56
  f = Code if cell.cell_type=='code' else Md
57
- if not out: return f(src)
57
+ kw = dict(id=cell.id) if ids and hasattr(cell, 'id') else {}
58
+ if not out: return f(src, **kw)
58
59
  parts = [Source(src)]
59
60
  out_items = L(getattr(cell,'outputs',[])).map(cell2out).filter()
60
61
  if out_items: parts.append(Outs(*out_items))
61
- return f(*parts)
62
+ return f(*parts, **kw)
62
63
 
63
64
  # %% ../00_xml.ipynb
64
- def nb2xml(fname=None, nb=None, out=True):
65
+ def nb2xml(fname=None, nb=None, out=True, ids=True):
65
66
  "Convert notebook to XML format"
66
67
  assert bool(fname)^bool(nb), "Pass either `fname` or `nb`"
67
68
  if not nb: nb = dict2obj(fname.read_json())
68
- cells_xml = [to_xml(cell2xml(c, out=out), do_escape=False) for c in nb.cells if c.cell_type in ('code','markdown')]
69
+ cells_xml = [to_xml(cell2xml(c, out=out, ids=ids), do_escape=False) for c in nb.cells if c.cell_type in ('code','markdown')]
69
70
  return to_xml(Notebook(*cells_xml), do_escape=False)
70
71
 
71
72
  # %% ../00_xml.ipynb
@@ -115,10 +116,10 @@ def docs_xml(docs:list[str], # The content of each document
115
116
  return pre + to_xml(Documents(*docs, **kw), do_escape=False)
116
117
 
117
118
  # %% ../00_xml.ipynb
118
- def read_file(fname, out=True, max_size=None):
119
+ def read_file(fname, out=True, max_size=None, ids=True):
119
120
  "Read file content, converting notebooks to XML if needed"
120
121
  fname = Path(fname)
121
- if fname.suffix == '.ipynb': res = nb2xml(fname, out=out)
122
+ if fname.suffix == '.ipynb': res = nb2xml(fname, out=out, ids=ids)
122
123
  else: res = fname.read_text()
123
124
  if max_size and len(res)>max_size: return f"[Skipped: {fname.name} exceeds {max_size} bytes]"
124
125
  return res
@@ -130,11 +131,12 @@ def files2ctx(
130
131
  out:bool=True, # Include notebook cell outputs?
131
132
  srcs:Optional[list]=None, # Use the labels instead of `fnames`
132
133
  max_size:int=None, # Skip files larger than this (bytes)
134
+ ids:bool=True, # Include cell ids in notebooks?
133
135
  **kwargs
134
136
  )->str: # XML for LM context
135
137
  "Convert files to XML context, handling notebooks"
136
138
  fnames = [Path(o) for o in fnames]
137
- contents = [read_file(o, out=out, max_size=max_size) for o in fnames]
139
+ contents = [read_file(o, out=out, max_size=max_size, ids=ids) for o in fnames]
138
140
  return docs_xml(contents, srcs or fnames, **kwargs)
139
141
 
140
142
  # %% ../00_xml.ipynb
@@ -149,6 +151,7 @@ def folder2ctx(
149
151
  max_total:int=10_000_000, # Max total output size in bytes
150
152
  readme_first:bool=False, # Prioritize README files at start of context?
151
153
  files_only:bool=False, # Return dict of {filename: size} instead of context?
154
+ ids:bool=True, # Include cell ids in notebooks?
152
155
  **kwargs
153
156
  )->Union[str,dict]:
154
157
  "Convert folder contents to XML context, handling notebooks"
@@ -157,14 +160,14 @@ def folder2ctx(
157
160
  if files_only: return {str(f.relative_to(folder)): f.stat().st_size for f in fnames}
158
161
  if readme_first: fnames = sorted(fnames, key=lambda f: (0 if 'readme' in f.name.lower() else 1, f))
159
162
  srcs = fnames if include_base else [f.relative_to(folder) for f in fnames]
160
- res = files2ctx(fnames, prefix=prefix, out=out, srcs=srcs, title=title, max_size=max_size)
163
+ res = files2ctx(fnames, prefix=prefix, out=out, srcs=srcs, title=title, max_size=max_size, ids=ids)
161
164
  suf = f"\n\n[TRUNCATED: output size {{_outsz_}} exceeded max size {max_total} bytes]"
162
165
  if max_total and len(res) > max_total: res = truncstr(res, max_total, suf=suf, sizevar='_outsz_')
163
166
  return res
164
167
 
165
168
  # %% ../00_xml.ipynb
166
169
  def sym2file(sym):
167
- "Return (filepath, contents) for a symbol's source file"
170
+ "Return md string with filepath and contents for a symbol's source file"
168
171
  f = Path(inspect.getfile(sym))
169
172
  return f"- `{f}`\n\n````\n{f.read_text()}\n````"
170
173
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolslm
3
- Version: 0.3.14
3
+ Version: 0.3.17
4
4
  Summary: Tools to make language models a bit easier to use
5
5
  Home-page: https://github.com/AnswerDotAI/toolslm
6
6
  Author: Jeremy Howard
@@ -18,6 +18,7 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: fastcore>=1.9.7
20
20
  Requires-Dist: httpx
21
+ Requires-Dist: ghapi
21
22
  Provides-Extra: dev
22
23
  Dynamic: author
23
24
  Dynamic: author-email
@@ -1,4 +1,5 @@
1
1
  fastcore>=1.9.7
2
2
  httpx
3
+ ghapi
3
4
 
4
5
  [dev]
@@ -1 +0,0 @@
1
- __version__ = "0.3.14"
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