Skip to content

Commit 4fc4b50

Browse files
committed
fixes #15
1 parent a6e0f17 commit 4fc4b50

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

dialoghelper/_modidx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
'doc_host': 'https://AnswerDotAI.github.io',
66
'git_url': 'https://github.com/AnswerDotAI/dialoghelper',
77
'lib_path': 'dialoghelper'},
8-
'syms': { 'dialoghelper.core': { 'dialoghelper.core._msg': ('core.html#_msg', 'dialoghelper/core.py'),
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'),
910
'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),
1011
'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
1112
'dialoghelper.core.add_msg': ('core.html#add_msg', 'dialoghelper/core.py'),

dialoghelper/core.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ def add_msg(
123123
assert msg_type not in ('note') or not output, "'note' messages cannot have an output."
124124
run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)
125125

126+
# %% ../nbs/00_core.ipynb
127+
@delegates(add_msg)
128+
def _add_msg_unsafe(
129+
content:str, # Content of the message (i.e the message prompt, code, or note text)
130+
run:bool=False, # For prompts, send it to the AI; for code, execute it (*DANGEROUS -- be careful of what you run!)
131+
**kwargs
132+
):
133+
"""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).
134+
*WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING"""
135+
add_msg(content=content, run=run, **kwargs)
136+
126137
# %% ../nbs/00_core.ipynb
127138
def _umsg(
128139
content:str|None = None, # Content of the message (i.e the message prompt, code, or note text)

nbs/00_core.ipynb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@
349349
" run_cmd('add_msg', content=content, msg_type=msg_type, output=output, placement=placement, sid=sid, **kwargs)"
350350
]
351351
},
352+
{
353+
"cell_type": "code",
354+
"execution_count": null,
355+
"metadata": {},
356+
"outputs": [],
357+
"source": [
358+
"#| export\n",
359+
"@delegates(add_msg)\n",
360+
"def _add_msg_unsafe(\n",
361+
" content:str, # Content of the message (i.e the message prompt, code, or note text)\n",
362+
" run:bool=False, # For prompts, send it to the AI; for code, execute it (*DANGEROUS -- be careful of what you run!)\n",
363+
" **kwargs\n",
364+
"):\n",
365+
" \"\"\"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).\n",
366+
" *WARNING*--This can execute arbitrary code, so check carefully what you run!--*WARNING\"\"\"\n",
367+
" add_msg(content=content, run=run, **kwargs)"
368+
]
369+
},
352370
{
353371
"cell_type": "code",
354372
"execution_count": null,

0 commit comments

Comments
 (0)