dialoghelper 0.0.1__py3-none-any.whl → 0.0.2__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/core.py CHANGED
@@ -14,15 +14,17 @@ from ghapi.all import *
14
14
  from fastlite import *
15
15
 
16
16
  # %% ../nbs/00_core.ipynb
17
- def get_db():
17
+ def get_db(ns:dict=None):
18
18
  if os.environ.get('IN_SOLVEIT', False): dataparent,nm = Path('/app'),'data.db'
19
19
  else: dataparent,nm = Path('..'),'dev_data.db'
20
20
  db = database(dataparent/'data'/nm)
21
- all_dcs(db)
21
+ dcs = [o for o in all_dcs(db) if o.__name__[0]!='_']
22
+ if ns:
23
+ for o in dcs: ns[o.__name__]=o
22
24
  return db
23
25
 
24
26
  # %% ../nbs/00_core.ipynb
25
- def find_var(var: str):
27
+ def find_var(var:str):
26
28
  "Search for var in all frames of the call stack"
27
29
  frame = inspect.currentframe()
28
30
  while frame:
@@ -37,7 +39,10 @@ def find_dialog_id():
37
39
  return find_var('__dialog_id')
38
40
 
39
41
  # %% ../nbs/00_core.ipynb
40
- def find_msgs(pattern: str, limit=10):
42
+ def find_msgs(
43
+ pattern: str, # Text to search for
44
+ limit:int=10 # Limit number of returned items
45
+ ):
41
46
  "Find messages in a specific dialog that contain the given pattern."
42
47
  did = find_dialog_id()
43
48
  return db.t.message('did=? AND content LIKE ?', [did, f'%{pattern}%'], limit=limit)
@@ -60,8 +65,8 @@ def msg_idx():
60
65
  return ids,ids.index(find_msg_id())
61
66
 
62
67
  # %% ../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)?
68
+ def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
69
+ relative:bool=True # Is `n` relative to current message (True) or absolute (False)?
65
70
  ):
66
71
  "Get the message indexed in the current dialog."
67
72
  ids,idx = msg_idx()
@@ -77,7 +82,7 @@ def add_msg(
77
82
  msg_type: str='note', # message type, can be 'code', 'note', or 'prompt'
78
83
  output='', # for prompts/code, initial output
79
84
  placement='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
80
- msg_id=None
85
+ msg_id:str=None # id of message that placement is relative to (if None, uses current message)
81
86
  ):
82
87
  "Add/update a message to the queue to show after code execution completes."
83
88
  assert msg_type in ('note', 'code', 'prompt'), "msg_type must be 'code', 'note', or 'prompt'."
@@ -86,26 +91,30 @@ def add_msg(
86
91
  run_cmd('add_msg', **kwargs)
87
92
 
88
93
  # %% ../nbs/00_core.ipynb
89
- def update_msg(msg):
94
+ def update_msg(msg:dict):
90
95
  "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)
96
+ if not isinstance(msg,dict): msg = asdict(msg)
97
+ add_msg(content=msg['content'], msg_type=msg['msg_type'], output=msg['output'], placement='update', msg_id=msg['id'])
92
98
 
93
99
  # %% ../nbs/00_core.ipynb
94
- def load_gist(gist_id):
95
- "Get the first file from a gist"
100
+ def load_gist(gist_id:str):
101
+ "Retrieve a gist"
96
102
  api = GhApi()
97
103
  if '/' in gist_id: *_,user,gist_id = gist_id.split('/')
98
104
  else: user = None
99
105
  return api.gists.get(gist_id, user=user)
100
106
 
101
107
  # %% ../nbs/00_core.ipynb
102
- def gist_file(gist_id):
108
+ def gist_file(gist_id:str):
103
109
  "Get the first file from a gist"
104
110
  gist = load_gist(gist_id)
105
111
  return first(gist.files.values())
106
112
 
107
113
  # %% ../nbs/00_core.ipynb
108
- def import_string(code, name):
114
+ def import_string(
115
+ code:str, # Code to import as a module
116
+ name:str # Name of module to create
117
+ ):
109
118
  with TemporaryDirectory() as tmpdir:
110
119
  path = Path(tmpdir) / f"{name}.py"
111
120
  path.write_text(code)
@@ -118,7 +127,11 @@ def import_string(code, name):
118
127
  return module
119
128
 
120
129
  # %% ../nbs/00_core.ipynb
121
- def import_gist(gist_id, mod_name=None, add_global=True):
130
+ def import_gist(
131
+ gist_id:str, # user/id or just id of gist to import as a module
132
+ mod_name:str=None, # module name to create (taken from gist filename if not passed)
133
+ add_global:bool=True # add module to caller's globals?
134
+ ):
122
135
  "Import gist directly from string without saving to disk"
123
136
  fil = gist_file(gist_id)
124
137
  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.2
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=XoppFCWM_8XsGAbynKKKg7C3Mca0Kzf_ueJ_7U-l9SE,42
2
+ dialoghelper/_modidx.py,sha256=PYuQKjuQ7Xtn6uhXCn0NxhfKNqzABE2m3wSpyt4pGYI,1920
3
+ dialoghelper/core.py,sha256=CXlKaFqZp-q7FRKtyeXVc9B7taXN-vRLnAIotpFELkw,5241
4
+ dialoghelper-0.0.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
+ dialoghelper-0.0.2.dist-info/METADATA,sha256=9FaWJbUNQ7FEKrkDWy9rSYQRBqMcaemjqd4mv8hB0xQ,2557
6
+ dialoghelper-0.0.2.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
7
+ dialoghelper-0.0.2.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
8
+ dialoghelper-0.0.2.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
9
+ dialoghelper-0.0.2.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,,