toolslm 0.3.8__tar.gz → 0.3.9__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.8/toolslm.egg-info → toolslm-0.3.9}/PKG-INFO +1 -1
- {toolslm-0.3.8 → toolslm-0.3.9}/settings.ini +1 -1
- toolslm-0.3.9/toolslm/__init__.py +1 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm/xml.py +25 -13
- {toolslm-0.3.8 → toolslm-0.3.9/toolslm.egg-info}/PKG-INFO +1 -1
- toolslm-0.3.8/toolslm/__init__.py +0 -1
- {toolslm-0.3.8 → toolslm-0.3.9}/LICENSE +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/MANIFEST.in +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/README.md +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/pyproject.toml +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/setup.cfg +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/setup.py +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm/_modidx.py +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm/download.py +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm/funccall.py +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm/md_hier.py +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm/shell.py +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm.egg-info/SOURCES.txt +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm.egg-info/dependency_links.txt +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm.egg-info/entry_points.txt +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm.egg-info/not-zip-safe +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm.egg-info/requires.txt +0 -0
- {toolslm-0.3.8 → toolslm-0.3.9}/toolslm.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.9"
|
|
@@ -102,48 +102,56 @@ def mk_doc(index:int, # The document index
|
|
|
102
102
|
def docs_xml(docs:list[str], # The content of each document
|
|
103
103
|
srcs:Optional[list]=None, # URLs, filenames, etc; each one defaults to `md5(content)` if not provided
|
|
104
104
|
prefix:bool=True, # Include Anthropic's suggested prose intro?
|
|
105
|
-
details:Optional[list]=None # Optional list of dicts with additional attrs for each doc
|
|
105
|
+
details:Optional[list]=None, # Optional list of dicts with additional attrs for each doc
|
|
106
|
+
title:str=None # Optional title attr for Documents element
|
|
106
107
|
)->str:
|
|
107
108
|
"Create an XML string containing `docs` in Anthropic's recommended format"
|
|
108
109
|
pre = 'Here are some documents for you to reference for your task:\n\n' if prefix else ''
|
|
109
110
|
if srcs is None: srcs = [None]*len(docs)
|
|
110
111
|
if details is None: details = [{}]*len(docs)
|
|
111
112
|
docs = (mk_doc(i+1, d, s, **kw) for i,(d,s,kw) in enumerate(zip(docs,srcs,details)))
|
|
112
|
-
|
|
113
|
+
kw = dict(title=title) if title else {}
|
|
114
|
+
return pre + to_xml(Documents(*docs, **kw), do_escape=False)
|
|
113
115
|
|
|
114
116
|
# %% ../00_xml.ipynb
|
|
115
|
-
def read_file(fname, out=True):
|
|
117
|
+
def read_file(fname, out=True, max_size=None):
|
|
116
118
|
"Read file content, converting notebooks to XML if needed"
|
|
117
119
|
fname = Path(fname)
|
|
118
|
-
if fname.suffix == '.ipynb':
|
|
119
|
-
|
|
120
|
+
if fname.suffix == '.ipynb': res = nb2xml(fname, out=out)
|
|
121
|
+
else: res = fname.read_text()
|
|
122
|
+
if max_size and len(res)>max_size: return f"[Skipped: {fname.name} exceeds {max_size} bytes]"
|
|
123
|
+
return res
|
|
120
124
|
|
|
121
125
|
# %% ../00_xml.ipynb
|
|
122
126
|
def files2ctx(
|
|
123
127
|
fnames:list[Union[str,Path]], # List of file names to add to context
|
|
124
128
|
prefix:bool=True, # Include Anthropic's suggested prose intro?
|
|
125
129
|
out:bool=True, # Include notebook cell outputs?
|
|
126
|
-
srcs:Optional[list]=None # Use the labels instead of `fnames`
|
|
130
|
+
srcs:Optional[list]=None, # Use the labels instead of `fnames`
|
|
131
|
+
title:str=None, # Optional title attr for Documents element
|
|
132
|
+
max_size:int=None # Skip files larger than this (bytes)
|
|
127
133
|
)->str: # XML for LM context
|
|
128
134
|
"Convert files to XML context, handling notebooks"
|
|
129
135
|
fnames = [Path(o) for o in fnames]
|
|
130
|
-
contents = [read_file(o, out=out) for o in fnames]
|
|
131
|
-
return docs_xml(contents, srcs or fnames, prefix=prefix)
|
|
136
|
+
contents = [read_file(o, out=out, max_size=max_size) for o in fnames]
|
|
137
|
+
return docs_xml(contents, srcs or fnames, prefix=prefix, title=title)
|
|
132
138
|
|
|
133
139
|
# %% ../00_xml.ipynb
|
|
134
140
|
@delegates(globtastic)
|
|
135
141
|
def folder2ctx(
|
|
136
142
|
folder:Union[str,Path],
|
|
137
|
-
prefix:bool=True,
|
|
138
|
-
out:bool=True,
|
|
139
|
-
include_base:bool=True,
|
|
143
|
+
prefix:bool=True, # Include Anthropic's suggested prose intro?
|
|
144
|
+
out:bool=True, # Include notebook cell outputs?
|
|
145
|
+
include_base:bool=True, # Include full path in src?
|
|
146
|
+
title:str=None, # Optional title attr for Documents element
|
|
147
|
+
max_size:int=100_000, # Skip files larger than this (bytes)
|
|
140
148
|
**kwargs
|
|
141
149
|
)->str:
|
|
142
150
|
"Convert folder contents to XML context, handling notebooks"
|
|
143
151
|
folder = Path(folder)
|
|
144
152
|
fnames = globtastic(folder, **kwargs)
|
|
145
153
|
srcs = fnames if include_base else [Path(f).relative_to(folder) for f in fnames]
|
|
146
|
-
return files2ctx(fnames, prefix=prefix, out=out, srcs=srcs)
|
|
154
|
+
return files2ctx(fnames, prefix=prefix, out=out, srcs=srcs, title=title, max_size=max_size)
|
|
147
155
|
|
|
148
156
|
# %% ../00_xml.ipynb
|
|
149
157
|
@delegates(folder2ctx)
|
|
@@ -158,11 +166,15 @@ def repo2ctx(
|
|
|
158
166
|
api = GhApi()
|
|
159
167
|
if ref is None: ref = api.repos.get(owner, repo).default_branch
|
|
160
168
|
data = api.repos.download_tarball_archive(owner, repo, ref)
|
|
169
|
+
parts = ' | '.join(f"{k}: {', '.join(v) if isinstance(v, (list,tuple)) else v}"
|
|
170
|
+
for k,v in kwargs.items() if v)
|
|
171
|
+
title = f"GitHub repository contents from {owner}/{repo} at ref '{ref}'"
|
|
172
|
+
if parts: title += f" (filters applied: {parts})"
|
|
161
173
|
tf = tarfile.open(fileobj=io.BytesIO(data))
|
|
162
174
|
with tempfile.TemporaryDirectory() as tmp:
|
|
163
175
|
tf.extractall(tmp, filter='data')
|
|
164
176
|
subdir = Path(tmp) / tf.getmembers()[0].name.split('/')[0]
|
|
165
|
-
return folder2ctx(subdir, include_base=False, **kwargs)
|
|
177
|
+
return folder2ctx(subdir, include_base=False, title=title, **kwargs)
|
|
166
178
|
|
|
167
179
|
# %% ../00_xml.ipynb
|
|
168
180
|
@call_parse
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.3.8"
|
|
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
|
|
File without changes
|
|
File without changes
|