toolslm 0.3.26__tar.gz → 0.3.27__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.
@@ -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,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "toolslm"
7
+ dynamic = ["version"]
8
+ description = "Tools to make language models a bit easier to use"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = {text = "Apache-2.0"}
12
+ authors = [{name = "Jeremy Howard", email = "j@fast.ai"}]
13
+ keywords = ['nbdev', 'jupyter', 'notebook', 'python']
14
+ classifiers = ["Natural Language :: English", "Intended Audience :: Developers", "Development Status :: 3 - Alpha", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only"]
15
+ dependencies = ['fastcore>=1.12.4', 'httpx', 'ghapi', 'codesigs']
16
+
17
+ [project.urls]
18
+ Repository = "https://github.com/AnswerDotAI/toolslm"
19
+ Documentation = "https://AnswerDotAI.github.io/toolslm"
20
+
21
+ [project.entry-points.nbdev]
22
+ toolslm = "toolslm._modidx:d"
23
+
24
+ [project.optional-dependencies]
25
+ dev = ['ipython']
26
+
27
+
28
+ [project.scripts]
29
+ folder2ctx = "toolslm.xml:folder2ctx_cli"
30
+ repo2ctx = "toolslm.xml:repo2ctx_cli"
31
+
32
+ [tool.setuptools.dynamic]
33
+ version = {attr = "toolslm.__version__"}
34
+
35
+ [tool.setuptools.packages.find]
36
+ include = ["toolslm"]
37
+
38
+ [tool.nbdev]
39
+ nbs_path = '.'
40
+ jupyter_hooks = true
41
+ custom_sidebar = false
@@ -0,0 +1 @@
1
+ __version__ = "0.3.27"
@@ -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'),
@@ -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
 
@@ -2,8 +2,6 @@ LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
4
  pyproject.toml
5
- settings.ini
6
- setup.py
7
5
  toolslm/__init__.py
8
6
  toolslm/_modidx.py
9
7
  toolslm/download.py
@@ -16,6 +14,5 @@ toolslm.egg-info/PKG-INFO
16
14
  toolslm.egg-info/SOURCES.txt
17
15
  toolslm.egg-info/dependency_links.txt
18
16
  toolslm.egg-info/entry_points.txt
19
- toolslm.egg-info/not-zip-safe
20
17
  toolslm.egg-info/requires.txt
21
18
  toolslm.egg-info/top_level.txt
@@ -1,11 +0,0 @@
1
- [build-system]
2
- requires = ["setuptools>=64.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name="toolslm"
7
- requires-python=">=3.9"
8
- dynamic = [ "keywords", "description", "version", "dependencies", "optional-dependencies", "readme", "license", "authors", "classifiers", "entry-points", "scripts", "urls"]
9
-
10
- [tool.uv]
11
- cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]
@@ -1,43 +0,0 @@
1
- [DEFAULT]
2
- repo = toolslm
3
- lib_name = toolslm
4
- version = 0.3.26
5
- min_python = 3.9
6
- license = apache2
7
- black_formatting = False
8
- requirements = fastcore>=1.12.4 httpx ghapi codesigs
9
- dev_requirements = ipython
10
- doc_path = _docs
11
- lib_path = toolslm
12
- nbs_path = .
13
- recursive = True
14
- tst_flags = notest
15
- put_version_in_init = True
16
- branch = main
17
- custom_sidebar = False
18
- doc_host = https://AnswerDotAI.github.io
19
- doc_baseurl = /toolslm
20
- git_url = https://github.com/AnswerDotAI/toolslm
21
- title = toolslm
22
- audience = Developers
23
- author = Jeremy Howard
24
- author_email = j@fast.ai
25
- copyright = 2024 onwards, Jeremy Howard
26
- description = Tools to make language models a bit easier to use
27
- keywords = nbdev jupyter notebook python
28
- language = English
29
- status = 3
30
- user = AnswerDotAI
31
- readme_nb = index.ipynb
32
- allowed_metadata_keys =
33
- allowed_cell_metadata_keys =
34
- jupyter_hooks = True
35
- clear_all = False
36
- conda_user = fastai
37
- console_scripts = folder2ctx=toolslm.xml:folder2ctx_cli
38
- repo2ctx=toolslm.xml:repo2ctx_cli
39
- cell_number = False
40
- skip_procs =
41
- update_pyproject = True
42
- clean_ids = True
43
-
toolslm-0.3.26/setup.py DELETED
@@ -1,57 +0,0 @@
1
- from pkg_resources import parse_version
2
- from configparser import ConfigParser
3
- import setuptools, shlex
4
- assert parse_version(setuptools.__version__)>=parse_version('36.2')
5
-
6
- # note: all settings are in settings.ini; edit there, not here
7
- config = ConfigParser(delimiters=['='])
8
- config.read('settings.ini', encoding='utf-8')
9
- cfg = config['DEFAULT']
10
-
11
- cfg_keys = 'version description keywords author author_email'.split()
12
- expected = cfg_keys + "lib_name user branch license status min_python audience language".split()
13
- for o in expected: assert o in cfg, "missing expected setting: {}".format(o)
14
- setup_cfg = {o:cfg[o] for o in cfg_keys}
15
-
16
- licenses = {
17
- 'apache2': ('Apache Software License 2.0','OSI Approved :: Apache Software License'),
18
- 'mit': ('MIT License', 'OSI Approved :: MIT License'),
19
- 'gpl2': ('GNU General Public License v2', 'OSI Approved :: GNU General Public License v2 (GPLv2)'),
20
- 'gpl3': ('GNU General Public License v3', 'OSI Approved :: GNU General Public License v3 (GPLv3)'),
21
- 'bsd3': ('BSD License', 'OSI Approved :: BSD License'),
22
- }
23
- statuses = [ '1 - Planning', '2 - Pre-Alpha', '3 - Alpha',
24
- '4 - Beta', '5 - Production/Stable', '6 - Mature', '7 - Inactive' ]
25
- py_versions = '3.6 3.7 3.8 3.9 3.10'.split()
26
-
27
- requirements = shlex.split(cfg.get('requirements', ''))
28
- if cfg.get('pip_requirements'): requirements += shlex.split(cfg.get('pip_requirements', ''))
29
- min_python = cfg['min_python']
30
- lic = licenses.get(cfg['license'].lower(), (cfg['license'], None))
31
- dev_requirements = (cfg.get('dev_requirements') or '').split()
32
-
33
- setuptools.setup(
34
- name = cfg['lib_name'],
35
- license = lic[0],
36
- classifiers = [
37
- 'Development Status :: ' + statuses[int(cfg['status'])],
38
- 'Intended Audience :: ' + cfg['audience'].title(),
39
- 'Natural Language :: ' + cfg['language'].title(),
40
- ] + ['Programming Language :: Python :: '+o for o in py_versions[py_versions.index(min_python):]] + (['License :: ' + lic[1] ] if lic[1] else []),
41
- url = cfg['git_url'],
42
- packages = setuptools.find_packages(),
43
- include_package_data = True,
44
- install_requires = requirements,
45
- extras_require={ 'dev': dev_requirements },
46
- dependency_links = cfg.get('dep_links','').split(),
47
- python_requires = '>=' + cfg['min_python'],
48
- long_description = open('README.md', encoding='utf-8').read(),
49
- long_description_content_type = 'text/markdown',
50
- zip_safe = False,
51
- entry_points = {
52
- 'console_scripts': cfg.get('console_scripts','').split(),
53
- 'nbdev': [f'{cfg.get("lib_path")}={cfg.get("lib_path")}._modidx:d']
54
- },
55
- **setup_cfg)
56
-
57
-
@@ -1 +0,0 @@
1
- __version__ = "0.3.26"
@@ -1 +0,0 @@
1
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes