dialoghelper 0.0.29__py3-none-any.whl → 0.0.30__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.29"
1
+ __version__ = "0.0.30"
2
2
  from .core import *
dialoghelper/_modidx.py CHANGED
@@ -12,6 +12,7 @@ d = { 'settings': { 'branch': 'main',
12
12
  'dialoghelper.core.call_endp': ('core.html#call_endp', 'dialoghelper/core.py'),
13
13
  'dialoghelper.core.curr_dialog': ('core.html#curr_dialog', 'dialoghelper/core.py'),
14
14
  'dialoghelper.core.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
15
+ 'dialoghelper.core.find_dname': ('core.html#find_dname', 'dialoghelper/core.py'),
15
16
  'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
16
17
  'dialoghelper.core.find_msgs': ('core.html#find_msgs', 'dialoghelper/core.py'),
17
18
  'dialoghelper.core.find_var': ('core.html#find_var', 'dialoghelper/core.py'),
dialoghelper/core.py CHANGED
@@ -1,9 +1,9 @@
1
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
2
2
 
3
3
  # %% auto 0
4
- __all__ = ['Placements', 'empty', 'find_var', 'call_endp', 'curr_dialog', 'find_msgs', 'find_msg_id', 'msg_idx', 'read_msg',
5
- 'add_html', 'del_msg', 'run_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string',
6
- 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'asdict']
4
+ __all__ = ['Placements', 'empty', 'find_var', 'call_endp', 'find_dname', 'find_msg_id', 'curr_dialog', 'find_msgs', 'msg_idx',
5
+ 'read_msg', 'add_html', 'del_msg', 'run_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file',
6
+ 'import_string', 'is_usable_tool', 'mk_toollist', 'import_gist', 'tool_info', 'asdict']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
9
  import json, importlib, linecache
@@ -37,74 +37,90 @@ def find_var(var:str):
37
37
  raise ValueError(f"Could not find {var} in any scope")
38
38
 
39
39
  # %% ../nbs/00_core.ipynb
40
- def call_endp(path, json=False, raiseex=False, **data):
40
+ def call_endp(path, dname='', json=False, raiseex=False, **data):
41
+ if not dname: dname = find_dname()
42
+ data['dlg_name'] = dname
41
43
  res = xpost(f'http://localhost:5001/{path}', data=data)
42
44
  if raiseex: res.raise_for_status()
43
- return res.json() if json else res.text
45
+ try: return res.json() if json else res.text
46
+ except Exception as e: return str(e)
47
+
48
+ # %% ../nbs/00_core.ipynb
49
+ def find_dname():
50
+ "Get the message id by searching the call stack for __dialog_id."
51
+ return find_var('__dialog_name')
52
+
53
+ # %% ../nbs/00_core.ipynb
54
+ def find_msg_id():
55
+ "Get the message id by searching the call stack for __dialog_id."
56
+ return find_var('__msg_id')
44
57
 
45
58
  # %% ../nbs/00_core.ipynb
46
59
  def curr_dialog(
47
- with_messages:bool=False # Include messages as well?
60
+ with_messages:bool=False, # Include messages as well?
61
+ dname:str='' # Running dialog to get info for; defaults to current dialog
48
62
  ):
49
63
  "Get the current dialog info."
50
- return call_endp('curr_dialog_', json=True, with_messages=with_messages)
64
+ res = call_endp('curr_dialog_', dname, json=True, with_messages=with_messages)
65
+ if res: return {'name': res['name'], 'mode': res['mode']}
51
66
 
52
67
  # %% ../nbs/00_core.ipynb
53
68
  def find_msgs(
54
69
  re_pattern:str='', # Optional regex to search for (re.DOTALL+re.MULTILINE is used)
55
70
  msg_type:str=None, # optional limit by message type ('code', 'note', or 'prompt')
56
71
  limit:int=None, # Optionally limit number of returned items
57
- include_output:bool=True # Include output in returned dict?
72
+ include_output:bool=True, # Include output in returned dict?
73
+ dname:str='' # Running dialog to get info for; defaults to current dialog
58
74
  ):
59
75
  "Find `list[dict]` of messages in current specific dialog that contain the given information. To refer to a message found later, use its `id` field."
60
- res = call_endp('find_msgs_', json=True, re_pattern=re_pattern, msg_type=msg_type, limit=limit)['msgs']
76
+ res = call_endp('find_msgs_', dname, json=True, re_pattern=re_pattern, msg_type=msg_type, limit=limit)['msgs']
61
77
  if not include_output:
62
78
  for o in res: o.pop('output', None)
63
79
  return res
64
80
 
65
- # %% ../nbs/00_core.ipynb
66
- def find_msg_id():
67
- "Get the message id by searching the call stack for __dialog_id."
68
- return find_var('__msg_id')
69
-
70
81
  # %% ../nbs/00_core.ipynb
71
82
  def msg_idx(
72
83
  msgid=None, # Message id to find (defaults to current message)
84
+ dname:str='' # Running dialog to get info for; defaults to current dialog
73
85
  ):
74
86
  "Get absolute index of message in dialog."
75
87
  if not msgid: msgid = find_msg_id()
76
- return call_endp('msg_idx_', json=True, msgid=msgid)['msgid']
88
+ return call_endp('msg_idx_', dname, json=True, msgid=msgid)['msgid']
77
89
 
78
90
  # %% ../nbs/00_core.ipynb
79
91
  def read_msg(
80
92
  n:int=-1, # Message index (if relative, +ve is downwards)
81
93
  msgid=None, # Message id to find (defaults to current message)
82
- relative:bool=True # Is `n` relative to current message (True) or absolute (False)?
94
+ relative:bool=True, # Is `n` relative to current message (True) or absolute (False)?
95
+ dname:str='' # Running dialog to get info for; defaults to current dialog
83
96
  ):
84
97
  "Get the `Message` object indexed in the current dialog."
85
98
  if not msgid: msgid = find_msg_id()
86
- return call_endp('read_msg_', json=True, msgid=msgid, n=n, relative=relative)['msg']
99
+ return call_endp('read_msg_', dname, json=True, msgid=msgid, n=n, relative=relative)['msg']
87
100
 
88
101
  # %% ../nbs/00_core.ipynb
89
102
  def add_html(
90
103
  content:str, # The HTML to send to the client (generally should include hx-swap-oob)
104
+ dname:str='' # Running dialog to get info for; defaults to current dialog
91
105
  ):
92
106
  "Send HTML to the browser to be swapped into the DOM"
93
- call_endp('add_html_', content=to_xml(content))
107
+ call_endp('add_html_', dname, content=to_xml(content))
94
108
 
95
109
  # %% ../nbs/00_core.ipynb
96
110
  def del_msg(
97
111
  msgid:str=None, # id of message to delete
112
+ dname:str='' # Running dialog to get info for; defaults to current dialog
98
113
  ):
99
114
  "Delete a message from the dialog."
100
- call_endp('rm_msg_', raiseex=True, msid=msgid)
115
+ call_endp('rm_msg_', dname, raiseex=True, msid=msgid)
101
116
 
102
117
  # %% ../nbs/00_core.ipynb
103
118
  def run_msg(
104
119
  msgid:str=None, # id of message to execute
120
+ dname:str='' # Running dialog to get info for; defaults to current dialog
105
121
  ):
106
122
  "Adds a message to the run queue. Use read_msg to see the output once it runs."
107
- return call_endp('add_runq_', msgid=msgid, api=True)
123
+ return call_endp('add_runq_', dname, msgid=msgid, api=True)
108
124
 
109
125
  # %% ../nbs/00_core.ipynb
110
126
  Placements = str_enum('Placements', 'add_after', 'add_before', 'at_start', 'at_end')
@@ -123,11 +139,12 @@ def add_msg(
123
139
  o_collapsed: int | None = 0, # Collapse output?
124
140
  heading_collapsed: int | None = 0, # Collapse heading section?
125
141
  pinned: int | None = 0, # Pin to context?
142
+ dname:str='' # Running dialog to get info for; defaults to current dialog
126
143
  ):
127
144
  "Add/update a message to the queue to show after code execution completes."
128
145
  if placement not in ('at_start','at_end') and not msgid: msgid = find_msg_id()
129
146
  return call_endp(
130
- 'add_relative_', content=content, placement=placement, msgid=msgid, msg_type=msg_type, output=output,
147
+ 'add_relative_', dname, content=content, placement=placement, msgid=msgid, msg_type=msg_type, output=output,
131
148
  time_run=time_run, is_exported=is_exported, skipped=skipped, pinned=pinned,
132
149
  i_collapsed=i_collapsed, o_collapsed=o_collapsed, heading_collapsed=heading_collapsed)
133
150
 
@@ -143,8 +160,9 @@ def _add_msg_unsafe(
143
160
  """Add/update a message to the queue to show after code execution completes, and optionally run it. Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change).
144
161
  *WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
145
162
  if placement not in ('at_start','at_end') and not msgid: msgid = find_msg_id()
163
+ dname = kwargs.pop('dname')
146
164
  return call_endp(
147
- 'add_relative_', content=content, placement=placement, msgid=msgid, run=run, **kwargs)
165
+ 'add_relative_', dname, content=content, placement=placement, msgid=msgid, run=run, **kwargs)
148
166
 
149
167
  # %% ../nbs/00_core.ipynb
150
168
  def _umsg(
@@ -165,12 +183,13 @@ def _umsg(
165
183
  def update_msg(
166
184
  msgid:str=None, # id of message to update (if None, uses current message)
167
185
  msg:Optional[Dict]=None, # Dictionary of field keys/values to update
186
+ dname:str='', # Running dialog to get info for; defaults to current dialog
168
187
  **kwargs):
169
188
  """Update an existing message. Provide either `msg` OR field key/values to update.
170
189
  Use `content` param to update contents.
171
190
  Only include parameters to update--missing ones will be left unchanged."""
172
191
  if not msgid and not msg: raise TypeError("update_msg needs either a dict message or `msgid=`")
173
- return call_endp('add_relative_', placement='update', msgid=msgid, **kwargs)
192
+ return call_endp('add_relative_', dname, placement='update', msgid=msgid, **kwargs)
174
193
 
175
194
  # %% ../nbs/00_core.ipynb
176
195
  def load_gist(gist_id:str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.29
3
+ Version: 0.0.30
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,12 @@
1
+ dialoghelper/__init__.py,sha256=Y4J_58Un2NkktVq246vbfUB1fr9alL7LxlQNIsZE5ec,43
2
+ dialoghelper/_modidx.py,sha256=Au4FWcKVoSRyKPwVeiqCCKTL8cZ2vGPnjgk4FQfMlyg,4273
3
+ dialoghelper/core.py,sha256=c7wGjFYucWTCDfOYGex3QX728elUdqGR34FfxsspvsA,12319
4
+ dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
+ dialoghelper/experimental.py,sha256=yTXzyY37MPW-9mqzbem-q6CCPXElN0GwAyOK-iJofMY,3910
6
+ dialoghelper/screenshot.js,sha256=DDqlRhemwj8I0AloxMJBnBqDDIqu5knlT1lpG_0rphI,4851
7
+ dialoghelper-0.0.30.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ dialoghelper-0.0.30.dist-info/METADATA,sha256=PhB6_-rVkKRmbPunN35xi7qJpZ1HeS7BQkjOXCGQpcY,2637
9
+ dialoghelper-0.0.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ dialoghelper-0.0.30.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
+ dialoghelper-0.0.30.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
+ dialoghelper-0.0.30.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- dialoghelper/__init__.py,sha256=WbA03-_Zk9_bs1UWTpY7lBis1mVY0z7IJ3-qkKikrHE,43
2
- dialoghelper/_modidx.py,sha256=haFiPtlNF3j0tsHG-ODfyiy85H1OTbbdjR3ojhP6K4U,4156
3
- dialoghelper/core.py,sha256=U9FvC8ZR6-v7X_PoP-D2etYrZX_Agzed5xpyNFL6a-8,11160
4
- dialoghelper/db_dc.py,sha256=mi2Q2am_SoAPGpNQg7KPFS5pR9WEapRXT8ypkNmMfw0,2330
5
- dialoghelper/experimental.py,sha256=yTXzyY37MPW-9mqzbem-q6CCPXElN0GwAyOK-iJofMY,3910
6
- dialoghelper/screenshot.js,sha256=DDqlRhemwj8I0AloxMJBnBqDDIqu5knlT1lpG_0rphI,4851
7
- dialoghelper-0.0.29.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- dialoghelper-0.0.29.dist-info/METADATA,sha256=koS3q01TrcrDbKaWXZJXFyCryirDDUvvKDIq3ck-buM,2637
9
- dialoghelper-0.0.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- dialoghelper-0.0.29.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
11
- dialoghelper-0.0.29.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
12
- dialoghelper-0.0.29.dist-info/RECORD,,