dialoghelper


source

get_db

 get_db (ns:dict=None)
db = get_db(globals())
dlg = db.t.dialog.fetchone()
dlg
Dialog(id=1, name='test dialog', mode=2)
Dialog(42, name='The Answer')
Dialog(id=42, name='The Answer', mode=2)

source

find_var

 find_var (var:str)

Search for var in all frames of the call stack

a = 1
find_var('a')
1

source

find_dialog_id

 find_dialog_id ()

*Get the dialog id by searching the call stack for __dialog_id.*

__dialog_id = dlg.id
find_dialog_id()
1

source

find_msgs

 find_msgs (pattern:str, limit:int=10)

Find messages in a specific dialog that contain the given pattern.

Type Default Details
pattern str Text to search for
limit int 10 Limit number of returned items
found = find_msgs('to the')
found[0]
Message(id='msg-a2', sid='_vZxms608LW0aPR_nvIlgqQ', content='*Hello* to the **world**!', output='', input_tokens=13, output_tokens=0, msg_type='note', time_run='', is_exported=0, skipped=1, did=1, i_collapsed=0, o_collapsed=0, header_collapsed=0, pinned=0)

source

find_msg_id

 find_msg_id ()

*Get the message id by searching the call stack for __dialog_id.*

__msg_id = found[0].sid
find_msg_id()
'_vZxms608LW0aPR_nvIlgqQ'

source

read_msg_ids

 read_msg_ids ()

Get all ids in current dialog.


source

msg_idx

 msg_idx ()

Get index of current message in dialog.

ids,idx = msg_idx()
idx
2

source

read_msg

 read_msg (n:int=-1, relative:bool=True)

Get the message indexed in the current dialog.

Type Default Details
n int -1 Message index (if relative, +ve is downwards)
relative bool True Is n relative to current message (True) or absolute (False)?
# Previous message relative to current
read_msg(-1)
Message(id='msg-a1', sid='_I7jB6TkkVt4_sTuQRmhSVw', content='hello world', output='', input_tokens=3, output_tokens=0, msg_type='note', time_run='', is_exported=0, skipped=0, did=1, i_collapsed=0, o_collapsed=0, header_collapsed=0, pinned=0)
# Last message in dialog
read_msg(-1, relative=False)
Message(id='msg-a4', sid='_dZzeZrrPs9ALH5Fjzp-1fw', content='How do I create a new instance?', output='', input_tokens=0, output_tokens=0, msg_type='note', time_run='', is_exported=0, skipped=0, did=1, i_collapsed=0, o_collapsed=0, header_collapsed=0, pinned=0)

source

add_msg

 add_msg (content:str, msg_type:str='note', output='',
          placement='add_after', msg_id:str=None)

Add/update a message to the queue to show after code execution completes.

Type Default Details
content str message that we are updating or adding before/after
msg_type str note message type, can be ‘code’, ‘note’, or ‘prompt’
output str for prompts/code, initial output
placement str add_after can be ‘add_after’, ‘add_before’, ‘update’, ‘at_start’, ‘at_end’
msg_id str None id of message that placement is relative to (if None, uses current message)

source

update_msg

 update_msg (msg:dict)

Update an existing message in the dialog.


source

add_html

 add_html (html:str)

Dynamically add HTML to the current web page. Supports HTMX attrs too.

Type Details
html str HTML to add to the DOM

source

load_gist

 load_gist (gist_id:str)

Retrieve a gist

gistid = 'jph00/e7cfd4ded593e8ef6217e78a0131960c'
gist = load_gist(gistid)
gist.html_url
'https://gist.github.com/jph00/e7cfd4ded593e8ef6217e78a0131960c'

source

gist_file

 gist_file (gist_id:str)

Get the first file from a gist

gfile = gist_file(gistid)
print(gfile.content)
testfoo='testbar'

source

import_string

 import_string (code:str, name:str)
Type Details
code str Code to import as a module
name str Name of module to create

source

import_gist

 import_gist (gist_id:str, mod_name:str=None, add_global:bool=True)

Import gist directly from string without saving to disk

Type Default Details
gist_id str user/id or just id of gist to import as a module
mod_name str None module name to create (taken from gist filename if not passed)
add_global bool True add module to caller’s globals?
import_gist(gistid)
importtest.testfoo
'testbar'