dialoghelper 0.0.10__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.10"
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__ = ['get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx', 'read_msg', 'add_msg',
5
- 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist', 'export_dialog',
6
- '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
@@ -105,6 +106,8 @@ def _msg(
105
106
  pinned: int | None = 0 # Pin to context?
106
107
  ): ...
107
108
 
109
+ Placements = str_enum('Placements', 'add_after', 'add_before', 'update', 'at_start', 'at_end')
110
+
108
111
  # %% ../nbs/00_core.ipynb
109
112
  @delegates(_msg)
110
113
  def add_msg(
@@ -187,17 +190,38 @@ def import_string(
187
190
  spec.loader.exec_module(module)
188
191
  return module
189
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
+
190
205
  # %% ../nbs/00_core.ipynb
191
206
  def import_gist(
192
207
  gist_id:str, # user/id or just id of gist to import as a module
193
208
  mod_name:str=None, # module name to create (taken from gist filename if not passed)
194
- 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
195
212
  ):
196
213
  "Import gist directly from string without saving to disk"
197
214
  fil = gist_file(gist_id)
198
215
  mod_name = mod_name or Path(fil['filename']).stem
199
216
  module = import_string(fil['content'], mod_name)
200
- 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)}")
201
225
  return module
202
226
 
203
227
  # %% ../nbs/00_core.ipynb
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.10
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=vGb5bWRnqikdeGjmhzb9R8htmRhc2CloD1a9bB7Ttvo,43
2
- dialoghelper/_modidx.py,sha256=fZ9-eTMaLdG-nvxxTe9_qjLwKIGS9_FU7KpFyCiF7DU,2529
3
- dialoghelper/core.py,sha256=nJyoSz4TlYY4lOLBV8TqSXc3PW61J82GA6eleDr6i-4,9442
4
- dialoghelper/db_dc.py,sha256=ieSie_K1HHXACEJVZ0rMkD_uo42GgmMqqKDYrodjhtM,2297
5
- dialoghelper-0.0.10.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- dialoghelper-0.0.10.dist-info/METADATA,sha256=qSxn-0_wPe8LdbEDSQU6R2ArvrWHh2E8vle_Fw9hZJc,2558
7
- dialoghelper-0.0.10.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
8
- dialoghelper-0.0.10.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
- dialoghelper-0.0.10.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
- dialoghelper-0.0.10.dist-info/RECORD,,