= 1
a 'a') find_var(
1
Re-export asdict:
find_var (var:str)
Search for var in all frames of the call stack
call_endp (path, json=False, raiseex=False, **data)
curr_dialog (with_messages:bool=False)
Get the current dialog info.
Type | Default | Details | |
---|---|---|---|
with_messages | bool | False | Include messages as well? |
find_msgs (re_pattern:str='', msg_type:str=None, limit:int=None, include_output:bool=True)
Find list[dict]
of messages in current specific dialog that contain the given information. To refer to a message found later, use its id
field.
Type | Default | Details | |
---|---|---|---|
re_pattern | str | Optional regex to search for (re.DOTALL+re.MULTILINE is used) | |
msg_type | str | None | optional limit by message type (‘code’, ‘note’, or ‘prompt’) |
limit | int | None | Optionally limit number of returned items |
include_output | bool | True | Include output in returned dict? |
# NB: must have a dialogue open including a message with this text in its content
txt = 'tools'
found = find_msgs(txt)
found[0]['content']
'Available tools: &`[add,mult,weather,username]`. Use only where required or requested.'
find_msg_id ()
*Get the message id by searching the call stack for __dialog_id.*
msg_idx (msgid=None)
Get absolute index of message in dialog.
Type | Default | Details | |
---|---|---|---|
msgid | NoneType | None | Message id to find (defaults to current message) |
read_msg (n:int=-1, msgid=None, relative:bool=True)
Get the Message
object indexed in the current dialog.
Type | Default | Details | |
---|---|---|---|
n | int | -1 | Message index (if relative, +ve is downwards) |
msgid | NoneType | None | Message id to find (defaults to current message) |
relative | bool | True | Is n relative to current message (True) or absolute (False)? |
'from solveit.core import rt,app\nfrom fasthtml.common import *\n\ndef add(x:float, y:float):\n "Add x and y"\n return x+y\n\ndef mult(x:float, y:float):\n "Multiply x and y"\n return x*y\n\ndef weather(city:str):\n "Get weather for city"\n return f"Sunny and clear"\n\ndef username():\n "Get username"\n return "jph00"\n'
add_html (content:str)
Send HTML to the browser to be swapped into the DOM
Type | Details | |
---|---|---|
content | str | The HTML to send to the client (generally should include hx-swap-oob) |
del_msg (msgid:str=None)
Delete a message from the dialog.
Type | Default | Details | |
---|---|---|---|
msgid | str | None | id of message to delete |
run_msg (msgid:str=None)
Adds a message to the run queue. Use read_msg to see the output once it runs.
Type | Default | Details | |
---|---|---|---|
msgid | str | None | id of message to execute |
add_msg (content:str, placement:str='add_after', msgid:str=None, msg_type:str='note', output:str='', time_run:str|None='', is_exported:int|None=0, skipped:int|None=0, i_collapsed:int|None=0, o_collapsed:int|None=0, heading_collapsed:int|None=0, pinned:int|None=0)
Add/update a message to the queue to show after code execution completes.
Type | Default | Details | |
---|---|---|---|
content | str | Content of the message (i.e the message prompt, code, or note text) | |
placement | str | add_after | Can be ‘add_after’, ‘add_before’, ‘at_start’, ‘at_end’ |
msgid | str | None | id of message that placement is relative to (if None, uses current message) |
msg_type | str | note | Message type, can be ‘code’, ‘note’, or ‘prompt’ |
output | str | For prompts/code, initial output | |
time_run | str | None | When was message executed | |
is_exported | int | None | 0 | Export message to a module? |
skipped | int | None | 0 | Hide message from prompt? |
i_collapsed | int | None | 0 | Collapse input? |
o_collapsed | int | None | 0 | Collapse output? |
heading_collapsed | int | None | 0 | Collapse heading section? |
pinned | int | None | 0 | Pin to context? |
update_msg (msgid:str=None, msg:Optional[Dict]=None, content:str|None=None, msg_type:str|None=None, output:str|None=None, time_run:str|None=None, is_exported:int|None=None, skipped:int|None=None, i_collapsed:int|None=None, o_collapsed:int|None=None, heading_collapsed:int|None=None, pinned:int|None=None)
Update an existing message. Provide either msg
OR field key/values to update. Use content
param to update contents. Only include parameters to update–missing ones will be left unchanged.
Type | Default | Details | |
---|---|---|---|
msgid | str | None | id of message to update (if None, uses current message) |
msg | Optional | None | Dictionary of field keys/values to update |
content | str | None | None | Content of the message (i.e the message prompt, code, or note text) |
msg_type | str | None | None | Message type, can be ‘code’, ‘note’, or ‘prompt’ |
output | str | None | None | For prompts/code, the output |
time_run | str | None | None | When was message executed |
is_exported | int | None | None | Export message to a module? |
skipped | int | None | None | Hide message from prompt? |
i_collapsed | int | None | None | Collapse input? |
o_collapsed | int | None | None | Collapse output? |
heading_collapsed | int | None | None | Collapse heading section? |
pinned | int | None | None | Pin to context? |
load_gist (gist_id:str)
Retrieve a gist
'https://gist.github.com/jph00/e7cfd4ded593e8ef6217e78a0131960c'
gist_file (gist_id:str)
Get the first file from a gist
"This is a test module which makes some simple tools available."
__all__ = ["hi","whoami"]
testfoo=…
import_string (code:str, name:str)
Type | Details | |
---|---|---|
code | str | Code to import as a module |
name | str | Name of module to create |
is_usable_tool (func:<built-infunctioncallable>)
True if the function has a docstring and all parameters have types, meaning that it can be used as an LLM tool.
mk_toollist (syms)
import_gist (gist_id:str, mod_name:str=None, add_global:bool=True, import_wildcard:bool=False, create_msg:bool=False)
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_wildcard | bool | False | import all exported symbols to caller’s globals |
create_msg | bool | False | Add a message that lists usable tools |
This is how we get a superset of tools to include:
tool_info ()
for o in _all:
s = globals()[o]
if s.__name__[0]=='_' or not s.__doc__: continue
print(f'- &`{s.__name__}`: {s.__doc__}')
- &`find_var`: Search for var in all frames of the call stack
- &`curr_dialog`: Get the current dialog info.
- &`find_msgs`: Find `list[dict]` of messages in current specific dialog that contain the given information. To refer to a message found later, use its `id` field.
- &`find_msg_id`: Get the message id by searching the call stack for __dialog_id.
- &`msg_idx`: Get absolute index of message in dialog.
- &`read_msg`: Get the `Message` object indexed in the current dialog.
- &`add_html`: Send HTML to the browser to be swapped into the DOM
- &`del_msg`: Delete a message from the dialog. Be sure to pass a `sid`, not a `mid`.
- &`add_msg`: Add/update a message to the queue to show after code execution completes.
- &`update_msg`: Update an existing message. Provide either `msg` OR field key/values to update.
Use `content` param to update contents.
Only include parameters to update--missing ones will be left unchanged.
- &`load_gist`: Retrieve a gist
- &`gist_file`: Get the first file from a gist
- &`is_usable_tool`: True if the function has a docstring and all parameters have types, meaning that it can be used as an LLM tool.
- &`import_gist`: Import gist directly from string without saving to disk
- &`asdict`: Convert `o` to a `dict`, supporting dataclasses, namedtuples, iterables, and `__dict__` attrs.