Chat Scripts
Apply custom logic to actions in chats.
Last updated
Apply custom logic to actions in chats.
Last updated
Chat scripts are simple Python expressions. They're used for data manipulation in certain AI assistant actions triggered during a chat.
The following actions support chat scripts. To display a variable's value within an AI assistant's action content, enclose the variable name within curly braces { }
as a delimiter.
{ … }
is required to print out variable/script values.
_.dt_diff(datetime1, datetime2, unit)
Calculates the difference between two datetime objects and returns the result in the specified time unit. Unit - d for day, h for hour, m for minute, s for second, e.g.:
_.fmt(string, value)
Formats the specified value(s) and insert them inside the string's placeholder, e.g.:
_.format_time(datetime, format, timezone)
Format datetime, e.g.:
_.join(separator, items)
Join all items in a tuple into a string, using a character as a separator, e.g.:
_.json_parse(data)
Parses a JSON string and returns a Python object, e.g.:
_.json_stringify(data)
Serialises Python objects into JSON format. It returns a JSON string representing the input data, e.g.:
_.len(x)
The number of characters in a variable, e.g.:
_.lower(string)
Convert string to lowercase, e.g.:
_.now(timezone, format)
Retrieves the current date and time in the Coordinated Universal Time (UTC) timezone. If a timezone is define, it would display the current year and hour based on the timezone, formatted as a string. If a dateime format code is define, it will output based on the format set.
_.replace(string, search, replacement)
Replaces a specified phrase with another specified phrase, e.g.:
_.split(string, separator)
Split a string into a list where each word is a list item, e.g.:
_.str2datetime(timestring, format)
Convert string to datetime, e.g.:
_.upper(string)
Convert string to uppercase, e.g.:
_.as_int(string)
Convert string to integer, e.g.:
_.as_float(string)
Convert string to float, e.g.:
_.as_str(string)
Convert specified value to string, e.g.:
_.round_num(number,precision)
Returns a floating point number that is a rounded version of the specified number, e.g.:
_.random_num(min,max)
Returns an integer number selected element from the specified range, e.g.:
_.random_choice(list)
Returns a randomly selected element from the specified sequence. The sequence can be a string, a range, a list, a tuple, or any other kind of sequence, e.g.:
_.match_pattern(string, pattern)
Search the regular expression pattern and return the first occurrence, .e.g.:
_.obj_keys(dictionary)
Takes a dictionary as input and returns a list containing all the keys from the input dictionary, e.g.:
_.obj_values(dictionary)
Takes a dictionary as input and returns a list containing all the values from the input dictionary, e.g.:
_.get(dictionary, path)
Retrieves the value at a specified path within a nested dictionary or list, e.g.:
_.map_get(list[dict], path)
Maps the get function over a list of dictionaries. It retrieves the value at a specified path within each dictionary in the list, e.g.: