Reference Functions
Code
Convenience functions to process code.
Extract
extract(markdown, language)
Extracts code blocks from markdown
text.
When no language
is specified, a dictionary is retrieved with all code blocks grouped by lanuage. If the blocks contain filename
header, a dictionary of file names is retrieve instead. The default
can contain a dictionary of files to use as defaults.
Param | Type | Description |
---|---|---|
markdown | String | The markdown to extract blocks from. |
language | String | The language of the code blocks to extract. |
default | Any | The default value when code not found, defaults to None . |
Complete
Convenience functions to handle LLM completions
Complete
complete(completion, messages, tools, show)
Finishes completing the completions by printing them, appending messages, or handling tools.
Param | Type | Description |
---|---|---|
completion | String | The completions form the LLM. |
messages | Array | Messages to append replies to, defaults to [] . |
tools | Array | An array of functions to use as tools, defaults [] . |
show | Bool | Print the completions? Defaults to True . |
Describe
describe(funcs)
Describes an array of functions with descriptions, parameters and types. Useful when completing chats.
Param | Type | Description |
---|---|---|
functions | Array | An array of functions to describe. |
Events
Functions to log events.
Event
event(name, details)
Appends the name
event with details
details.
Param | Type | Description |
---|---|---|
name | String | The name of the event. Use kebab-case naming conventions. |
details | String | Details particular to this event. |
IO
Convenience functions to process inputs and outputs.
Input
input (prompt, extract)
Wraps input()
with an optional extract
parameter to convert URLs to text
Param | Type | Description |
---|---|---|
prompt | String | A String, representing a default message before the input. |
extract | Boolean | True to extract the contents of URL as text, defaults to False . Requires the textract package to be installed. |
Load
load (name, default, access)
Reload the contents stored with remember()
with name
.
Param | Type | Description |
---|---|---|
name | String | The file name of the file to load. |
default | Object | The default object when file does not exists. |
Returns the contents of name
file, default
if it does not exist.
Save
save (name, contents, hidden, files, encoding, access)
Saves as name
the given contents
. Useful to share binary files with users.
Param | Type | Description |
---|---|---|
name | String | The file name of the file to save. |
contents | String | The contents of the file to save. |
hidden | Boolean | True to hide file from user, defaults to False . |
files | Dictionary | A dictionary mapping additional file names to contents to save. |
encoding | String | The encoding to use when saving text. |
access | String | Modify access level to user or shared . Defaults to storage to save file for current session. The shared level allows any user using this chat to access this file. The user level allows other sessions for the same user to access the file. |
Saves to name
file the given contents
under the .storage
subfolder. An appropriate extension for the name
will be generated based on the type of contents
.
URL
Convenience functions to process URL prompts.
Is
is_url(prompt)
Tests if prompt
is a URL.
Param | Type | Description |
---|---|---|
prompt | String | The prompt to test. |
Contents
url_contents(prompt)
Retrieves the contents from a prompt
that is a URL.
Param | Type | Description |
---|---|---|
prompt | String | The prompt to retrieve. |