dialoghelper 0.0.4__py3-none-any.whl → 0.0.5__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 +1 -1
- dialoghelper/core.py +31 -15
- {dialoghelper-0.0.4.dist-info → dialoghelper-0.0.5.dist-info}/METADATA +1 -1
- dialoghelper-0.0.5.dist-info/RECORD +9 -0
- dialoghelper-0.0.4.dist-info/RECORD +0 -9
- {dialoghelper-0.0.4.dist-info → dialoghelper-0.0.5.dist-info}/WHEEL +0 -0
- {dialoghelper-0.0.4.dist-info → dialoghelper-0.0.5.dist-info}/entry_points.txt +0 -0
- {dialoghelper-0.0.4.dist-info → dialoghelper-0.0.5.dist-info}/licenses/LICENSE +0 -0
- {dialoghelper-0.0.4.dist-info → dialoghelper-0.0.5.dist-info}/top_level.txt +0 -0
dialoghelper/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.5"
|
|
2
2
|
from .core import *
|
dialoghelper/core.py
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
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', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist']
|
|
5
|
+
'update_msg', 'add_html', 'load_gist', 'gist_file', 'import_string', 'import_gist', 'asdict']
|
|
6
6
|
|
|
7
7
|
# %% ../nbs/00_core.ipynb
|
|
8
8
|
import inspect, json, importlib, linecache
|
|
9
|
+
from typing import Dict
|
|
9
10
|
from tempfile import TemporaryDirectory
|
|
10
11
|
from ipykernel_helper import *
|
|
11
12
|
|
|
@@ -13,6 +14,10 @@ from fastcore.utils import *
|
|
|
13
14
|
from fastcore.meta import delegates
|
|
14
15
|
from ghapi.all import *
|
|
15
16
|
from fastlite import *
|
|
17
|
+
from fastcore.xtras import asdict
|
|
18
|
+
|
|
19
|
+
# %% ../nbs/00_core.ipynb
|
|
20
|
+
_all_ = ["asdict"]
|
|
16
21
|
|
|
17
22
|
# %% ../nbs/00_core.ipynb
|
|
18
23
|
def get_db(ns:dict=None):
|
|
@@ -48,7 +53,8 @@ def find_msgs(
|
|
|
48
53
|
"Find messages in a specific dialog that contain the given pattern."
|
|
49
54
|
did = find_dialog_id()
|
|
50
55
|
db = get_db()
|
|
51
|
-
|
|
56
|
+
res = db.t.message('did=? AND content LIKE ? ORDER BY mid', [did, f'%{pattern}%'], limit=limit)
|
|
57
|
+
return [asdict(o) for o in res]
|
|
52
58
|
|
|
53
59
|
# %% ../nbs/00_core.ipynb
|
|
54
60
|
def find_msg_id():
|
|
@@ -60,7 +66,7 @@ def read_msg_ids():
|
|
|
60
66
|
"Get all ids in current dialog."
|
|
61
67
|
did = find_dialog_id()
|
|
62
68
|
db = get_db()
|
|
63
|
-
return [o.sid for o in db.t.message('did=?', [did], select='sid', order_by='
|
|
69
|
+
return [o.sid for o in db.t.message('did=?', [did], select='sid', order_by='mid')]
|
|
64
70
|
|
|
65
71
|
# %% ../nbs/00_core.ipynb
|
|
66
72
|
def msg_idx():
|
|
@@ -98,25 +104,35 @@ def _msg(
|
|
|
98
104
|
# %% ../nbs/00_core.ipynb
|
|
99
105
|
@delegates(_msg)
|
|
100
106
|
def add_msg(
|
|
101
|
-
content:str, # message
|
|
107
|
+
content:str, # content of the message (i.e the message prompt, code, or note text)
|
|
102
108
|
msg_type: str='note', # message type, can be 'code', 'note', or 'prompt'
|
|
103
109
|
output:str='', # for prompts/code, initial output
|
|
104
110
|
placement:str='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
|
|
105
|
-
|
|
111
|
+
sid:str=None, # id of message that placement is relative to (if None, uses current message)
|
|
106
112
|
**kwargs # additional Message fields such as skipped i/o_collapsed, etc, passed through to the server
|
|
107
113
|
):
|
|
108
114
|
"Add/update a message to the queue to show after code execution completes."
|
|
109
115
|
assert msg_type in ('note', 'code', 'prompt'), "msg_type must be 'code', 'note', or 'prompt'."
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
assert msg_type not in ('note') or not output, "'note' messages cannot have an output."
|
|
117
|
+
run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)
|
|
118
|
+
|
|
119
|
+
# %% ../nbs/00_core.ipynb
|
|
120
|
+
@delegates(add_msg)
|
|
121
|
+
def update_msg(
|
|
122
|
+
msg:Optional[Dict]=None, # Dictionary of field keys/values to update
|
|
123
|
+
sid:str=None, # id of message that placement is relative to (if None, uses current message)
|
|
124
|
+
content:str=None, # content of the message (i.e the message prompt, code, or note text)
|
|
125
|
+
**kwargs):
|
|
126
|
+
"Update an existing message. Provide either `msg` OR field key/values to update. Use `content` param to update contents."
|
|
127
|
+
if content: kwargs['content']=content
|
|
128
|
+
assert bool(msg)^bool(kwargs), "Provide *either* msg, for kwargs, not both"
|
|
129
|
+
if msg and 'sid' in msg: target_id = msg['sid']
|
|
130
|
+
elif sid: target_id = sid
|
|
131
|
+
else: raise TypeError("update_msg needs either a dict message or `sid=...`")
|
|
132
|
+
old = asdict(get_db().t.message[target_id])
|
|
133
|
+
kw = old | (msg or {}) | kwargs
|
|
134
|
+
kw.pop('did', None)
|
|
135
|
+
return add_msg(placement='update', **kw)
|
|
120
136
|
|
|
121
137
|
# %% ../nbs/00_core.ipynb
|
|
122
138
|
def add_html(
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
dialoghelper/__init__.py,sha256=vcF3PxICb5jmbcz0MoaVcpqURhdQQbFoHZ8V2L6D5Ls,42
|
|
2
|
+
dialoghelper/_modidx.py,sha256=FU_XLF5YTthjS3HZvq0MFMKHDDfGc3ll1i_jCKCJsc4,2138
|
|
3
|
+
dialoghelper/core.py,sha256=NzAdDsrZXDIpWxb2q7H20_uKENFjh1QcQg39pxGJTck,6954
|
|
4
|
+
dialoghelper-0.0.5.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
dialoghelper-0.0.5.dist-info/METADATA,sha256=wfMk6GCTiVwxO3owOyZ500kcb_Vjk3U8zZuP6YddKJY,2557
|
|
6
|
+
dialoghelper-0.0.5.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
7
|
+
dialoghelper-0.0.5.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
|
|
8
|
+
dialoghelper-0.0.5.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
|
|
9
|
+
dialoghelper-0.0.5.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
dialoghelper/__init__.py,sha256=aeFr0PgPk9_EeMwvlUatX5uddiE_ZoYCKQ5DBD_vHbQ,42
|
|
2
|
-
dialoghelper/_modidx.py,sha256=FU_XLF5YTthjS3HZvq0MFMKHDDfGc3ll1i_jCKCJsc4,2138
|
|
3
|
-
dialoghelper/core.py,sha256=gszlBxzbBAsvtYCmb8TOoo0_V5Tkis-p0Tj5d8qwObY,6213
|
|
4
|
-
dialoghelper-0.0.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
dialoghelper-0.0.4.dist-info/METADATA,sha256=0dujOBPynlQB76DFRWYU0zczFeEYQi03sp2EkqtcGPo,2557
|
|
6
|
-
dialoghelper-0.0.4.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
7
|
-
dialoghelper-0.0.4.dist-info/entry_points.txt,sha256=wvDeX-XTS_XVjWiiPQe6yVfmyNwy9eCr36ewp9baFIg,46
|
|
8
|
-
dialoghelper-0.0.4.dist-info/top_level.txt,sha256=VXLlkgltFs_q-XB9imt2G64I_-MPm1RnxlpvUWPuLKM,13
|
|
9
|
-
dialoghelper-0.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|