dialoghelper 0.0.3__tar.gz → 0.0.5__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.3/dialoghelper.egg-info → dialoghelper-0.0.5}/PKG-INFO +1 -1
- dialoghelper-0.0.5/dialoghelper/__init__.py +2 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper/_modidx.py +2 -1
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper/core.py +50 -19
- {dialoghelper-0.0.3 → dialoghelper-0.0.5/dialoghelper.egg-info}/PKG-INFO +1 -1
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/settings.ini +1 -1
- dialoghelper-0.0.3/dialoghelper/__init__.py +0 -2
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/LICENSE +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/MANIFEST.in +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/README.md +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper.egg-info/SOURCES.txt +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper.egg-info/dependency_links.txt +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper.egg-info/entry_points.txt +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper.egg-info/not-zip-safe +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper.egg-info/requires.txt +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/dialoghelper.egg-info/top_level.txt +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/pyproject.toml +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/setup.cfg +0 -0
- {dialoghelper-0.0.3 → dialoghelper-0.0.5}/setup.py +0 -0
|
@@ -5,7 +5,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
5
5
|
'doc_host': 'https://AnswerDotAI.github.io',
|
|
6
6
|
'git_url': 'https://github.com/AnswerDotAI/dialoghelper',
|
|
7
7
|
'lib_path': 'dialoghelper'},
|
|
8
|
-
'syms': { 'dialoghelper.core': { 'dialoghelper.core.
|
|
8
|
+
'syms': { 'dialoghelper.core': { 'dialoghelper.core._msg': ('core.html#_msg', 'dialoghelper/core.py'),
|
|
9
|
+
'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
|
|
9
10
|
'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
|
|
10
11
|
'dialoghelper.core.find_dialog_id': ('core.html#find_dialog_id', 'dialoghelper/core.py'),
|
|
11
12
|
'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
|
|
@@ -2,16 +2,22 @@
|
|
|
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
|
|
|
12
13
|
from fastcore.utils import *
|
|
14
|
+
from fastcore.meta import delegates
|
|
13
15
|
from ghapi.all import *
|
|
14
16
|
from fastlite import *
|
|
17
|
+
from fastcore.xtras import asdict
|
|
18
|
+
|
|
19
|
+
# %% ../nbs/00_core.ipynb
|
|
20
|
+
_all_ = ["asdict"]
|
|
15
21
|
|
|
16
22
|
# %% ../nbs/00_core.ipynb
|
|
17
23
|
def get_db(ns:dict=None):
|
|
@@ -47,7 +53,8 @@ def find_msgs(
|
|
|
47
53
|
"Find messages in a specific dialog that contain the given pattern."
|
|
48
54
|
did = find_dialog_id()
|
|
49
55
|
db = get_db()
|
|
50
|
-
|
|
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]
|
|
51
58
|
|
|
52
59
|
# %% ../nbs/00_core.ipynb
|
|
53
60
|
def find_msg_id():
|
|
@@ -59,7 +66,7 @@ def read_msg_ids():
|
|
|
59
66
|
"Get all ids in current dialog."
|
|
60
67
|
did = find_dialog_id()
|
|
61
68
|
db = get_db()
|
|
62
|
-
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')]
|
|
63
70
|
|
|
64
71
|
# %% ../nbs/00_core.ipynb
|
|
65
72
|
def msg_idx():
|
|
@@ -81,27 +88,51 @@ def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
|
|
|
81
88
|
return db.t.message.fetchone('sid=?', [ids[idx]])
|
|
82
89
|
|
|
83
90
|
# %% ../nbs/00_core.ipynb
|
|
91
|
+
def _msg(
|
|
92
|
+
input_tokens: int | None = 0,
|
|
93
|
+
output_tokens: int | None = 0,
|
|
94
|
+
time_run: str | None = '',
|
|
95
|
+
is_exported: int | None = 0,
|
|
96
|
+
skipped: int | None = 0,
|
|
97
|
+
did: int | None = None,
|
|
98
|
+
i_collapsed: int | None = 0,
|
|
99
|
+
o_collapsed: int | None = 0,
|
|
100
|
+
header_collapsed: int | None = 0,
|
|
101
|
+
pinned: int | None = 0
|
|
102
|
+
): ...
|
|
103
|
+
|
|
104
|
+
# %% ../nbs/00_core.ipynb
|
|
105
|
+
@delegates(_msg)
|
|
84
106
|
def add_msg(
|
|
85
|
-
content:str, # message
|
|
107
|
+
content:str, # content of the message (i.e the message prompt, code, or note text)
|
|
86
108
|
msg_type: str='note', # message type, can be 'code', 'note', or 'prompt'
|
|
87
|
-
output='', # for prompts/code, initial output
|
|
88
|
-
placement='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
|
|
89
|
-
|
|
90
|
-
**
|
|
109
|
+
output:str='', # for prompts/code, initial output
|
|
110
|
+
placement:str='add_after', # can be 'add_after', 'add_before', 'update', 'at_start', 'at_end'
|
|
111
|
+
sid:str=None, # id of message that placement is relative to (if None, uses current message)
|
|
112
|
+
**kwargs # additional Message fields such as skipped i/o_collapsed, etc, passed through to the server
|
|
91
113
|
):
|
|
92
114
|
"Add/update a message to the queue to show after code execution completes."
|
|
93
115
|
assert msg_type in ('note', 'code', 'prompt'), "msg_type must be 'code', 'note', or 'prompt'."
|
|
94
|
-
|
|
95
|
-
run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement,
|
|
96
|
-
|
|
97
|
-
# %% ../nbs/00_core.ipynb
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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)
|
|
105
136
|
|
|
106
137
|
# %% ../nbs/00_core.ipynb
|
|
107
138
|
def add_html(
|
|
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
|