dialoghelper 0.0.11__tar.gz → 0.0.12__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.
Potentially problematic release.
This version of dialoghelper might be problematic. Click here for more details.
- {dialoghelper-0.0.11/dialoghelper.egg-info → dialoghelper-0.0.12}/PKG-INFO +1 -1
- dialoghelper-0.0.12/dialoghelper/__init__.py +2 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper/_modidx.py +2 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper/core.py +29 -7
- {dialoghelper-0.0.11 → dialoghelper-0.0.12/dialoghelper.egg-info}/PKG-INFO +1 -1
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/settings.ini +1 -1
- dialoghelper-0.0.11/dialoghelper/__init__.py +0 -2
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/LICENSE +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/MANIFEST.in +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/README.md +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper/db_dc.py +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper.egg-info/SOURCES.txt +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper.egg-info/dependency_links.txt +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper.egg-info/entry_points.txt +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper.egg-info/not-zip-safe +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper.egg-info/requires.txt +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/dialoghelper.egg-info/top_level.txt +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/pyproject.toml +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/setup.cfg +0 -0
- {dialoghelper-0.0.11 → dialoghelper-0.0.12}/setup.py +0 -0
|
@@ -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'),
|
|
@@ -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', '
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|