toolslm 0.0.2__py3-none-any.whl → 0.0.3__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/_modidx.py +7 -1
- toolslm/{lmcode.py → funccall.py} +47 -6
- {toolslm-0.0.2.dist-info → toolslm-0.0.3.dist-info}/METADATA +1 -1
- toolslm-0.0.3.dist-info/RECORD +11 -0
- toolslm-0.0.2.dist-info/RECORD +0 -11
- {toolslm-0.0.2.dist-info → toolslm-0.0.3.dist-info}/LICENSE +0 -0
- {toolslm-0.0.2.dist-info → toolslm-0.0.3.dist-info}/WHEEL +0 -0
- {toolslm-0.0.2.dist-info → toolslm-0.0.3.dist-info}/entry_points.txt +0 -0
- {toolslm-0.0.2.dist-info → toolslm-0.0.3.dist-info}/top_level.txt +0 -0
toolslm/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.3"
|
toolslm/_modidx.py
CHANGED
|
@@ -5,7 +5,13 @@ d = { 'settings': { 'branch': 'main',
|
|
|
5
5
|
'doc_host': 'https://AnswerDotAI.github.io',
|
|
6
6
|
'git_url': 'https://github.com/AnswerDotAI/toolslm',
|
|
7
7
|
'lib_path': 'toolslm'},
|
|
8
|
-
'syms': { 'toolslm.
|
|
8
|
+
'syms': { 'toolslm.funccall': { 'toolslm.funccall._copy_loc': ('funccall.html#_copy_loc', 'toolslm/funccall.py'),
|
|
9
|
+
'toolslm.funccall._param': ('funccall.html#_param', 'toolslm/funccall.py'),
|
|
10
|
+
'toolslm.funccall._run': ('funccall.html#_run', 'toolslm/funccall.py'),
|
|
11
|
+
'toolslm.funccall._types': ('funccall.html#_types', 'toolslm/funccall.py'),
|
|
12
|
+
'toolslm.funccall.get_schema': ('funccall.html#get_schema', 'toolslm/funccall.py'),
|
|
13
|
+
'toolslm.funccall.python': ('funccall.html#python', 'toolslm/funccall.py')},
|
|
14
|
+
'toolslm.lmcode': { 'toolslm.lmcode._copy_loc': ('lmcode.html#_copy_loc', 'toolslm/lmcode.py'),
|
|
9
15
|
'toolslm.lmcode._run': ('lmcode.html#_run', 'toolslm/lmcode.py'),
|
|
10
16
|
'toolslm.lmcode.python': ('lmcode.html#python', 'toolslm/lmcode.py')},
|
|
11
17
|
'toolslm.shell': { 'toolslm.shell.TerminalInteractiveShell.run_cell': ( 'shell.html#terminalinteractiveshell.run_cell',
|
|
@@ -1,13 +1,54 @@
|
|
|
1
|
-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../
|
|
1
|
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../01_funccall.ipynb.
|
|
2
2
|
|
|
3
3
|
# %% auto 0
|
|
4
|
-
__all__ = ['python']
|
|
4
|
+
__all__ = ['empty', 'get_schema', 'python']
|
|
5
5
|
|
|
6
|
-
# %% ../
|
|
6
|
+
# %% ../01_funccall.ipynb 2
|
|
7
|
+
import inspect
|
|
8
|
+
from fastcore.utils import *
|
|
9
|
+
from fastcore.docments import docments
|
|
10
|
+
|
|
11
|
+
# %% ../01_funccall.ipynb 3
|
|
12
|
+
empty = inspect.Parameter.empty
|
|
13
|
+
|
|
14
|
+
# %% ../01_funccall.ipynb 11
|
|
15
|
+
def _types(t:type)->tuple[str,Optional[str]]:
|
|
16
|
+
"Tuple of json schema type name and (if appropriate) array item name."
|
|
17
|
+
if t is empty: raise TypeError('Missing type')
|
|
18
|
+
tmap = {int:"integer", float:"number", str:"string", bool:"boolean", list:"array", dict:"object"}
|
|
19
|
+
if getattr(t, '__origin__', None) in (list,tuple): return "array", tmap.get(t.__args__[0], "object")
|
|
20
|
+
else: return tmap[t], None
|
|
21
|
+
|
|
22
|
+
# %% ../01_funccall.ipynb 14
|
|
23
|
+
def _param(name, info):
|
|
24
|
+
"json schema parameter given `name` and `info` from docments full dict."
|
|
25
|
+
paramt,itemt = _types(info.anno)
|
|
26
|
+
pschema = dict(type=paramt, description=info.docment or "")
|
|
27
|
+
if itemt: pschema["items"] = {"type": itemt}
|
|
28
|
+
if info.default is not empty: pschema["default"] = info.default
|
|
29
|
+
return pschema
|
|
30
|
+
|
|
31
|
+
# %% ../01_funccall.ipynb 17
|
|
32
|
+
def get_schema(f:callable)->dict:
|
|
33
|
+
"Convert function `f` into a JSON schema `dict` for tool use."
|
|
34
|
+
d = docments(f, full=True)
|
|
35
|
+
ret = d.pop('return')
|
|
36
|
+
d.pop('self', None) # Ignore `self` for methods
|
|
37
|
+
paramd = {
|
|
38
|
+
'type': "object",
|
|
39
|
+
'properties': {n:_param(n,o) for n,o in d.items() if n[0]!='_'},
|
|
40
|
+
'required': [n for n,o in d.items() if o.default is empty and n[0]!='_']
|
|
41
|
+
}
|
|
42
|
+
desc = f.__doc__
|
|
43
|
+
if ret.anno is not empty: desc += f'\n\nReturns:\n- type: {_types(ret.anno)[0]}'
|
|
44
|
+
if ret.docment: desc += f'\n- description: {ret.docment}'
|
|
45
|
+
return dict(name=f.__name__, description=desc or "", input_schema=paramd)
|
|
46
|
+
|
|
47
|
+
# %% ../01_funccall.ipynb 22
|
|
7
48
|
import ast, time, signal, traceback
|
|
8
49
|
from fastcore.utils import *
|
|
9
50
|
|
|
10
|
-
# %% ../
|
|
51
|
+
# %% ../01_funccall.ipynb 23
|
|
11
52
|
def _copy_loc(new, orig):
|
|
12
53
|
"Copy location information from original node to new node and all children."
|
|
13
54
|
new = ast.copy_location(new, orig)
|
|
@@ -16,7 +57,7 @@ def _copy_loc(new, orig):
|
|
|
16
57
|
elif isinstance(o, list): setattr(new, field, [_copy_loc(value, orig) for value in o])
|
|
17
58
|
return new
|
|
18
59
|
|
|
19
|
-
# %% ../
|
|
60
|
+
# %% ../01_funccall.ipynb 25
|
|
20
61
|
def _run(code:str ):
|
|
21
62
|
"Run `code`, returning final expression (similar to IPython)"
|
|
22
63
|
tree = ast.parse(code)
|
|
@@ -39,7 +80,7 @@ def _run(code:str ):
|
|
|
39
80
|
if _result is not None: return _result
|
|
40
81
|
return stdout_buffer.getvalue().strip()
|
|
41
82
|
|
|
42
|
-
# %% ../
|
|
83
|
+
# %% ../01_funccall.ipynb 30
|
|
43
84
|
def python(code, # Code to execute
|
|
44
85
|
timeout=5 # Maximum run time in seconds before a `TimeoutError` is raised
|
|
45
86
|
): # Result of last node, if it's an expression, or `None` otherwise
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
toolslm/__init__.py,sha256=4GZKi13lDTD25YBkGakhZyEQZWTER_OWQMNPoH_UM2c,22
|
|
2
|
+
toolslm/_modidx.py,sha256=mf2R89-fA85sjtgETrs_981ZiKBXwlnfWSo7FYPQDBg,2531
|
|
3
|
+
toolslm/funccall.py,sha256=VLJ16OPeyv4QwMY6pTOGig0uep2QbEvN4lXIk3OfqEw,3809
|
|
4
|
+
toolslm/shell.py,sha256=GVqfL74NHw66zzZ7jvGVLjE55ZNJGBPvEb8kLz4aoYc,1576
|
|
5
|
+
toolslm/xml.py,sha256=4DnFUYG09fB1ZTzcyeugKdkMU40MMMf3zZEHbDfSGIo,4635
|
|
6
|
+
toolslm-0.0.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
+
toolslm-0.0.3.dist-info/METADATA,sha256=xdGav82GXXWNJUDvGg2Hr6WXrDmUHR3zXeJ45FUC4J8,3773
|
|
8
|
+
toolslm-0.0.3.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
9
|
+
toolslm-0.0.3.dist-info/entry_points.txt,sha256=3os5YWuvVIFuweYaNtnwgv-xCe4Gb1KcZndFz8KWI0E,36
|
|
10
|
+
toolslm-0.0.3.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
11
|
+
toolslm-0.0.3.dist-info/RECORD,,
|
toolslm-0.0.2.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
toolslm/__init__.py,sha256=QvlVh4JTl3JL7jQAja76yKtT-IvF4631ASjWY1wS6AQ,22
|
|
2
|
-
toolslm/_modidx.py,sha256=fmKi8RF2pdYu9iFlVY__PTCgOTaWgWYqUfrQBjimhxA,1860
|
|
3
|
-
toolslm/lmcode.py,sha256=G28x34SsxQPGhSNGHggXh6dWaeGlxQH69nAu9tgdNF8,2104
|
|
4
|
-
toolslm/shell.py,sha256=GVqfL74NHw66zzZ7jvGVLjE55ZNJGBPvEb8kLz4aoYc,1576
|
|
5
|
-
toolslm/xml.py,sha256=4DnFUYG09fB1ZTzcyeugKdkMU40MMMf3zZEHbDfSGIo,4635
|
|
6
|
-
toolslm-0.0.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
7
|
-
toolslm-0.0.2.dist-info/METADATA,sha256=KHlZaY6NAr7a0DCNTeq6rHxaJO5cze8jciBAT4Z7C-g,3773
|
|
8
|
-
toolslm-0.0.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
9
|
-
toolslm-0.0.2.dist-info/entry_points.txt,sha256=3os5YWuvVIFuweYaNtnwgv-xCe4Gb1KcZndFz8KWI0E,36
|
|
10
|
-
toolslm-0.0.2.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
11
|
-
toolslm-0.0.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|