dialoghelper 0.0.13__tar.gz → 0.0.15__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.13/dialoghelper.egg-info → dialoghelper-0.0.15}/PKG-INFO +1 -1
- dialoghelper-0.0.15/dialoghelper/__init__.py +2 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper/core.py +20 -12
- {dialoghelper-0.0.13 → dialoghelper-0.0.15/dialoghelper.egg-info}/PKG-INFO +1 -1
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/settings.ini +1 -1
- dialoghelper-0.0.13/dialoghelper/__init__.py +0 -2
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/LICENSE +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/MANIFEST.in +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/README.md +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper/_modidx.py +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper/db_dc.py +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper.egg-info/SOURCES.txt +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper.egg-info/dependency_links.txt +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper.egg-info/entry_points.txt +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper.egg-info/not-zip-safe +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper.egg-info/requires.txt +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/dialoghelper.egg-info/top_level.txt +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/pyproject.toml +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/setup.cfg +0 -0
- {dialoghelper-0.0.13 → dialoghelper-0.0.15}/setup.py +0 -0
|
@@ -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
|
|
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.
|
|
132
|
-
|
|
133
|
-
|
|
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,
|
|
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):
|
|
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
|
|
File without changes
|