dialoghelper 0.0.1__py3-none-any.whl → 0.0.3__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.1"
1
+ __version__ = "0.0.3"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -5,7 +5,8 @@ d = { 'settings': { 'branch': 'main',
5
5
  'doc_host': 'https://AnswerDotAI.github.io',
6
6
  'git_url': 'https://github.com/AnswerDotAI/dialoghelper',
7
7
  'lib_path': 'dialoghelper'},
8
- 'syms': { 'dialoghelper.core': { 'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
8
+ 'syms': { 'dialoghelper.core': { 'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
9
+ 'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
9
10
  'dialoghelper.core.find_dialog_id': ('core.html#find_dialog_id', 'dialoghelper/core.py'),
10
11
  'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
11
12
  'dialoghelper.core.find_msgs': ('core.html#find_msgs', 'dialoghelper/core.py'),
dialoghelper/core.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # %% auto 0
4
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', 'load_gist', 'gist_file', 'import_string', 'import_gist']
5
+ 'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist']
6
6
 
7
7
  # %% ../nbs/00_core.ipynb
8
8
  import inspect, json, importlib, linecache
@@ -14,15 +14,18 @@ from ghapi.all import *
14
14
  from fastlite import *
15
15
 
16
16
  # %% ../nbs/00_core.ipynb
17
- def get_db():
18
- if os.environ.get('IN_SOLVEIT', False): dataparent,nm = Path('/app'),'data.db'
17
+ def get_db(ns:dict=None):
18
+ app_path = Path('/app') if Path('/.dockerenv').exists() else Path('.')
19
+ if os.environ.get('IN_SOLVEIT', False): dataparent,nm = app_path, 'data.db'
19
20
  else: dataparent,nm = Path('..'),'dev_data.db'
20
21
  db = database(dataparent/'data'/nm)
21
- all_dcs(db)
22
+ dcs = [o for o in all_dcs(db) if o.__name__[0]!='_']
23
+ if ns:
24
+ for o in dcs: ns[o.__name__]=o
22
25
  return db
23
26
 
24
27
  # %% ../nbs/00_core.ipynb
25
- def find_var(var: str):
28
+ def find_var(var:str):
26
29
  "Search for var in all frames of the call stack"
27
30
  frame = inspect.currentframe()
28
31
  while frame:
@@ -37,9 +40,13 @@ def find_dialog_id():
37
40
  return find_var('__dialog_id')
38
41
 
39
42
  # %% ../nbs/00_core.ipynb
40
- def find_msgs(pattern: str, limit=10):
43
+ def find_msgs(
44
+ pattern: str, # Text to search for
45
+ limit:int=10 # Limit number of returned items
46
+ ):
41
47
  "Find messages in a specific dialog that contain the given pattern."
42
48
  did = find_dialog_id()
49
+ db = get_db()
43
50
  return db.t.message('did=? AND content LIKE ?', [did, f'%{pattern}%'], limit=limit)
44
51
 
45
52
  # %% ../nbs/00_core.ipynb
@@ -51,6 +58,7 @@ def find_msg_id():
51
58
  def read_msg_ids():
52
59
  "Get all ids in current dialog."
53
60
  did = find_dialog_id()
61
+ db = get_db()
54
62
  return [o.sid for o in db.t.message('did=?', [did], select='sid', order_by='id')]
55
63
 
56
64
  # %% ../nbs/00_core.ipynb
@@ -60,8 +68,8 @@ def msg_idx():
60
68
  return ids,ids.index(find_msg_id())
61
69
 
62
70
  # %% ../nbs/00_core.ipynb
63
- def read_msg(n: int=-1, # Message index (if relative, +ve is downwards)
64
- relative=True # Is `n` relative to current message (True) or absolute (False)?
71
+ def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
72
+ relative:bool=True # Is `n` relative to current message (True) or absolute (False)?
65
73
  ):
66
74
  "Get the message indexed in the current dialog."
67
75
  ids,idx = msg_idx()
@@ -69,6 +77,7 @@ def read_msg(n: int=-1, # Message index (if relative, +ve is downwards)
69
77
  idx = idx+n
70
78
  if not 0<=idx<len(ids): return None
71
79
  else: idx = n
80
+ db = get_db()
72
81
  return db.t.message.fetchone('sid=?', [ids[idx]])
73
82
 
74
83
  # %% ../nbs/00_core.ipynb
@@ -77,35 +86,49 @@ def add_msg(
77
86
  msg_type: str='note', # message type, can be 'code', 'note', or 'prompt'
78
87
  output='', # for prompts/code, initial output
79
88
  placement='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
80
- msg_id=None
89
+ msg_id:str=None, # id of message that placement is relative to (if None, uses current message)
90
+ **kw # Additional Message fields such as skipped i/o_collapsed, etc, passed through to the server
81
91
  ):
82
92
  "Add/update a message to the queue to show after code execution completes."
83
93
  assert msg_type in ('note', 'code', 'prompt'), "msg_type must be 'code', 'note', or 'prompt'."
84
- kwargs = dict(content=content, msg_type=msg_type, output=output, placement=placement)
85
- if msg_id: kwargs['msg_id']=msg_id
86
- run_cmd('add_msg', **kwargs)
94
+ # kwargs = {'msg_id':msg_id} if msg_id else {}
95
+ run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement, msg_id=msg_id, **kw)
87
96
 
88
97
  # %% ../nbs/00_core.ipynb
89
- def update_msg(msg):
98
+ def update_msg(msg: dict):
90
99
  "Update an existing message in the dialog."
91
- add_msg(content=msg.content, msg_type=msg.msg_type, output=msg.output, placement='update', msg_id=msg.id)
100
+ if not isinstance(msg, dict): msg = asdict(msg)
101
+ exclude = {'id', 'content', 'msg_type', 'output'} # explicit args
102
+ kw = {k: v for k, v in msg.items() if k not in exclude}
103
+ add_msg(content=msg['content'], msg_type=msg['msg_type'], output=msg['output'],
104
+ placement = 'update', msg_id=msg['id'], **kw)
92
105
 
93
106
  # %% ../nbs/00_core.ipynb
94
- def load_gist(gist_id):
95
- "Get the first file from a gist"
107
+ def add_html(
108
+ html:str, # HTML to add to the DOM
109
+ ):
110
+ "Dynamically add HTML to the current web page. Supports HTMX attrs too."
111
+ run_cmd('add_ft', html=html)
112
+
113
+ # %% ../nbs/00_core.ipynb
114
+ def load_gist(gist_id:str):
115
+ "Retrieve a gist"
96
116
  api = GhApi()
97
117
  if '/' in gist_id: *_,user,gist_id = gist_id.split('/')
98
118
  else: user = None
99
119
  return api.gists.get(gist_id, user=user)
100
120
 
101
121
  # %% ../nbs/00_core.ipynb
102
- def gist_file(gist_id):
122
+ def gist_file(gist_id:str):
103
123
  "Get the first file from a gist"
104
124
  gist = load_gist(gist_id)
105
125
  return first(gist.files.values())
106
126
 
107
127
  # %% ../nbs/00_core.ipynb
108
- def import_string(code, name):
128
+ def import_string(
129
+ code:str, # Code to import as a module
130
+ name:str # Name of module to create
131
+ ):
109
132
  with TemporaryDirectory() as tmpdir:
110
133
  path = Path(tmpdir) / f"{name}.py"
111
134
  path.write_text(code)
@@ -118,7 +141,11 @@ def import_string(code, name):
118
141
  return module
119
142
 
120
143
  # %% ../nbs/00_core.ipynb
121
- def import_gist(gist_id, mod_name=None, add_global=True):
144
+ def import_gist(
145
+ gist_id:str, # user/id or just id of gist to import as a module
146
+ mod_name:str=None, # module name to create (taken from gist filename if not passed)
147
+ add_global:bool=True # add module to caller's globals?
148
+ ):
122
149
  "Import gist directly from string without saving to disk"
123
150
  fil = gist_file(gist_id)
124
151
  mod_name = mod_name or Path(fil['filename']).stem
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.1
3
+ Version: 0.0.3
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,9 @@
1
+ dialoghelper/__init__.py,sha256=DyjzzgRJvp3QnEDlrwpSgOvDRy9Thxh14LVq-rV7GgI,42
2
+ dialoghelper/_modidx.py,sha256=1PHT0r4S123iToeVNakiU2Yr2Y-53RX4cZyIxV3RbKQ,2033
3
+ dialoghelper/core.py,sha256=-JuWSExqKql2Wtgf9xpEn9jDbwvpR0dwB-gbUCvromw,5832
4
+ dialoghelper-0.0.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
+ dialoghelper-0.0.3.dist-info/METADATA,sha256=3BjM2WdNrBNx8lQgURp-buL1uGmlXblSP-fBtuFeOvU,2557
6
+ dialoghelper-0.0.3.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
7
+ dialoghelper-0.0.3.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
8
+ dialoghelper-0.0.3.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
9
+ dialoghelper-0.0.3.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- dialoghelper/__init__.py,sha256=XoppFCWM_8XsGAbynKKKg7C3Mca0Kzf_ueJ_7U-l9SE,42
2
- dialoghelper/_modidx.py,sha256=PYuQKjuQ7Xtn6uhXCn0NxhfKNqzABE2m3wSpyt4pGYI,1920
3
- dialoghelper/core.py,sha256=qXF8TeRvvL9aFdrQzAsSdULikTW__pu_L8ysBCqp25s,4672
4
- dialoghelper-0.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
- dialoghelper-0.0.1.dist-info/METADATA,sha256=99dHvGz7e8tkw1Bb1E7jb9UuKWxnoiDqeX0IAE7Kx7g,2557
6
- dialoghelper-0.0.1.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
7
- dialoghelper-0.0.1.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
8
- dialoghelper-0.0.1.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
9
- dialoghelper-0.0.1.dist-info/RECORD,,