Tensorlake functions are the building blocks of workflows. They are Python functions decorated with the @tensorlake_function
decorator.
from tensorlake import tensorlake_function
image = Image()
.run("pip install transformers")
.build()
@tensorlake_function(image=image, input_encoding="json")
def my_function(data: str) -> int:
return len(data)
You can write any Python code inside the function, and depend on any Python package. The functions are run inside a container
of an image built from the specification of the Image
object.
Dynamic Routing
Functions can route data to different nodes based on custom logic, enabling dynamic branching.
@tensorlake_function()
def handle_error(text: str):
# Logic to handle error messages
pass
@tensorlake_function()
def handle_normal(text: str):
# Logic to process normal text
pass
# The function routes data into the handle_error and handle_normal based on the
# logic of the function.
@tensorlake_router()
def analyze_text(text: str) -> List[Union[handle_error, handle_normal]]:
if 'error' in text.lower():
return [handle_error]
else:
return [handle_normal]