dialoghelper 0.0.13__py3-none-any.whl → 0.0.15__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.
dialoghelper/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "0.0.13"
1
+ __version__ = "0.0.15"
2
2
  from .core import *
dialoghelper/core.py CHANGED
@@ -57,8 +57,8 @@ def find_msgs(
57
57
  msg_type:str=None, # optional limit by message type ('code', 'note', or 'prompt')
58
58
  limit:int=None, # Optionally limit number of returned items
59
59
  include_output:bool=True # Include output in returned dict?
60
- ):
61
- "Find messages in current specific dialog that contain the given information. To refer to a message found later, use its `sid` field (which is the pk)."
60
+ )->list[dict]:
61
+ "Find `list[dict]` of messages in current specific dialog that contain the given information. To refer to a message found later, use its `sid` field (which is the pk)."
62
62
  did = find_dialog_id()
63
63
  db = get_db()
64
64
  res = db.t.message('did=? AND content LIKE ? ORDER BY mid', [did, f'%{pattern}%'], limit=limit)
@@ -73,7 +73,7 @@ def find_msg_id():
73
73
  return find_var('__msg_id')
74
74
 
75
75
  # %% ../nbs/00_core.ipynb
76
- def read_msg_ids():
76
+ def read_msg_ids()->list[str]:
77
77
  "Get all ids in current dialog."
78
78
  did = find_dialog_id()
79
79
  db = get_db()
@@ -89,7 +89,7 @@ def msg_idx():
89
89
  def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
90
90
  relative:bool=True # Is `n` relative to current message (True) or absolute (False)?
91
91
  ):
92
- "Get the message indexed in the current dialog."
92
+ "Get the `Message` object indexed in the current dialog."
93
93
  ids,idx = msg_idx()
94
94
  if relative:
95
95
  idx = idx+n
@@ -107,6 +107,8 @@ def del_msg(
107
107
 
108
108
  # %% ../nbs/00_core.ipynb
109
109
  def _msg(
110
+ msg_type: str='note', # Message type, can be 'code', 'note', or 'prompt'
111
+ output:str='', # For prompts/code, initial output
110
112
  time_run: str | None = '', # When was message executed
111
113
  is_exported: int | None = 0, # Export message to a module?
112
114
  skipped: int | None = 0, # Hide message from prompt?
@@ -122,17 +124,23 @@ Placements = str_enum('Placements', 'add_after', 'add_before', 'update', 'at_sta
122
124
  @delegates(_msg)
123
125
  def add_msg(
124
126
  content:str, # Content of the message (i.e the message prompt, code, or note text)
125
- msg_type: str='note', # Message type, can be 'code', 'note', or 'prompt'
126
- output:str='', # For prompts/code, initial output
127
127
  placement:str='add_after', # Can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
128
128
  sid:str=None, # sid (stable id -- pk) of message that placement is relative to (if None, uses current message)
129
129
  **kwargs
130
130
  ):
131
- "Add/update a message to the queue to show after code execution completes. Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change)."
132
- if msg_type not in ('note', 'code', 'prompt'): return "msg_type must be 'code', 'note', or 'prompt'."
133
- if msg_type=='note' and output: return "note messages cannot have an output."
131
+ """Add/update a message to the queue to show after code execution completes.
132
+ Be sure to pass a `sid` (stable id) not a `mid` (which is used only for sorting, and can change).
133
+ Sets msg_type to 'note' by default if not update placement."""
134
+ if 'msg_type' not in kwargs and placement!='update': kwargs['msg_type']='note'
135
+ mt = kwargs.get('msg_type',None)
136
+ ot = kwargs.get('output',None)
137
+ if mt and mt not in ('note', 'code', 'prompt'): return "msg_type must be 'code', 'note', or 'prompt'."
138
+ if mt=='note' and ot: return "note messages cannot have an output."
139
+ if mt=='code':
140
+ try: json.loads(ot or '[]')
141
+ except: return "Code output must be valid json"
134
142
  if not sid: sid = find_msg_id()
135
- data = dict(content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)
143
+ data = dict(content=content, placement=placement, sid=sid, **kwargs)
136
144
  return xpost('http://localhost:5001/add_relative_', data=data).text
137
145
 
138
146
  # %% ../nbs/00_core.ipynb
@@ -144,7 +152,7 @@ def _add_msg_unsafe(
144
152
  ):
145
153
  """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).
146
154
  *WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
147
- add_msg(content=content, run=run, **kwargs)
155
+ return add_msg(content=content, run=run, **kwargs)
148
156
 
149
157
  # %% ../nbs/00_core.ipynb
150
158
  def _umsg(
@@ -174,7 +182,7 @@ def update_msg(
174
182
  sid = kw.pop('sid', sid)
175
183
  if not sid: raise TypeError("update_msg needs either a dict message or `sid=...`")
176
184
  kw.pop('did', None)
177
- add_msg(content, placement='update', sid=sid, **kw)
185
+ return add_msg(content, placement='update', sid=sid, **kw)
178
186
 
179
187
  # %% ../nbs/00_core.ipynb
180
188
  def load_gist(gist_id:str):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dialoghelper
3
- Version: 0.0.13
3
+ Version: 0.0.15
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=dXuF6Y3XUXblN4PkEpkmXrD8vDPhYo7XLaXILawxjwQ,43
2
+ dialoghelper/_modidx.py,sha256=BmhVoIv53snN6JQm_EzJp-bu793QuY7EZg2hKaq5_7E,3013
3
+ dialoghelper/core.py,sha256=8DlmNRQT4PeMWychhQETXAJKgJ72Z8CjEW09Zh_VgJk,12562
4
+ dialoghelper/db_dc.py,sha256=ieSie_K1HHXACEJVZ0rMkD_uo42GgmMqqKDYrodjhtM,2297
5
+ dialoghelper-0.0.15.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
+ dialoghelper-0.0.15.dist-info/METADATA,sha256=G4p7L6QivWW736VWNazRXXmNW3nvVSast69RUKesQrM,2558
7
+ dialoghelper-0.0.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ dialoghelper-0.0.15.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
+ dialoghelper-0.0.15.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
+ dialoghelper-0.0.15.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- dialoghelper/__init__.py,sha256=7byX0N8qjtMnanYWGgpBm__8aWTi6sy6Thzt4kYvjaQ,43
2
- dialoghelper/_modidx.py,sha256=BmhVoIv53snN6JQm_EzJp-bu793QuY7EZg2hKaq5_7E,3013
3
- dialoghelper/core.py,sha256=IOnjRTU8oaJPpzt9sOBSmYGumZuZT0j1QOmBhql9kJY,12205
4
- dialoghelper/db_dc.py,sha256=ieSie_K1HHXACEJVZ0rMkD_uo42GgmMqqKDYrodjhtM,2297
5
- dialoghelper-0.0.13.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
6
- dialoghelper-0.0.13.dist-info/METADATA,sha256=GwWpTw4e3hkbKus7m_Ks-5P4YfrwGLvo-t1vo_rmjjo,2558
7
- dialoghelper-0.0.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- dialoghelper-0.0.13.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
9
- dialoghelper-0.0.13.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
10
- dialoghelper-0.0.13.dist-info/RECORD,,