toolslm 0.3.26__py3-none-any.whl → 0.3.27__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.26"
1
+ __version__ = "0.3.27"
toolslm/_modidx.py CHANGED
@@ -28,10 +28,12 @@ d = { 'settings': { 'branch': 'main',
28
28
  'toolslm.funccall.call_func': ('funccall.html#call_func', 'toolslm/funccall.py'),
29
29
  'toolslm.funccall.call_func_async': ('funccall.html#call_func_async', 'toolslm/funccall.py'),
30
30
  'toolslm.funccall.get_schema': ('funccall.html#get_schema', 'toolslm/funccall.py'),
31
+ 'toolslm.funccall.get_schema_nm': ('funccall.html#get_schema_nm', 'toolslm/funccall.py'),
31
32
  'toolslm.funccall.mk_ns': ('funccall.html#mk_ns', 'toolslm/funccall.py'),
32
33
  'toolslm.funccall.mk_param': ('funccall.html#mk_param', 'toolslm/funccall.py'),
33
34
  'toolslm.funccall.mk_tool': ('funccall.html#mk_tool', 'toolslm/funccall.py'),
34
35
  'toolslm.funccall.python': ('funccall.html#python', 'toolslm/funccall.py'),
36
+ 'toolslm.funccall.resolve_nm': ('funccall.html#resolve_nm', 'toolslm/funccall.py'),
35
37
  'toolslm.funccall.schema2sig': ('funccall.html#schema2sig', 'toolslm/funccall.py')},
36
38
  'toolslm.inspecttools': { 'toolslm.inspecttools.SymbolNotFound': ( 'inspecttools.html#symbolnotfound',
37
39
  'toolslm/inspecttools.py'),
toolslm/funccall.py CHANGED
@@ -1,8 +1,8 @@
1
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../01_funccall.ipynb.
2
2
 
3
3
  # %% auto #0
4
- __all__ = ['empty', 'custom_types', 'get_schema', 'python', 'mk_ns', 'call_func', 'call_func_async', 'mk_param', 'schema2sig',
5
- 'mk_tool']
4
+ __all__ = ['empty', 'custom_types', 'get_schema', 'python', 'mk_ns', 'resolve_nm', 'get_schema_nm', 'call_func',
5
+ 'call_func_async', 'mk_param', 'schema2sig', 'mk_tool']
6
6
 
7
7
  # %% ../01_funccall.ipynb #e5ad6b86
8
8
  import inspect, json, ast
@@ -15,6 +15,7 @@ from typing import get_type_hints
15
15
  from inspect import Parameter, Signature
16
16
  from decimal import Decimal
17
17
  from uuid import UUID
18
+ from functools import reduce
18
19
 
19
20
  # %% ../01_funccall.ipynb #a9f43047
20
21
  empty = inspect.Parameter.empty
@@ -25,7 +26,7 @@ def _types(t:type)->tuple[str,Optional[str]]:
25
26
  if t is empty: raise TypeError('Missing type')
26
27
  tmap = {int:"integer", float:"number", str:"string", bool:"boolean", list:"array", dict:"object"}
27
28
  tmap.update({k.__name__: v for k, v in tmap.items()})
28
- if getattr(t, '__origin__', None) in (list,tuple):
29
+ if getattr(t, '__origin__', None) in (list,tuple,set):
29
30
  args = getattr(t, '__args__', None)
30
31
  item_type = "object" if not args else tmap.get(t.__args__[0].__name__, "object")
31
32
  return "array", item_type
@@ -58,9 +59,11 @@ custom_types = {Path, bytes, Decimal, UUID}
58
59
 
59
60
  def _handle_type(t, defs):
60
61
  "Handle a single type, creating nested schemas if necessary"
62
+ ot = ifnone(get_origin(t), t)
61
63
  if t is NoneType: return {'type': 'null'}
62
64
  if t in custom_types: return {'type':'string', 'format':t.__name__}
63
- if t in (dict, list, tuple, set): return {'type': _types(t)[0]}
65
+ if ot is dict: return {'type': _types(t)[0]}
66
+ if ot in (list, tuple, set): return {'type': _types(t)[0], 'items':{}}
64
67
  if isinstance(t, type) and not issubclass(t, (int, float, str, bool)) or inspect.isfunction(t):
65
68
  defs[t.__name__] = _get_nested_schema(t)
66
69
  return {'$ref': f'#/$defs/{t.__name__}'}
@@ -132,10 +135,13 @@ def get_schema(
132
135
  f:Union[callable,dict], # Function to get schema for
133
136
  pname='input_schema', # Key name for parameters
134
137
  evalable=False, # stringify defaults that can't be literal_eval'd?
135
- skip_hidden=False # skip parameters starting with '_'?
138
+ skip_hidden=False, # skip parameters starting with '_'?
139
+ name=None # Override function name (useful for dotted paths like 'obj.method')
136
140
  )->dict: # {'name':..., 'description':..., pname:...}
137
141
  "Generate JSON schema for a class, function, or method"
138
142
  if isinstance(f, dict): return f
143
+ if hasattr(f, '__call__') and not isinstance(f, type) and not inspect.isfunction(f) and not inspect.ismethod(f):
144
+ f = f.__call__
139
145
  schema = _get_nested_schema(f, evalable=evalable, skip_hidden=skip_hidden)
140
146
  desc = f.__doc__
141
147
  assert desc, "Docstring missing!"
@@ -147,7 +153,7 @@ def get_schema(
147
153
  type_str = f'type: {_types(ret.anno)[0]}' if has_type else None
148
154
  ret_str = f'{ret.docment} ({type_str})' if has_type and has_doc else (type_str if has_type else ret.docment)
149
155
  desc += f'\n\nReturns:\n- {ret_str}'
150
- return {"name": f.__name__, "description": desc, pname: schema}
156
+ return {"name": name or f.__name__, "description": desc, pname: schema}
151
157
 
152
158
  # %% ../01_funccall.ipynb #873000d7
153
159
  import ast, time, signal, traceback
@@ -223,11 +229,22 @@ def _coerce_inputs(func, inputs):
223
229
  else: res[k] = v
224
230
  return res
225
231
 
226
- # %% ../01_funccall.ipynb #d817ab01
232
+ # %% ../01_funccall.ipynb #925f462b
233
+ def resolve_nm(nm, ns):
234
+ st,*rest = nm.split('.')
235
+ return reduce(getattr, rest, ns[st])
236
+
237
+ # %% ../01_funccall.ipynb #6f6b5bfa
238
+ def get_schema_nm(nm:str, ns, dot2dash=False, **kwargs):
239
+ "Get schema for symbol `nm` in namespace `ns`, preserving the full dotted name"
240
+ name = nm.replace('.', '-') if dot2dash else nm
241
+ return get_schema(resolve_nm(nm, ns), name=name, **kwargs)
242
+
243
+ # %% ../01_funccall.ipynb #47b49644
227
244
  def call_func(fc_name, fc_inputs, ns, raise_on_err=True):
228
245
  "Call the function `fc_name` with the given `fc_inputs` using namespace `ns`."
229
246
  if not isinstance(ns, abc.Mapping): ns = mk_ns(ns)
230
- func = ns[fc_name]
247
+ func = resolve_nm(fc_name, ns)
231
248
  inps = {re.sub(r'\W', '', k):v for k,v in fc_inputs.items()}
232
249
  inps = _coerce_inputs(func, inps)
233
250
  try: return func(**inps)
@@ -235,7 +252,7 @@ def call_func(fc_name, fc_inputs, ns, raise_on_err=True):
235
252
  if raise_on_err: raise e from None
236
253
  else: return traceback.format_exc()
237
254
 
238
- # %% ../01_funccall.ipynb #7ac04e80-7bb9-4b52-8285-454684605d47
255
+ # %% ../01_funccall.ipynb #73bca085
239
256
  async def call_func_async(fc_name, fc_inputs, ns, raise_on_err=True):
240
257
  "Awaits the function `fc_name` with the given `fc_inputs` using namespace `ns`."
241
258
  res = call_func(fc_name, fc_inputs, ns, raise_on_err=raise_on_err)
@@ -1,18 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolslm
3
- Version: 0.3.26
3
+ Version: 0.3.27
4
4
  Summary: Tools to make language models a bit easier to use
5
- Home-page: https://github.com/AnswerDotAI/toolslm
6
- Author: Jeremy Howard
7
- Author-email: j@fast.ai
8
- License: Apache Software License 2.0
9
- Keywords: nbdev jupyter notebook python
10
- Classifier: Development Status :: 4 - Beta
11
- Classifier: Intended Audience :: Developers
5
+ Author-email: Jeremy Howard <j@fast.ai>
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/AnswerDotAI/toolslm
8
+ Project-URL: Documentation, https://AnswerDotAI.github.io/toolslm
9
+ Keywords: nbdev,jupyter,notebook,python
12
10
  Classifier: Natural Language :: English
13
- Classifier: Programming Language :: Python :: 3.9
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
16
15
  Requires-Python: >=3.9
17
16
  Description-Content-Type: text/markdown
18
17
  License-File: LICENSE
@@ -22,19 +21,7 @@ Requires-Dist: ghapi
22
21
  Requires-Dist: codesigs
23
22
  Provides-Extra: dev
24
23
  Requires-Dist: ipython; extra == "dev"
25
- Dynamic: author
26
- Dynamic: author-email
27
- Dynamic: classifier
28
- Dynamic: description
29
- Dynamic: description-content-type
30
- Dynamic: home-page
31
- Dynamic: keywords
32
- Dynamic: license
33
24
  Dynamic: license-file
34
- Dynamic: provides-extra
35
- Dynamic: requires-dist
36
- Dynamic: requires-python
37
- Dynamic: summary
38
25
 
39
26
  # toolslm
40
27
 
@@ -0,0 +1,14 @@
1
+ toolslm/__init__.py,sha256=29NKIdIEuYqO-c6J9l3sWNaNJuboRFR7B9xLtslgwZk,23
2
+ toolslm/_modidx.py,sha256=16eJzowUt9cpwnpt83goPyn_3Q3doH73X61s0YFmyuI,9172
3
+ toolslm/download.py,sha256=tBDG5QFnbDdRigiSBjA_GUAC4lAE1LOEs-cjpW5C-kw,4582
4
+ toolslm/funccall.py,sha256=pFdGZrvKJnhiDkgBbCu1eZtadbH6EVF0ne-OM25JZHk,12445
5
+ toolslm/inspecttools.py,sha256=wkHlbOgbps7hTmYQbG7mg4gDkFL_prvk3pfgSQz27L4,9810
6
+ toolslm/md_hier.py,sha256=r_NPezhgfxjRmSYFlu_ND42hXt1qSbaPWHTcjbviOn4,11010
7
+ toolslm/shell.py,sha256=VhXav3MSwK7P8e63-HKawFmrCkOdZSi8t4QgsIu8oFU,1617
8
+ toolslm/xml.py,sha256=buCRuFluYQ2EvQR0nIGoeQoxrIln-o5QCRNyLFO_RcY,13226
9
+ toolslm-0.3.27.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
10
+ toolslm-0.3.27.dist-info/METADATA,sha256=IcrIoBD1yCFkiROWlxeX-5fpCjeRQhAbNqSinpFF3uE,2231
11
+ toolslm-0.3.27.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
12
+ toolslm-0.3.27.dist-info/entry_points.txt,sha256=L77QoeUC_BjrE3BVY-Wpi4RMq_iwfX_1eAWchc6Zsmw,131
13
+ toolslm-0.3.27.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
14
+ toolslm-0.3.27.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,14 +0,0 @@
1
- toolslm/__init__.py,sha256=PEJ4dz-V-DCK0OeabDYIWRrLQrxB_F8MVeCQiGql0Y0,23
2
- toolslm/_modidx.py,sha256=uRIQ7S4CNtTE4v6um6VE0HTOLvCbnLzKjWVpYQSytRk,8930
3
- toolslm/download.py,sha256=tBDG5QFnbDdRigiSBjA_GUAC4lAE1LOEs-cjpW5C-kw,4582
4
- toolslm/funccall.py,sha256=S68mlYOn-OW0j52PR7pHzAKk_D3omWv0q1W5pt-GIUc,11650
5
- toolslm/inspecttools.py,sha256=wkHlbOgbps7hTmYQbG7mg4gDkFL_prvk3pfgSQz27L4,9810
6
- toolslm/md_hier.py,sha256=r_NPezhgfxjRmSYFlu_ND42hXt1qSbaPWHTcjbviOn4,11010
7
- toolslm/shell.py,sha256=VhXav3MSwK7P8e63-HKawFmrCkOdZSi8t4QgsIu8oFU,1617
8
- toolslm/xml.py,sha256=buCRuFluYQ2EvQR0nIGoeQoxrIln-o5QCRNyLFO_RcY,13226
9
- toolslm-0.3.26.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
10
- toolslm-0.3.26.dist-info/METADATA,sha256=8f85HepLX7oU4Upxw0UWkCMZzty10mkV2fg4NAqFeBQ,2489
11
- toolslm-0.3.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- toolslm-0.3.26.dist-info/entry_points.txt,sha256=L77QoeUC_BjrE3BVY-Wpi4RMq_iwfX_1eAWchc6Zsmw,131
13
- toolslm-0.3.26.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
14
- toolslm-0.3.26.dist-info/RECORD,,