toolslm 0.3.9__py3-none-any.whl → 0.3.11__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/funccall.py +24 -11
- {toolslm-0.3.9.dist-info → toolslm-0.3.11.dist-info}/METADATA +1 -1
- toolslm-0.3.11.dist-info/RECORD +13 -0
- toolslm-0.3.9.dist-info/RECORD +0 -13
- {toolslm-0.3.9.dist-info → toolslm-0.3.11.dist-info}/WHEEL +0 -0
- {toolslm-0.3.9.dist-info → toolslm-0.3.11.dist-info}/entry_points.txt +0 -0
- {toolslm-0.3.9.dist-info → toolslm-0.3.11.dist-info}/licenses/LICENSE +0 -0
- {toolslm-0.3.9.dist-info → toolslm-0.3.11.dist-info}/top_level.txt +0 -0
toolslm/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.3.
|
|
1
|
+
__version__ = "0.3.11"
|
toolslm/funccall.py
CHANGED
|
@@ -5,7 +5,7 @@ __all__ = ['empty', 'custom_types', 'get_schema', 'python', 'mk_ns', 'call_func'
|
|
|
5
5
|
'mk_tool']
|
|
6
6
|
|
|
7
7
|
# %% ../01_funccall.ipynb
|
|
8
|
-
import inspect, json
|
|
8
|
+
import inspect, json, ast
|
|
9
9
|
from collections import abc
|
|
10
10
|
from fastcore.utils import *
|
|
11
11
|
from fastcore.docments import docments
|
|
@@ -37,12 +37,20 @@ def _types(t:type)->tuple[str,Optional[str]]:
|
|
|
37
37
|
else: return tmap.get(t.__name__, "object"), None
|
|
38
38
|
|
|
39
39
|
# %% ../01_funccall.ipynb
|
|
40
|
-
def _param(
|
|
41
|
-
|
|
40
|
+
def _param(
|
|
41
|
+
name, # param name
|
|
42
|
+
info, # dict from docments
|
|
43
|
+
evalable=False): # stringify defaults that can't be literal_eval'd?
|
|
44
|
+
"json schema parameter given `name` and `info` from docments full dict"
|
|
42
45
|
paramt,itemt = _types(info.anno)
|
|
43
46
|
pschema = dict(type=paramt, description=info.docment or "")
|
|
44
47
|
if itemt: pschema["items"] = {"type": itemt}
|
|
45
|
-
if info.default is not empty:
|
|
48
|
+
if info.default is not empty:
|
|
49
|
+
if evalable:
|
|
50
|
+
try: ast.literal_eval(repr(info.default))
|
|
51
|
+
except: pschema["default"] = str(info.default)
|
|
52
|
+
else: pschema["default"] = info.default
|
|
53
|
+
else: pschema["default"] = info.default
|
|
46
54
|
return pschema
|
|
47
55
|
|
|
48
56
|
# %% ../01_funccall.ipynb
|
|
@@ -90,9 +98,9 @@ def _handle_container(origin, args, defs):
|
|
|
90
98
|
return None
|
|
91
99
|
|
|
92
100
|
# %% ../01_funccall.ipynb
|
|
93
|
-
def _process_property(name, obj, props, req, defs):
|
|
101
|
+
def _process_property(name, obj, props, req, defs, evalable=False):
|
|
94
102
|
"Process a single property of the schema"
|
|
95
|
-
p = _param(name, obj)
|
|
103
|
+
p = _param(name, obj, evalable=evalable)
|
|
96
104
|
props[name] = p
|
|
97
105
|
if obj.default is empty: req[name] = True
|
|
98
106
|
|
|
@@ -103,14 +111,14 @@ def _process_property(name, obj, props, req, defs):
|
|
|
103
111
|
p.update(_handle_type(obj.anno, defs))
|
|
104
112
|
|
|
105
113
|
# %% ../01_funccall.ipynb
|
|
106
|
-
def _get_nested_schema(obj):
|
|
114
|
+
def _get_nested_schema(obj, evalable=False, skip_hidden=False):
|
|
107
115
|
"Generate nested JSON schema for a class or function"
|
|
108
116
|
d = docments(obj, full=True)
|
|
109
117
|
props, req, defs = {}, {}, {}
|
|
110
118
|
|
|
111
119
|
for n, o in d.items():
|
|
112
|
-
if n != 'return' and n != 'self':
|
|
113
|
-
_process_property(n, o, props, req, defs)
|
|
120
|
+
if n != 'return' and n != 'self' and not (skip_hidden and n.startswith('_')):
|
|
121
|
+
_process_property(n, o, props, req, defs, evalable=evalable)
|
|
114
122
|
|
|
115
123
|
tkw = {}
|
|
116
124
|
if isinstance(obj, type): tkw['title']=obj.__name__
|
|
@@ -120,10 +128,15 @@ def _get_nested_schema(obj):
|
|
|
120
128
|
return schema
|
|
121
129
|
|
|
122
130
|
# %% ../01_funccall.ipynb
|
|
123
|
-
def get_schema(
|
|
131
|
+
def get_schema(
|
|
132
|
+
f:Union[callable,dict], # Function to get schema for
|
|
133
|
+
pname='input_schema', # Key name for parameters
|
|
134
|
+
evalable=False, # stringify defaults that can't be literal_eval'd?
|
|
135
|
+
skip_hidden=False # skip parameters starting with '_'?
|
|
136
|
+
)->dict: # {'name':..., 'description':..., pname:...}
|
|
124
137
|
"Generate JSON schema for a class, function, or method"
|
|
125
138
|
if isinstance(f, dict): return f
|
|
126
|
-
schema = _get_nested_schema(f)
|
|
139
|
+
schema = _get_nested_schema(f, evalable=evalable, skip_hidden=skip_hidden)
|
|
127
140
|
desc = f.__doc__
|
|
128
141
|
assert desc, "Docstring missing!"
|
|
129
142
|
d = docments(f, full=True)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
toolslm/__init__.py,sha256=TESjMH0a_iUkwdfWT4nyzKizSFmmCY2omxnS2XyT97Y,23
|
|
2
|
+
toolslm/_modidx.py,sha256=kpgsDpj-Tvn90wezrHaMttyzhNcyNVgw_dQgK10qotI,5308
|
|
3
|
+
toolslm/download.py,sha256=g3BxUSxylC_575M7RFSJ1GI3Co3EwPDdEeWzxaf2Czk,4451
|
|
4
|
+
toolslm/funccall.py,sha256=_5TyhTjWaWLi-eJ96-4P3_faFv6Ft07nO60UjCF-bPU,11160
|
|
5
|
+
toolslm/md_hier.py,sha256=r_NPezhgfxjRmSYFlu_ND42hXt1qSbaPWHTcjbviOn4,11010
|
|
6
|
+
toolslm/shell.py,sha256=dGInuRKvexu21VmtZkw_0S3BGiTsbAongUG-yG4YHpc,1566
|
|
7
|
+
toolslm/xml.py,sha256=tAHoqXrTRiX8i3pR-9KpHoBb8QXJ_TKEVyTEOPviudE,8095
|
|
8
|
+
toolslm-0.3.11.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
toolslm-0.3.11.dist-info/METADATA,sha256=LrsRNEumsWCi0JnHLTn73b8GoqjwQ3m6mDak4n2h47g,2404
|
|
10
|
+
toolslm-0.3.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
toolslm-0.3.11.dist-info/entry_points.txt,sha256=xFz0Eymlo5X7BGpaO6DI9gMxvN5A7faebzrlr8ctp5I,95
|
|
12
|
+
toolslm-0.3.11.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
13
|
+
toolslm-0.3.11.dist-info/RECORD,,
|
toolslm-0.3.9.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
toolslm/__init__.py,sha256=xmkmdvq15kb61xdtCoa1YARnvHBnUgI-0GWIJYvHNeA,22
|
|
2
|
-
toolslm/_modidx.py,sha256=kpgsDpj-Tvn90wezrHaMttyzhNcyNVgw_dQgK10qotI,5308
|
|
3
|
-
toolslm/download.py,sha256=g3BxUSxylC_575M7RFSJ1GI3Co3EwPDdEeWzxaf2Czk,4451
|
|
4
|
-
toolslm/funccall.py,sha256=0OBrx6KzI0KK13L-5Hn69yah9oZhgTsKchmMenCoT0A,10421
|
|
5
|
-
toolslm/md_hier.py,sha256=r_NPezhgfxjRmSYFlu_ND42hXt1qSbaPWHTcjbviOn4,11010
|
|
6
|
-
toolslm/shell.py,sha256=dGInuRKvexu21VmtZkw_0S3BGiTsbAongUG-yG4YHpc,1566
|
|
7
|
-
toolslm/xml.py,sha256=tAHoqXrTRiX8i3pR-9KpHoBb8QXJ_TKEVyTEOPviudE,8095
|
|
8
|
-
toolslm-0.3.9.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
-
toolslm-0.3.9.dist-info/METADATA,sha256=djSwIqYu8Taj8g0yyXKw3IqFr_fbAKhbI3aQu14kv9U,2403
|
|
10
|
-
toolslm-0.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
-
toolslm-0.3.9.dist-info/entry_points.txt,sha256=xFz0Eymlo5X7BGpaO6DI9gMxvN5A7faebzrlr8ctp5I,95
|
|
12
|
-
toolslm-0.3.9.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
13
|
-
toolslm-0.3.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|