dialoghelper 0.0.12__tar.gz → 0.0.13__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.
- {dialoghelper-0.0.12/dialoghelper.egg-info → dialoghelper-0.0.13}/PKG-INFO +1 -1
- dialoghelper-0.0.13/dialoghelper/__init__.py +2 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper/_modidx.py +4 -2
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper/core.py +48 -17
- {dialoghelper-0.0.12 → dialoghelper-0.0.13/dialoghelper.egg-info}/PKG-INFO +1 -1
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/settings.ini +1 -1
- dialoghelper-0.0.12/dialoghelper/__init__.py +0 -2
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/LICENSE +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/MANIFEST.in +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/README.md +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper/db_dc.py +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper.egg-info/SOURCES.txt +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper.egg-info/dependency_links.txt +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper.egg-info/entry_points.txt +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper.egg-info/not-zip-safe +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper.egg-info/requires.txt +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/dialoghelper.egg-info/top_level.txt +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/pyproject.toml +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/setup.cfg +0 -0
- {dialoghelper-0.0.12 → dialoghelper-0.0.13}/setup.py +0 -0
|
@@ -5,10 +5,11 @@ 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._add_msg_unsafe': ('core.html#_add_msg_unsafe', 'dialoghelper/core.py'),
|
|
9
|
+
'dialoghelper.core._msg': ('core.html#_msg', 'dialoghelper/core.py'),
|
|
9
10
|
'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),
|
|
10
|
-
'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
|
|
11
11
|
'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),
|
|
12
|
+
'dialoghelper.core.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
|
|
12
13
|
'dialoghelper.core.export_dialog': ('core.html#export_dialog', 'dialoghelper/core.py'),
|
|
13
14
|
'dialoghelper.core.find_dialog_id': ('core.html#find_dialog_id', 'dialoghelper/core.py'),
|
|
14
15
|
'dialoghelper.core.find_msg_id': ('core.html#find_msg_id', 'dialoghelper/core.py'),
|
|
@@ -25,5 +26,6 @@ d = { 'settings': { 'branch': 'main',
|
|
|
25
26
|
'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
|
|
26
27
|
'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
|
|
27
28
|
'dialoghelper.core.read_msg_ids': ('core.html#read_msg_ids', 'dialoghelper/core.py'),
|
|
29
|
+
'dialoghelper.core.tool_info': ('core.html#tool_info', 'dialoghelper/core.py'),
|
|
28
30
|
'dialoghelper.core.update_msg': ('core.html#update_msg', 'dialoghelper/core.py')},
|
|
29
31
|
'dialoghelper.db_dc': {}}}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
# %% auto 0
|
|
4
4
|
__all__ = ['Placements', 'empty', 'get_db', 'find_var', 'find_dialog_id', 'find_msgs', 'find_msg_id', 'read_msg_ids', 'msg_idx',
|
|
5
|
-
'read_msg', '
|
|
6
|
-
'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'asdict']
|
|
5
|
+
'read_msg', 'del_msg', 'add_msg', 'update_msg', 'load_gist', 'gist_file', 'import_string', 'is_usable_tool',
|
|
6
|
+
'mk_toollist', 'import_gist', 'export_dialog', 'import_dialog', 'tool_info', 'asdict']
|
|
7
7
|
|
|
8
8
|
# %% ../nbs/00_core.ipynb
|
|
9
9
|
import json, importlib, linecache
|
|
@@ -18,6 +18,9 @@ from ghapi.all import *
|
|
|
18
18
|
from fastlite import *
|
|
19
19
|
from fastcore.xtras import asdict
|
|
20
20
|
from inspect import currentframe,Parameter,signature
|
|
21
|
+
from httpx import get as xget, post as xpost
|
|
22
|
+
from .core import __all__ as _all
|
|
23
|
+
from IPython.display import display,Markdown
|
|
21
24
|
|
|
22
25
|
# %% ../nbs/00_core.ipynb
|
|
23
26
|
_all_ = ["asdict"]
|
|
@@ -93,7 +96,14 @@ def read_msg(n:int=-1, # Message index (if relative, +ve is downwards)
|
|
|
93
96
|
if not 0<=idx<len(ids): return None
|
|
94
97
|
else: idx = n
|
|
95
98
|
db = get_db()
|
|
96
|
-
return db.t.message.
|
|
99
|
+
return db.t.message.selectone('sid=?', [ids[idx]])
|
|
100
|
+
|
|
101
|
+
# %% ../nbs/00_core.ipynb
|
|
102
|
+
def del_msg(
|
|
103
|
+
sid:str=None, # sid (stable id -- pk) of message that placement is relative to (if None, uses current message)
|
|
104
|
+
):
|
|
105
|
+
"Delete a message from the dialog. Be sure to pass a `sid`, not a `mid`."
|
|
106
|
+
xpost('http://localhost:5001/rm_msg_', data=dict(msid=sid)).raise_for_status()
|
|
97
107
|
|
|
98
108
|
# %% ../nbs/00_core.ipynb
|
|
99
109
|
def _msg(
|
|
@@ -119,13 +129,25 @@ def add_msg(
|
|
|
119
129
|
**kwargs
|
|
120
130
|
):
|
|
121
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)."
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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."
|
|
134
|
+
if not sid: sid = find_msg_id()
|
|
135
|
+
data = dict(content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)
|
|
136
|
+
return xpost('http://localhost:5001/add_relative_', data=data).text
|
|
137
|
+
|
|
138
|
+
# %% ../nbs/00_core.ipynb
|
|
139
|
+
@delegates(add_msg)
|
|
140
|
+
def _add_msg_unsafe(
|
|
141
|
+
content:str, # Content of the message (i.e the message prompt, code, or note text)
|
|
142
|
+
run:bool=False, # For prompts, send it to the AI; for code, execute it (*DANGEROUS -- be careful of what you run!)
|
|
143
|
+
**kwargs
|
|
144
|
+
):
|
|
145
|
+
"""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
|
+
*WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
|
|
147
|
+
add_msg(content=content, run=run, **kwargs)
|
|
125
148
|
|
|
126
149
|
# %% ../nbs/00_core.ipynb
|
|
127
150
|
def _umsg(
|
|
128
|
-
content:str|None = None, # Content of the message (i.e the message prompt, code, or note text)
|
|
129
151
|
msg_type: str|None = None, # Message type, can be 'code', 'note', or 'prompt'
|
|
130
152
|
output:str|None = None, # For prompts/code, the output
|
|
131
153
|
time_run: str | None = None, # When was message executed
|
|
@@ -140,8 +162,9 @@ def _umsg(
|
|
|
140
162
|
# %% ../nbs/00_core.ipynb
|
|
141
163
|
@delegates(_umsg)
|
|
142
164
|
def update_msg(
|
|
143
|
-
msg:Optional[Dict]=None, # Dictionary of field keys/values to update
|
|
144
165
|
sid:str=None, # sid (stable id -- pk) of message to update (if None, uses current message)
|
|
166
|
+
content:str|None = None, # Content of the message (i.e the message prompt, code, or note text)
|
|
167
|
+
msg:Optional[Dict]=None, # Dictionary of field keys/values to update
|
|
145
168
|
**kwargs):
|
|
146
169
|
"""Update an existing message. Provide either `msg` OR field key/values to update.
|
|
147
170
|
Use `content` param to update contents. Be sure to pass a `sid` (stable id -- the pk) not a `mid`
|
|
@@ -151,14 +174,7 @@ def update_msg(
|
|
|
151
174
|
sid = kw.pop('sid', sid)
|
|
152
175
|
if not sid: raise TypeError("update_msg needs either a dict message or `sid=...`")
|
|
153
176
|
kw.pop('did', None)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
# %% ../nbs/00_core.ipynb
|
|
157
|
-
def add_html(
|
|
158
|
-
html:str, # HTML to add to the DOM
|
|
159
|
-
):
|
|
160
|
-
"Dynamically add HTML to the current web page. Supports HTMX attrs too."
|
|
161
|
-
run_cmd('add_ft', html=html)
|
|
177
|
+
add_msg(content, placement='update', sid=sid, **kw)
|
|
162
178
|
|
|
163
179
|
# %% ../nbs/00_core.ipynb
|
|
164
180
|
def load_gist(gist_id:str):
|
|
@@ -221,7 +237,9 @@ def import_gist(
|
|
|
221
237
|
syms = [getattr(module, nm) for nm in syms]
|
|
222
238
|
if import_wildcard:
|
|
223
239
|
for sym in syms: glbs[sym.__name__] = sym
|
|
224
|
-
if create_msg:
|
|
240
|
+
if create_msg:
|
|
241
|
+
pref = getattr(module, '__doc__', "Tools added to dialog:")
|
|
242
|
+
add_msg(f"{pref}\n\n{mk_toollist(syms)}")
|
|
225
243
|
return module
|
|
226
244
|
|
|
227
245
|
# %% ../nbs/00_core.ipynb
|
|
@@ -249,3 +267,16 @@ def import_dialog(fname, add_header=True):
|
|
|
249
267
|
add_msg(msg.get('content',''), msg.get('msg_type','note'), msg.get('output',''), 'at_end', **opts)
|
|
250
268
|
if add_header: add_msg(f"# Imported Dialog `{fname}`", 'note', placement='at_end')
|
|
251
269
|
return f"Imported {len(data['messages'])} messages"
|
|
270
|
+
|
|
271
|
+
# %% ../nbs/00_core.ipynb
|
|
272
|
+
def tool_info():
|
|
273
|
+
cts='''Tools available from `dialoghelper`:
|
|
274
|
+
|
|
275
|
+
- &`find_dialog_id`: Get the current dialog id.
|
|
276
|
+
- &`find_msg_id`: Get the current message id.
|
|
277
|
+
- &`find_msgs`: Find messages in current specific dialog that contain the given information.
|
|
278
|
+
- &`read_msg`: Get the message indexed in the current dialog.
|
|
279
|
+
- &`del_msg`: Delete a message from the dialog.
|
|
280
|
+
- &`add_msg`: Add/update a message to the queue to show after code execution completes.
|
|
281
|
+
- &`update_msg`: Update an existing message.'''
|
|
282
|
+
add_msg(cts)
|
|
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
|