dialoghelper 0.0.11__py3-none-any.whl → 0.0.12__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.

Potentially problematic release.


This version of dialoghelper might be problematic. Click here for more details.

dialoghelper/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.0.11"
1
+ __version__ = "0.0.12"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -19,7 +19,9 @@ d = { 'settings': { 'branch': 'main',
19
19
  'dialoghelper.core.import_dialog': ('core.html#import_dialog', 'dialoghelper/core.py'),
20
20
  'dialoghelper.core.import_gist': ('core.html#import_gist', 'dialoghelper/core.py'),
21
21
  'dialoghelper.core.import_string': ('core.html#import_string', 'dialoghelper/core.py'),
22
+ 'dialoghelper.core.is_usable_tool': ('core.html#is_usable_tool', 'dialoghelper/core.py'),
22
23
  'dialoghelper.core.load_gist': ('core.html#load_gist', 'dialoghelper/core.py'),
24
+ 'dialoghelper.core.mk_toollist': ('core.html#mk_toollist', 'dialoghelper/core.py'),
23
25
  'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
24
26
  'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
25
27
  'dialoghelper.core.read_msg_ids': ('core.html#read_msg_ids', 'dialoghelper/core.py'),
dialoghelper/core.py CHANGED
@@ -1,12 +1,12 @@
1
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
2
2
 
3
3
  # %% auto 0
4
- __all__ = ['Placements', 'get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx',
5
- 'read_msg', 'add_msg', 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist',
6
- 'export_dialog', 'import_dialog', 'asdict']
4
+ __all__ = ['Placements', 'empty', 'get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx',
5
+ 'read_msg', 'add_msg', 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool',
6
+ 'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'asdict']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
- import inspect, json, importlib, linecache
9
+ import json, importlib, linecache
10
10
  from typing import Dict
11
11
  from tempfile import TemporaryDirectory
12
12
  from ipykernel_helper import *
@@ -17,6 +17,7 @@ from fastcore.meta import delegates
17
17
  from ghapi.all import *
18
18
  from fastlite import *
19
19
  from fastcore.xtras import asdict
20
+ from inspect import currentframe,Parameter,signature
20
21
 
21
22
  # %% ../nbs/00_core.ipynb
22
23
  _all_ = ["asdict"]
@@ -35,7 +36,7 @@ def get_db(ns:dict=None):
35
36
  # %% ../nbs/00_core.ipynb
36
37
  def find_var(var:str):
37
38
  "Search for var in all frames of the call stack"
38
- frame = inspect.currentframe()
39
+ frame = currentframe()
39
40
  while frame:
40
41
  dv = frame.f_globals.get(var, frame.f_locals.get(var, None))
41
42
  if dv: return dv
@@ -189,17 +190,38 @@ def import_string(
189
190
  spec.loader.exec_module(module)
190
191
  return module
191
192
 
193
+ # %% ../nbs/00_core.ipynb
194
+ empty = Parameter.empty
195
+
196
+ def is_usable_tool(func:callable):
197
+ "True if the function has a docstring and all parameters have types, meaning that it can be used as an LLM tool."
198
+ if not func.__doc__ or not callable(func): return False
199
+ return all(p.annotation != empty for p in signature(func).parameters.values())
200
+
201
+ # %% ../nbs/00_core.ipynb
202
+ def mk_toollist(syms):
203
+ return "\n".join(f"- &`{sym.__name__}`: {sym.__doc__}" for sym in syms if is_usable_tool(sym))
204
+
192
205
  # %% ../nbs/00_core.ipynb
193
206
  def import_gist(
194
207
  gist_id:str, # user/id or just id of gist to import as a module
195
208
  mod_name:str=None, # module name to create (taken from gist filename if not passed)
196
- add_global:bool=True # add module to caller's globals?
209
+ add_global:bool=True, # add module to caller's globals?
210
+ import_wildcard:bool=False, # import all exported symbols to caller's globals
211
+ create_msg:bool=False # Add a message that lists usable tools
197
212
  ):
198
213
  "Import gist directly from string without saving to disk"
199
214
  fil = gist_file(gist_id)
200
215
  mod_name = mod_name or Path(fil['filename']).stem
201
216
  module = import_string(fil['content'], mod_name)
202
- if add_global: inspect.currentframe().f_back.f_globals[mod_name] = module
217
+ glbs = currentframe().f_back.f_globals
218
+ if add_global: glbs[mod_name] = module
219
+ syms = getattr(module, '__all__', None)
220
+ if syms is None: syms = [o for o in dir(module) if not o.startswith('_')]
221
+ syms = [getattr(module, nm) for nm in syms]
222
+ if import_wildcard:
223
+ for sym in syms: glbs[sym.__name__] = sym
224
+ if create_msg: add_msg(f"Tools added to dialog:\n\n{mk_toollist(syms)}")
203
225
  return module
204
226
 
205
227
  # %% ../nbs/00_core.ipynb
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.11
3
+ Version: 0.0.12
4
4
  Summary: Helper functions for solveit dialogs
5
5
  Home-page: https://github.com/AnswerDotAI/dialoghelper
6
6
  Author: Jeremy Howard
@@ -0,0 +1,10 @@
1
+ dialoghelper/__init__.py,sha256=NBQPBiYNpbwRh0tbd9ruOAJTKO2W4erG6F75QoavDZQ,43
2
+ dialoghelper/_modidx.py,sha256=vykjCRgjhfKJE-8CjADe_sEpd3WBBnCxBt3r7hzNpJM,2773
3
+ dialoghelper/core.py,sha256=OaFbX-GYw8nG_4vL96qMyV4G8MnnzVSwELrbkLz-xP4,10609
4
+ dialoghelper/db_dc.py,sha256=ieSie_K1HHXACEJVZ0rMkD_uo42GgmMqqKDYrodjhtM,2297
5
+ dialoghelper-0.0.12.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
+ dialoghelper-0.0.12.dist-info/METADATA,sha256=vaoX4p5Bty5klz-IF_3mx3Fa-6hen9SxBYkWCiBjy0I,2558
7
+ dialoghelper-0.0.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ dialoghelper-0.0.12.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
+ dialoghelper-0.0.12.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
+ dialoghelper-0.0.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- dialoghelper/__init__.py,sha256=pot8RlG0U4OhR3W-uFE3FF_SkXBM1i-NXq4JI4v6zdU,43
2
- dialoghelper/_modidx.py,sha256=fZ9-eTMaLdG-nvxxTe9_qjLwKIGS9_FU7KpFyCiF7DU,2529
3
- dialoghelper/core.py,sha256=515ndWh4b2vNEm1H6l5DBt4GWcqk3ILVo9zk8cEr3ig,9552
4
- dialoghelper/db_dc.py,sha256=ieSie_K1HHXACEJVZ0rMkD_uo42GgmMqqKDYrodjhtM,2297
5
- dialoghelper-0.0.11.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- dialoghelper-0.0.11.dist-info/METADATA,sha256=PY8bUCy8IiRCCmkHM_bW0hTtSdsbtZvMnoBxkBTnR0o,2558
7
- dialoghelper-0.0.11.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
8
- dialoghelper-0.0.11.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
- dialoghelper-0.0.11.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
- dialoghelper-0.0.11.dist-info/RECORD,,