UDF APIs
Explicit Registration Syntax for UDFs
Explicit registration refers to the manual embedding of registration logic directly into Python code, typically achieved through methods like backend.register or register_from_file, where calling these methods triggers the registration process. This method relies on having access to a backend session object before proceeding.
Scenarios recommending explicit registration: If you wish to explicitly control registration timing, allow intrusive addition of registration logic, or require separation of UDF registration and usage under the same backend connection.
A common scenario involves one team handling UDF registration while multiple teams utilize these functions, with no shared Python scripts between them.
| UDF Type | UDF Type (Secondary) | Registration Type (Tertiary) | Code Entry | Reference |
|---|---|---|---|---|
| UDF, UDAF, UDTF | Python | Direct registration | backend.[udf | udaf | udtf].python.register(<Registration function>, <Registration parameters>) | |
| File-based registration | backend.[udf | udaf | udtf].python.register_from_file(<File path>, <Function name>, <Registration parameters>) | |||
| Builtin | Direct registration | backend.[udf | udaf | udtf].builtin.register(<Registration function>, <Registration parameters>) | ||
| File-based registration | backend.[udf | udaf | udtf].builtin.register_from_file(<File path>, <Function name>, <Registration parameters>) | |||
| PyArrow | Direct registration | backend.udf.pyarrow.register(<Registration function>, <Registration parameters>) | ||
| File-based registration | backend.udf.pyarrow.register_from_file(<File path>, <Function name>, <Registration parameters>) | |||
| Pandas | Direct registration | backend.udf.pandas.register(<Registration function>, <Registration parameters>) | ||
| File-based registration | backend.udf.pandas.register_from_file(<File path>, <Function name>, <Registration parameters>) |
Implicit Registration Syntax for UDFs
Implicit registration simplifies this process by using the Python runtime to automatically detect and register UDFs. Instead of embedding registration logic directly into the code, you can decorate your Python functions with @ decorators. Once decorated, these functions can be referenced in DataFrames using their original identifiers, seamlessly completing the registration. With implicit registration, there is no need to obtain a backend session object when applying the @ decorator. The backend session is only required later when working with Ibis DataFrames.
This approach is particularly useful when you aim to register UDFs without intrusive modifications to your code and do not require separation between the registration and usage of UDFs under the same Backend connection.
A common use case involves scenarios where your Python script includes both the registration and application of UDFs in a single workflow.
| UDF Type | UDF Type (Secondary) | Code Entry | Reference |
|---|---|---|---|
| UDF, UDAF, UDTF | Python | @aura.[udf | udaf | udtf].python(<Registration parameters>) | |
| Builtin | @aura.[udf | udaf | udtf].builtin(<Registration parameters>) | ||
| PyArrow | @aura.udf.pyarrow(<Registration parameters>) | ||
| Pandas | @aura.udf.pandas(<Registration parameters>) |
For implicit registration, the timing of the actual registration action differs depending on the DataFrame operation mode (Lazy or Eager).
As mentioned earlier in the Ibis official documentation, DataFrame operations are divided into Eager and Lazy modes, controlled by the ibis.options.interactive configuration item. By default, this is set to false, meaning all DataFrames operate in Lazy mode by default. For these two DataFrame execution modes, the timing of UDF registration varies as described below:
| ibis.options.interactive | DataFrame Execution Mode | UDF Registration Time | UDF Usage Time |
|---|---|---|---|
| False | Lazy | When the entire DataFrame calls the execute method | When the entire DataFrame calls the execute method |
| True | Eager | First use in DataFrame | Every use in DataFrame |
Python/PyArrow/Pandas UDF Registration Parameters
Registering a Python/PyArrow/Pandas UDF involves registering an original Python function or class into the database.
Whether it is explicit or implicit registration, whether it is scalar UDF, UDAF, or UDTF, for registering Python, PyArrow, or Pandas type UDFs, you can currently pass in the following parameters:
| Registration Parameter | Description | Type | Default Value |
|---|---|---|---|
| name | Specifies the actual storage name of the UDF in the database. | str | None | None |
| database | Specifies the LakeFormation database where the UDF resides. | str | None | None |
| fn | Specifies the original Python function of the UDF. | Callable | None |
| signature | Specifies the UDF function signature and return value type. | aura_frame.ibis.common.annotations.Signature | None | None |
| replace (currently unavailable) | Specifies whether the UDF can be replaced. | bool | False |
| temporary (currently unavailable) | Specifies whether the UDF has a session-level lifecycle. | bool | False |
| if_not_exist (currently unavailable) | Specifies whether to skip errors for existing UDFs. | bool | False |
| strict | Specifies whether the UDF automatically filters NULL values. | bool | True |
| volatility | Specifies the stability of the UDF. | VolatilityType.VOLATILE | VolatilityType.STABLE | VolatilityType.IMMUTABLE | VolatilityType.VOLATILE |
| runtime_version (currently unavailable) | Specifies the Python version for executing the UDF. | str | sys.version_info |
| runtime_env | Specifies the Python module on which the UDF depends and the installation mode (venv), which will be used to replace packages. | Union[str, Mapping[str, Any]] | None | None |
| imports | Specifies the external code files on which the UDF depends. | List[str] | None |
| packages | Specifies the Python modules on which the UDF depends. | List[Union[str, module]] | None | None |
| register_type | Specifies the registration form of the UDF. | RegisterType.INLINE | RegisterType.STAGED | RegisterType.INLINE |
| comment | Specifies user comments for the UDF. | str | None | None |
Python/PyArrow/Pandas UDF Registration Parameter Notes
- For the imports parameter, only file paths in the same directory or subdirectories as the .py file containing the current Python function or class are allowed.
- For the fn parameter, if fn is not in the .py file where the UDF is being registered, then the file path defining fn must also be added to the imports parameter, for example:
from process import outer from aura_frame.multimodal import ai_lake con = ai_lake.connect( aura_endpoint=os.getenv("aura_endpoint"), aura_endpoint_name=os.getenv("aura_endpoint_name"), aura_workspace_id=os.getenv("aura_workspace_id"), lf_catalog_name=os.getenv("lf_catalog_name"), access_key=os.getenv("access_key"), secret_key=os.getenv("secret_key"), default_database=target_database, use_single_cn_mode=True ) # Register a UDAF. udf = con.udaf.python.register( outer(), #fn introduced externally imports=["process.py"] #Add the file path for fn ) - The signature parameter is currently optional for you to provide. If you specify it, your input takes precedence over automatic inference. When no signature is provided, the system defaults to inferring the parameter and return value types automatically. For more details, refer to Type Inference of the signature Parameter.
- When registering a PyArrow UDF, whether you provide a signature parameter, it always relies on PyArrowVector. For example:
import aura_frame as aura import pyarrow as pa import pyarrow.compute as pc from aura_frame.multimodal import ai_lake # === With signature: Requires dependency on PyArrowVector. === def calculate_sum( prices: pa.ChunkedArray, quantities: pa.ChunkedArray, ) -> pa.ChunkedArray: return pc.multiply(prices, quantities) con = ai_lake.connect( aura_endpoint=os.getenv("aura_endpoint"), aura_endpoint_name=os.getenv("aura_endpoint_name"), aura_workspace_id=os.getenv("aura_workspace_id"), lf_catalog_name=os.getenv("lf_catalog_name"), access_key=os.getenv("access_key"), secret_key=os.getenv("secret_key"), default_database=target_database, use_single_cn_mode=True ) # Register a UDF. con.create_scalar_function( calculate_sum, database=target_database ) # === Without signature: Also requires dependency on PyArrowVector. === def calculate_sum( prices: aura.PyarrowVector[float], quantities: aura.PyarrowVector[int], ) -> aura.PyarrowVector[float]: return aura.PyarrowVector[float](pc.multiply(prices, quantities)) con = ai_lake.connect( aura_endpoint=os.getenv("aura_endpoint"), aura_endpoint_name=os.getenv("aura_endpoint_name"), aura_workspace_id=os.getenv("aura_workspace_id"), lf_catalog_name=os.getenv("lf_catalog_name"), access_key=os.getenv("access_key"), secret_key=os.getenv("secret_key"), default_database=target_database, use_single_cn_mode=True ) # Register a UDF. con.create_scalar_function( calculate_sum, database=target_database ) - When registering a Pandas UDF, whether you provide a signature parameter, it always relies on PandasVector. For example:
import aura_frame as aura import pandas as pd from aura_frame.multimodal import ai_lake # === With signature: Requires dependency on PandasVector. === def calculate_sum( prices: pd.Series, quantities: pd.Series, ) -> pd.Series: return pd.Series(prices * quantities, dtype=pd.Float64Dtype()) con = ai_lake.connect( aura_endpoint=os.getenv("aura_endpoint"), aura_endpoint_name=os.getenv("aura_endpoint_name"), aura_workspace_id=os.getenv("aura_workspace_id"), lf_catalog_name=os.getenv("lf_catalog_name"), access_key=os.getenv("access_key"), secret_key=os.getenv("secret_key"), default_database=target_database, use_single_cn_mode=True ) # Register a UDF. con.create_scalar_function( calculate_sum, database=target_database ) # === Without signature: Also requires dependency on PandasVector. === def calculate_sum( prices: aura.PandasVector[float], quantities: aura.PandasVector[int], ) -> aura.PandasVector[float]: return aura.PandasVector[float](prices * quantities) con = ai_lake.connect( aura_endpoint=os.getenv("aura_endpoint"), aura_endpoint_name=os.getenv("aura_endpoint_name"), aura_workspace_id=os.getenv("aura_workspace_id"), lf_catalog_name=os.getenv("lf_catalog_name"), access_key=os.getenv("access_key"), secret_key=os.getenv("secret_key"), default_database=target_database, use_single_cn_mode=True ) # Register a UDF. con.create_scalar_function( calculate_sum, database=target_database )
- When registering a PyArrow UDF, whether you provide a signature parameter, it always relies on PyArrowVector. For example:
- For the volatility parameter, the meanings of the three enumeration types are:
- VolatilityType.VOLATILE: Function results may change at any time.
- VolatilityType.STABLE: Function results remain unchanged for a fixed input during a single scan.
- VolatilityType.IMMUTABLE: The function always produces the same result for identical inputs.
The volatility parameter does not impact the execution of function pushdown. Python UDFs can be pushed down to DNs regardless of whether they are classified as IMMUTABLE, STABLE, or VOLATILE.
- If you do not specify the packages parameter:
- For PyArrow UDFs, the PyArrow version installed in the backend environment is automatically used.
- For Pandas UDFs, the Pandas version installed in the backend environment is automatically used.
To ensure that third-party dependencies for Python are installed in an isolated environment, the packages specified in the packages parameter are passed to RuntimeEnv for installation. The default installation mode is venv.
Builtin UDF Registration Parameters
For Builtin UDFs, registering them simply means obtaining a handle for existing database functions—no actual registration occurs.
Whether it is explicit or implicit registration, whether it is scalar UDF, UDAF, or UDTF, for registering Builtin type UDFs, you can currently pass in the following parameters:
| Registration Parameter | Description | Type | Default Value |
|---|---|---|---|
| name | Specifies the actual storage name of the UDF in the database. | str | None | None |
| database | Specifies the LakeFormation database where the UDF resides. | str | None | None |
| fn | Specifies the original Python function of the UDF. | Callable | None |
| signature | Specifies the UDF function signature and return value type. | ibis.common.annotations.Signature | None | None |
Builtin UDF Registration Parameter Notes
The signature parameter is currently optional for you to provide. If you specify it, your input takes precedence over automatic inference. When no signature is provided, the system defaults to inferring the parameter and return value types automatically. For more details, refer to Type Inference of the signature Parameter.
Type Inference of the signature Parameter
For the signature parameter, you may choose to provide the parameter/return value types or omit them entirely.
- If you supply the signature parameter, there is no requirement for the original Python function to utilize type hinting syntax. This enables immediate operational registration of the UDF.
- Conversely, if the signature parameter is not provided, you are advised to use type hinting syntax within the original Python function, though this precludes immediate operational registration of the UDF.
A comparison of these approaches is summarized below.
| signature Parameter | Description | Require Original Python Function with Type Hint Syntax | Support Immediate REPL Operation |
|---|---|---|---|
| User omits passing value | Auto-deduction (recommended) | No, but recommended | No |
| User specifies value | Specified value | No | Yes |
Note: Immediate operation pertains to the read-evaluate-print loop (REPL), commonly encountered in Python's interactive terminal environment.
Introduced in Python 3.5 via PEP 484, type hinting syntax involves appending a colon (:) followed by the type after the parameter name and indicating the return type post the parameter list using an arrow (->), exemplified as follows:
def greet(name: str) -> str:
return f"Hello, {name}"
from typing import List, Dict, Optional
def process_data(data: List[int]) -> Dict[str, Optional[int]]:
return {"max": max(data) if data else None} For Python/PyArrow/Pandas UDFs, strict typing is mandated upon registration, requiring explicit specification of all parameter and return value types. If you fail to define these through the original Python function's type hinting, you must actively use the signature parameter to designate the Ibis DataType.
For Builtin UDFs, strict typing is not required upon registration (as the UDF has already been registered in the database). If you cannot specify the type annotations of the original Python function, you are advised to include only the parameter names without their types. If you later use the return value of the Builtin UDF (excluding Top SELECT UDF), then the function's return type needs to be specified, and when necessary, you should actively use the signature parameter to define the Ibis DataType. If not needed (for Top SELECT UDF), you may omit writing the function's return type.
Regarding cases where you do not provide the signature parameter and rely on auto-deduction, the following summary applies:
| Registered UDF Type | Data Type | Return Type |
|---|---|---|
| Python/Pyarrow/Pandas UDF | Requires type hinting syntax for specification. | Requires type hinting syntax for specification. |
| Builtin UDF | Allows writing just parameter names without types. | Requires type hinting syntax when utilizing return values subsequently. Otherwise, not mandatory. |
For cases where you do not pass in the signature parameter and it is inferred automatically, the underlying implementation principle is inspect.signature. Currently, the system accepts the following parameter/return value types from you:
| Python | Ibis DataType | Aura |
|---|---|---|
| DataType | DataType | - |
| type(None) | null | NULL |
| bool | Boolean | BOOLEAN |
| bytes | Binary | BYTEA |
| str | String | TEXT |
| numbers.Integral | Int64 | BIGINT |
| numbers.Real | Float64 | DOUBLE PRECISION |
| decimal.Decimal | Decimal | DECIMAL |
| datetime.datetime | Timestamp | TIMESTAMP/TIMESTAMPTZ |
| datetime.date | Date | TIMESTAMP |
| datetime.time | Time | TIME |
| datetime.timedelta | Interval | INTERVAL |
| uuid.UUID | UUID | UUID |
| class | Struct | STRUCT |
| typing.Sequence, typing.Array | Array | ARRAY |
| typing.Mapping, typing.Map | Map | HSTORE |
| aura_frame.PyarrowVector[T] | T | T |
| aura_frame.PandasVector[T] | T | T |
Notes:
- Python built-in int is a subclass of numbers.Integral.
- Python built-in float is a subclass of numbers.Real.
Python types not listed in the table above are currently not supported for automatic conversion.
For parameters/return values where you do not pass the signature parameter and also do not use Python type hinting syntax, automatic inference handles them as follows:
| Parameter Type | Generated Matching Pattern | Pattern Effectiveness |
|---|---|---|
| POSITIONAL_ONLY, KEYWORD_ONLY, POSITIONAL_OR_KEYWORD | ValueOf(None) | Exempts from __signature__.validate. |
| VAR_POSITIONAL | TupleOf(pattern=pattern) | Executes pattern in a for-loop. |
| VAR_KEYWORD | DictOf(key_pattern=InstanceOf(str), value_pattern=pattern) | Executes pattern in a for-loop. |
| Return | ValueOf(Unknown) | Provides UnknownScalar and UnknownColumn as UDF return values passed upward. |
inspect.signature classifies parameter types (Parameter.kind) as follows:
| Parameter Type | Description | Sample Code | Parameters Meeting Conditions |
|---|---|---|---|
| POSITIONAL_ONLY | Position-only parameter. | def func(a, /, b): pass | a |
| KEYWORD_ONLY | Keyword-only parameter. | def func(a, *, b): pass | b |
| POSITIONAL_OR_KEYWORD | Positional or keyword parameter. | def func(a, b): pass | a, b |
| VAR_POSITIONAL | Variable positional parameter. | def func(*args): pass | args |
| VAR_KEYWORD | Variable keyword parameter. | def func(**kwargs): pass | kwargs |
Direct Operation Syntax for UDFs
In scenarios where registration and usage are separate, the direct operation syntax for scalar UDFs, UDAFs, and UDTFs is provided for you. You only need to know the UDF name (name) and the database name (database) where the UDF resides to directly use the UDF. The following operations rely on the UDF attribute of the backend session object.
signature
Description: Returns the function signature and return value type of the UDF from the backend database.
Syntax:
signature(name, database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| name | Yes | str | The UDF name. |
| database | No | str | Name of the database to which the UDF belongs. |
Return type: aura_frame.ibis.common.annotations.Signature - Registered UDF's signature and return type.
get
Description: Returns the UDF from the backend database.
Syntax:
get(name, database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| name | Yes | str | The UDF name. |
| database | No | str | Name of the database to which the UDF belongs. |
Return type: Callable[..., ibis.expr.types.Value] - Registered UDFs.
names
Description: Returns the names of all UDFs from the backend database.
Syntax:
names(database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| database | No | str | Name of the database to which the UDF belongs. |
Return type: List[str] - Names of all registered UDFs.
unregister
Description: Deletes a specified UDF from the backend database.
Syntax:
unregister(name, database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| name | Yes | str | The UDF name. |
| database | No | str | Name of the database to which the UDF belongs. |
Return type: None.
UDF WITH ARGUMENTS Syntax
Whether you use explicit registration syntax, implicit registration syntax to return a UDF operator, or direct operation syntax to access a registered UDF, all currently support passing arguments via the with_arguments method. These arguments fall into two categories:
- Special-purpose parameters: These parameters configure runtime resources, concurrency, and execution time limits for the UDF. Examples include concurrency, timeout, dpu, and apu. For details, see Table 1. All types of UDFs currently allow you to pass these configuration parameters using with_arguments.
- General parameters: These parameters initialize the state of the UDF during its setup phase. They can only be passed as scalar values if you have defined optional parameters in the __init__ method of class UDF, class UDTF, or UDAF. This allows for one-time initialization of internal states, which can then be reused multiple times.
| Parameter | Applicable UDF Type | Description |
|---|---|---|
| Special parameters (e.g., concurrency, timeout, dpu, apu) | All UDF types, including scalar UDF, class UDF, vectorized UDF, UDTF, UDAF | Configures runtime resources, concurrency, and execution time limits for the UDF. |
| General parameters defined by the Python class's __init__ method | Class UDF types, including class UDF, class UDTF, UDAF | Sets up initial state for the UDF, suitable for cases involving internal caching, initialization parameters, or model objects. |
All parameter values passed through the with_arguments method are scalar values. These values are collectively passed as a **kwargs dictionary in Python.
create_agg_function
Description: Registers a UDAF.
Syntax:
create_agg_function(udf, /, input_type=InputType.PYTHON, *, database, name=None, signature=None, imports=None, packages=None, runtime_env=None, comment=None, **kwargs)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| udf | Yes | Callable | UDAF to be registered. |
| input_type | No | InputType | Input type of the function. The value can be PYTHON, BUILTIN, PYARROW, or PANDAS. |
| database | Yes | str | Name of the database to which the function belongs. |
| name | No | str | Name of the function. The default value is None. |
| signature | No | Signature | (Optional) Signature definition of a function. |
| imports | No | [Union[str, Iterable[str]]] | Import modules required by the function, which can be a single string or a list of strings. |
| packages | No | [Union[str, Iterable[str]]] | Dependency packages required by the function, which can be a single package name or a list of package names. |
| runtime_env | No | [Union[str, Mapping[str, Any]]] | Dependency packages and installation methods required by the function, which can be a JSON string or a Python dictionary. |
| comment | No | str | (Optional) Comments of the function. |
| **kwargs | No | - | Other optional keyword arguments. |
Return type:
Callable: Registered function.
create_scalar_function
Description: Registers a new scalar UDF.
Syntax:
create_scalar_function(udf, /, input_type=InputType.PYTHON, *, database, name=None, imports=None, packages=None, runtime_env=None, comment=None, **kwargs)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| udf | Yes | Callable | Scalar UDF to be registered. |
| input_type | No | InputType | Input type of the function. The value can be PYTHON, BUILTIN, PYARROW, or PANDAS. |
| database | Yes | str | Name of the database to which the function belongs. |
| name | No | str | Name of the function. The default value is None. |
| imports | No | [Union[str, Iterable[str]]] | Import modules required by the function, which can be a single string or a list of strings. |
| packages | No | [Union[str, Iterable[str]]] | Dependency packages required by the function, which can be a single package name or a list of package names. |
| runtime_env | No | [Union[str, Mapping[str, Any]]] | Dependency packages and installation methods required by the function, which can be a JSON string or a Python dictionary. |
| comment | No | Optional[str] | (Optional) Comments of the function. |
| **kwargs | No | - | Other optional keyword arguments. |
Return type: Callable
create_table_function
Description: Registers a UDTF.
Syntax:
create_table_function(udf, /, input_type=InputType.PYTHON, *, database, name=None, signature=None, imports=None, packages=None, runtime_env=None, comment=None, **kwargs)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| udf | Yes | Callable | UDTF to be registered. |
| input_type | No | InputType | Input type of the function. The value can be PYTHON or BUILTIN. |
| database | Yes | str | Name of the database to which the function belongs. |
| name | No | str | Name of the function. The default value is None. |
| signature | No | Signature | (Optional) Signature definition of a function. |
| imports | No | [Union[str, Iterable[str]]] | Import modules required by the function, which can be a single string or a list of strings. |
| packages | No | [Union[str, Iterable[str]]] | Dependency packages required by the function, which can be a single package name or a list of package names. |
| runtime_env | No | [Union[str, Mapping[str, Any]]] | Dependency packages and installation methods required by the function, which can be a JSON string or a Python dictionary. |
| comment | No | str | (Optional) Comments of the function. |
| **kwargs | No | - | Other optional keyword arguments. |
Return type:
Callable: Registered function.
delete_function
Description: Deletes a UDF from a specified database.
Syntax:
delete_function(name, /, *, database=None, if_it_exists=False)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| name | Yes | str | Name of the function to be deleted. |
| database | No | str | Name of the database from which the function is to be deleted. If it is not specified, the default database is used. |
| if_it_exists | No | bool | If it is set to True, the deletion operation is performed only when the function exists. This prevents errors caused by the absence of the function. |
Return type: str
describe_function
Description: Describes the functions in a specified database.
Syntax:
describe_function(name, /, *, database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| name | Yes | str | The function name. |
| database | No | str | Name of the database where the function is located. |
Return type: str, metadata information about the function.
get_function
Description: Retrieves a UDF from a specified or default database.
Syntax:
get_function(name, *, database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| func_name | Yes | str | Name of the user-defined function to be retrieved. |
| database | No | Optional[str] | Name of the database from which to retrieve the function. If not specified, the default database is used. |
Return type: Callable. A callable function is returned.
list_functions
Description: Lists all UDFs in a specified or default database.
Syntax:
list_functions(database=None)
Input parameters:
| Parameter | Mandatory (Yes/No) | Parameter Type | Description |
|---|---|---|---|
| database | No | str | Name of the database from which to list the function. If not specified, the default database is used. |
Return type: pandas.DataFrame.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot