toolslm 0.0.3__tar.gz → 0.0.4__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.0.3/toolslm.egg-info → toolslm-0.0.4}/PKG-INFO +2 -2
- {toolslm-0.0.3 → toolslm-0.0.4}/settings.ini +3 -3
- toolslm-0.0.4/toolslm/__init__.py +1 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm/_modidx.py +2 -7
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm/funccall.py +3 -2
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm/xml.py +38 -51
- {toolslm-0.0.3 → toolslm-0.0.4/toolslm.egg-info}/PKG-INFO +2 -2
- toolslm-0.0.4/toolslm.egg-info/entry_points.txt +5 -0
- toolslm-0.0.4/toolslm.egg-info/requires.txt +3 -0
- toolslm-0.0.3/toolslm/__init__.py +0 -1
- toolslm-0.0.3/toolslm.egg-info/entry_points.txt +0 -2
- toolslm-0.0.3/toolslm.egg-info/requires.txt +0 -3
- {toolslm-0.0.3 → toolslm-0.0.4}/LICENSE +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/MANIFEST.in +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/README.md +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/setup.cfg +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/setup.py +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm/shell.py +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm.egg-info/SOURCES.txt +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm.egg-info/dependency_links.txt +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm.egg-info/not-zip-safe +0 -0
- {toolslm-0.0.3 → toolslm-0.0.4}/toolslm.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: toolslm
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
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
|
|
@@ -16,7 +16,7 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
16
16
|
Requires-Python: >=3.9
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: fastcore
|
|
19
|
+
Requires-Dist: fastcore>=1.5.47
|
|
20
20
|
Provides-Extra: dev
|
|
21
21
|
|
|
22
22
|
# toolslm
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[DEFAULT]
|
|
2
2
|
repo = toolslm
|
|
3
3
|
lib_name = toolslm
|
|
4
|
-
version = 0.0.
|
|
4
|
+
version = 0.0.4
|
|
5
5
|
min_python = 3.9
|
|
6
6
|
license = apache2
|
|
7
7
|
black_formatting = False
|
|
8
|
-
requirements = fastcore
|
|
8
|
+
requirements = fastcore>=1.5.47
|
|
9
9
|
doc_path = _docs
|
|
10
10
|
lib_path = toolslm
|
|
11
11
|
nbs_path = .
|
|
@@ -34,4 +34,4 @@ jupyter_hooks = True
|
|
|
34
34
|
clean_ids = True
|
|
35
35
|
clear_all = False
|
|
36
36
|
conda_user = fastai
|
|
37
|
-
|
|
37
|
+
console_scripts = folder2ctx=toolslm.xml:folder2ctx_cli
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.4"
|
|
@@ -11,9 +11,6 @@ d = { 'settings': { 'branch': 'main',
|
|
|
11
11
|
'toolslm.funccall._types': ('funccall.html#_types', 'toolslm/funccall.py'),
|
|
12
12
|
'toolslm.funccall.get_schema': ('funccall.html#get_schema', 'toolslm/funccall.py'),
|
|
13
13
|
'toolslm.funccall.python': ('funccall.html#python', 'toolslm/funccall.py')},
|
|
14
|
-
'toolslm.lmcode': { 'toolslm.lmcode._copy_loc': ('lmcode.html#_copy_loc', 'toolslm/lmcode.py'),
|
|
15
|
-
'toolslm.lmcode._run': ('lmcode.html#_run', 'toolslm/lmcode.py'),
|
|
16
|
-
'toolslm.lmcode.python': ('lmcode.html#python', 'toolslm/lmcode.py')},
|
|
17
14
|
'toolslm.shell': { 'toolslm.shell.TerminalInteractiveShell.run_cell': ( 'shell.html#terminalinteractiveshell.run_cell',
|
|
18
15
|
'toolslm/shell.py'),
|
|
19
16
|
'toolslm.shell.get_shell': ('shell.html#get_shell', 'toolslm/shell.py')},
|
|
@@ -21,9 +18,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
21
18
|
'toolslm.xml.docs_xml': ('xml.html#docs_xml', 'toolslm/xml.py'),
|
|
22
19
|
'toolslm.xml.files2ctx': ('xml.html#files2ctx', 'toolslm/xml.py'),
|
|
23
20
|
'toolslm.xml.folder2ctx': ('xml.html#folder2ctx', 'toolslm/xml.py'),
|
|
24
|
-
'toolslm.xml.
|
|
21
|
+
'toolslm.xml.folder2ctx_cli': ('xml.html#folder2ctx_cli', 'toolslm/xml.py'),
|
|
25
22
|
'toolslm.xml.json_to_xml': ('xml.html#json_to_xml', 'toolslm/xml.py'),
|
|
26
23
|
'toolslm.xml.mk_doc': ('xml.html#mk_doc', 'toolslm/xml.py'),
|
|
27
|
-
'toolslm.xml.mk_doctype': ('xml.html#mk_doctype', 'toolslm/xml.py')
|
|
28
|
-
'toolslm.xml.to_xml': ('xml.html#to_xml', 'toolslm/xml.py'),
|
|
29
|
-
'toolslm.xml.xt': ('xml.html#xt', 'toolslm/xml.py')}}}
|
|
24
|
+
'toolslm.xml.mk_doctype': ('xml.html#mk_doctype', 'toolslm/xml.py')}}}
|
|
@@ -29,7 +29,7 @@ def _param(name, info):
|
|
|
29
29
|
return pschema
|
|
30
30
|
|
|
31
31
|
# %% ../01_funccall.ipynb 17
|
|
32
|
-
def get_schema(f:callable)->dict:
|
|
32
|
+
def get_schema(f:callable, pname='input_schema')->dict:
|
|
33
33
|
"Convert function `f` into a JSON schema `dict` for tool use."
|
|
34
34
|
d = docments(f, full=True)
|
|
35
35
|
ret = d.pop('return')
|
|
@@ -40,9 +40,10 @@ def get_schema(f:callable)->dict:
|
|
|
40
40
|
'required': [n for n,o in d.items() if o.default is empty and n[0]!='_']
|
|
41
41
|
}
|
|
42
42
|
desc = f.__doc__
|
|
43
|
+
assert desc, "Docstring missing!"
|
|
43
44
|
if ret.anno is not empty: desc += f'\n\nReturns:\n- type: {_types(ret.anno)[0]}'
|
|
44
45
|
if ret.docment: desc += f'\n- description: {ret.docment}'
|
|
45
|
-
return
|
|
46
|
+
return {'name':f.__name__, 'description':desc, pname:paramd}
|
|
46
47
|
|
|
47
48
|
# %% ../01_funccall.ipynb 22
|
|
48
49
|
import ast, time, signal, traceback
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../00_xml.ipynb.
|
|
2
2
|
|
|
3
3
|
# %% auto 0
|
|
4
|
-
__all__ = ['
|
|
5
|
-
'folder2ctx']
|
|
4
|
+
__all__ = ['doctype', 'json_to_xml', 'mk_doctype', 'mk_doc', 'docs_xml', 'files2ctx', 'folder2ctx', 'folder2ctx_cli']
|
|
6
5
|
|
|
7
6
|
# %% ../00_xml.ipynb 3
|
|
8
7
|
import hashlib,xml.etree.ElementTree as ET
|
|
@@ -10,45 +9,13 @@ from collections import namedtuple
|
|
|
10
9
|
|
|
11
10
|
from fastcore.utils import *
|
|
12
11
|
from fastcore.meta import delegates
|
|
12
|
+
from fastcore.xtras import hl_md
|
|
13
|
+
from fastcore.xml import to_xml, Document, Documents, Document_content, Source
|
|
14
|
+
from fastcore.script import call_parse
|
|
13
15
|
try: from IPython import display
|
|
14
16
|
except: display=None
|
|
15
17
|
|
|
16
|
-
# %% ../00_xml.ipynb
|
|
17
|
-
def xt(tag:str, # XML tag name
|
|
18
|
-
c:Optional[list]=None, # Children
|
|
19
|
-
**kw):
|
|
20
|
-
"Helper to create appropriate data structure for `to_xml`."
|
|
21
|
-
kw = {k.lstrip('_'):str(v) for k,v in kw.items()}
|
|
22
|
-
return tag,c,kw
|
|
23
|
-
|
|
24
|
-
# %% ../00_xml.ipynb 9
|
|
25
|
-
g = globals()
|
|
26
|
-
tags = 'div img h1 h2 h3 h4 h5 p hr span html'.split()
|
|
27
|
-
for o in tags: g[o] = partial(xt, o)
|
|
28
|
-
|
|
29
|
-
# %% ../00_xml.ipynb 12
|
|
30
|
-
def hl_md(s, lang='xml'):
|
|
31
|
-
"Syntax highlight `s` using `lang`."
|
|
32
|
-
if display: return display.Markdown(f'```{lang}\n{s}\n```')
|
|
33
|
-
print(s)
|
|
34
|
-
|
|
35
|
-
# %% ../00_xml.ipynb 15
|
|
36
|
-
def to_xml(node:tuple, # XML structure in `xt` format
|
|
37
|
-
hl=False # Syntax highlight response?
|
|
38
|
-
):
|
|
39
|
-
"Convert `node` to an XML string."
|
|
40
|
-
def mk_el(tag, cs, attrs):
|
|
41
|
-
el = ET.Element(tag, attrib=attrs)
|
|
42
|
-
if isinstance(cs, list): el.extend([mk_el(*o) for o in cs])
|
|
43
|
-
elif cs is not None: el.text = str(cs)
|
|
44
|
-
return el
|
|
45
|
-
|
|
46
|
-
root = mk_el(*node)
|
|
47
|
-
ET.indent(root, space=' ' if hl else '')
|
|
48
|
-
res = ET.tostring(root, encoding='unicode')
|
|
49
|
-
return hl_md(res) if hl else res
|
|
50
|
-
|
|
51
|
-
# %% ../00_xml.ipynb 18
|
|
18
|
+
# %% ../00_xml.ipynb 4
|
|
52
19
|
def json_to_xml(d:dict, # JSON dictionary to convert
|
|
53
20
|
rnm:str # Root name
|
|
54
21
|
)->str:
|
|
@@ -64,17 +31,17 @@ def json_to_xml(d:dict, # JSON dictionary to convert
|
|
|
64
31
|
ET.indent(root)
|
|
65
32
|
return ET.tostring(root, encoding='unicode')
|
|
66
33
|
|
|
67
|
-
# %% ../00_xml.ipynb
|
|
34
|
+
# %% ../00_xml.ipynb 9
|
|
68
35
|
doctype = namedtuple('doctype', ['source', 'content'])
|
|
69
36
|
|
|
70
|
-
# %% ../00_xml.ipynb
|
|
37
|
+
# %% ../00_xml.ipynb 11
|
|
71
38
|
def _add_nls(s):
|
|
72
39
|
"Add newlines to start and end of `s` if missing"
|
|
73
40
|
if s[ 0]!='\n': s = '\n'+s
|
|
74
41
|
if s[-1]!='\n': s = s+'\n'
|
|
75
42
|
return s
|
|
76
43
|
|
|
77
|
-
# %% ../00_xml.ipynb
|
|
44
|
+
# %% ../00_xml.ipynb 13
|
|
78
45
|
def mk_doctype(content:str, # The document content
|
|
79
46
|
source:Optional[str]=None # URL, filename, etc; defaults to `md5(content)` if not provided
|
|
80
47
|
) -> namedtuple:
|
|
@@ -82,18 +49,29 @@ def mk_doctype(content:str, # The document content
|
|
|
82
49
|
if source is None: source = hashlib.md5(content.encode()).hexdigest()[:8]
|
|
83
50
|
return doctype(_add_nls(str(source).strip()), _add_nls(content.strip()))
|
|
84
51
|
|
|
85
|
-
# %% ../00_xml.ipynb
|
|
52
|
+
# %% ../00_xml.ipynb 17
|
|
86
53
|
def mk_doc(index:int, # The document index
|
|
87
54
|
content:str, # The document content
|
|
88
55
|
source:Optional[str]=None # URL, filename, etc; defaults to `md5(content)` if not provided
|
|
89
56
|
) -> tuple:
|
|
90
|
-
"Create an `
|
|
57
|
+
"Create an `ft` format tuple for a single doc in Anthropic's recommended format"
|
|
91
58
|
dt = mk_doctype(content, source)
|
|
92
|
-
content =
|
|
93
|
-
source =
|
|
94
|
-
return
|
|
59
|
+
content = ft('document_content', dt.content)
|
|
60
|
+
source = ft('source', dt.source)
|
|
61
|
+
return ft('document', source, content, index=index)
|
|
95
62
|
|
|
96
|
-
# %% ../00_xml.ipynb
|
|
63
|
+
# %% ../00_xml.ipynb 18
|
|
64
|
+
def mk_doc(index:int, # The document index
|
|
65
|
+
content:str, # The document content
|
|
66
|
+
source:Optional[str]=None # URL, filename, etc; defaults to `md5(content)` if not provided
|
|
67
|
+
) -> tuple:
|
|
68
|
+
"Create an `ft` format tuple for a single doc in Anthropic's recommended format"
|
|
69
|
+
dt = mk_doctype(content, source)
|
|
70
|
+
content = Document_content(dt.content)
|
|
71
|
+
source = Source(dt.source)
|
|
72
|
+
return Document(source, content, index=index)
|
|
73
|
+
|
|
74
|
+
# %% ../00_xml.ipynb 22
|
|
97
75
|
def docs_xml(docs:list[str], # The content of each document
|
|
98
76
|
sources:Optional[list]=None, # URLs, filenames, etc; each one defaults to `md5(content)` if not provided
|
|
99
77
|
prefix:bool=True # Include Anthropic's suggested prose intro?
|
|
@@ -101,10 +79,10 @@ def docs_xml(docs:list[str], # The content of each document
|
|
|
101
79
|
"Create an XML string containing `docs` in Anthropic's recommended format"
|
|
102
80
|
pre = 'Here are some documents for you to reference for your task:\n\n' if prefix else ''
|
|
103
81
|
if sources is None: sources = [None]*len(docs)
|
|
104
|
-
docs =
|
|
105
|
-
return pre + to_xml(
|
|
82
|
+
docs = (mk_doc(i+1, *o) for i,o in enumerate(zip(docs,sources)))
|
|
83
|
+
return pre + to_xml(Documents(docs))
|
|
106
84
|
|
|
107
|
-
# %% ../00_xml.ipynb
|
|
85
|
+
# %% ../00_xml.ipynb 29
|
|
108
86
|
def files2ctx(
|
|
109
87
|
fnames:list[Union[str,Path]], # List of file names to add to context
|
|
110
88
|
prefix:bool=True # Include Anthropic's suggested prose intro?
|
|
@@ -113,7 +91,7 @@ def files2ctx(
|
|
|
113
91
|
contents = [o.read_text() for o in fnames]
|
|
114
92
|
return docs_xml(contents, fnames, prefix=prefix)
|
|
115
93
|
|
|
116
|
-
# %% ../00_xml.ipynb
|
|
94
|
+
# %% ../00_xml.ipynb 32
|
|
117
95
|
@delegates(globtastic)
|
|
118
96
|
def folder2ctx(
|
|
119
97
|
folder:Union[str,Path], # Folder name containing files to add to context
|
|
@@ -122,3 +100,12 @@ def folder2ctx(
|
|
|
122
100
|
)->str: # XML for Claude context
|
|
123
101
|
fnames = globtastic(folder, **kwargs)
|
|
124
102
|
return files2ctx(fnames, prefix=prefix)
|
|
103
|
+
|
|
104
|
+
# %% ../00_xml.ipynb 34
|
|
105
|
+
@call_parse
|
|
106
|
+
@delegates(folder2ctx)
|
|
107
|
+
def folder2ctx_cli(
|
|
108
|
+
folder:str, # Folder name containing files to add to context
|
|
109
|
+
**kwargs # Passed to `folder2ctx`
|
|
110
|
+
)->str: # XML for Claude context
|
|
111
|
+
return folder2ctx(folder, **kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: toolslm
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
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
|
|
@@ -16,7 +16,7 @@ Classifier: License :: OSI Approved :: Apache Software License
|
|
|
16
16
|
Requires-Python: >=3.9
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: fastcore
|
|
19
|
+
Requires-Dist: fastcore>=1.5.47
|
|
20
20
|
Provides-Extra: dev
|
|
21
21
|
|
|
22
22
|
# toolslm
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.3"
|
|
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
|