aiTransform

Create an AI Transform Runnable that applies transformation functions to data in AI pipelines. Supports custom closures, built-in transformers, and chainable operations for data processing.

Syntax

aiTransform(transformer, config)

Parameters

Parameter
Type
Required
Default
Description

transformer

any

Yes

-

The transformation function (closure), internal transformer name, or full classpath to transformer

config

struct

No

{}

Optional configuration struct for the transformer

Transformer Types

Custom Closure:

aiTransform( data => data.uCase() )

Built-in Transformers:

  • "code" or "codeExtractor" - Extract code blocks from AI responses

  • "json" or "jsonExtractor" - Extract and parse JSON from responses

  • "text" or "textExtractor" - Extract plain text content

  • "xml" or "xmlExtractor" - Extract and parse XML from responses

Custom Class:

Returns

Returns an AiTransformRunnable object implementing IAiRunnable with:

  • Pipeline integration: run(), stream(), to() methods

  • Chainable: Can be chained with other runnables

  • Flexible: Supports any transformation logic

Examples

Basic Transformation

In Pipeline

Extract Content

Multiple Transforms

Code Extractor

JSON Extractor

Text Extractor

XML Extractor

Custom Logic

Error Handling

Data Mapping

Filter and Process

Streaming Transform

Conditional Transform

Aggregate Transform

Validation Transform

Caching Transform

Pipeline Factory

Response Enrichment

Built-in with Config

Notes

  • 🔗 IAiRunnable: Implements full runnable interface for pipelines

  • 🎨 Flexible: Supports closures, built-ins, and custom classes

  • 🔄 Chainable: Compose multiple transforms in sequence

  • 🚀 Performance: Transformations are efficient and lightweight

  • 📦 Reusable: Create once, use in multiple pipelines

  • 🎯 Type Safe: Validate inputs and outputs as needed

  • 💡 Built-ins: Code, JSON, text, and XML extractors included

Best Practices

Chain transforms - Break complex transformations into simple steps

Use built-ins - Leverage code/json/text extractors when appropriate

Handle errors - Wrap risky transformations in try/catch

Keep transforms pure - Avoid side effects in transformation functions

Reuse transforms - Create transform once, use in multiple pipelines

Stream-friendly - Design transforms to work with both run() and stream()

Don't make heavy transforms - Keep transformations lightweight and fast

Don't mutate input - Return new data, don't modify input

Don't ignore errors - Handle transformation failures gracefully

Last updated