Built-in Functions Reference
The AI Task system provides a variety of built-in functions for common operations in AI workflows. This document serves as a reference for these functions, explaining their parameters and usage.
File Operations
convert_to_docx
Converts a TXT file to DOCX format with specific formatting for transcripts.
Parameters: - source: Path to input TXT file (required) - result: Path to output DOCX file (required)
Example:
- name: convert_to_docx
type: function
function: convert_to_docx
params:
source: "profile/profile_{{id}}/transcription/INQUA2_{{id}}_transcription_01.txt"
result: "profile/profile_{{id}}/transcription/INQUA2_{{id}}_transcription_01.docx"
aisource
Loads content from a file into the pipeline.
Parameters: - file: Path to the file to load (required) - dir: Base directory (defaults to current working directory) - content: Optional content to use instead of reading from the file
Example:
- name: load_audio
type: function
function: aisource
params:
file: "profile/profile_{{id}}/audio/document_{{id}}.m4a"
airesult
Saves pipeline content to a file.
Parameters: - file: Path where the content should be saved (required) - dir: Base directory (defaults to current working directory)
Example:
- name: save_transcript
type: function
function: airesult
params:
file: "profile/profile_{{id}}/transcription/INQUA2_{{id}}_transcription_01.txt"
Content Processing
content
Extracts or processes text content from the pipeline.
Parameters: - format: Format type (defaults to “text”) - extract: Optional regex pattern to extract specific content
Example:
- name: extract_json
type: function
function: content
params:
extract: "```json\\n(.*?)\\n```"
Custom Function Registration
You can register custom functions to extend the system’s capabilities:
from ai_task.funcs import register
def my_custom_function(pipe_data, params):
# Process data
result = some_processing(pipe_data.get("pipein_text", ""), params)
# Return updated pipe_data
pipe_data["pipeout_text"] = result
return pipe_data
# Register the function
register("my_custom_function", my_custom_function)
Once registered, the custom function can be used in partitur files:
- name: process_data
type: function
function: my_custom_function
params:
param1: "value1"
param2: "value2"
Function Placement
Custom functions can be placed in the following locations:
- Project-level:
function/ directory in your project root
- Profile-specific:
profile/profile_{{id}}/function/ for profile-specific functions
Example project structure:
project/
├── function/ # Project-level functions
│ ├── __init__.py
│ ├── custom_docx.py
│ └── custom_audio.py
├── profile/
│ ├── profile_001/
│ │ ├── function/ # Profile-specific functions
│ │ │ ├── __init__.py
│ │ │ └── custom_format.py
The system searches for functions in the following order: 1. Built-in functions in the AI Task package 2. Project-level functions in function/ 3. Profile-specific functions in profile/profile_{{id}}/function/
This allows profile-specific functions to override project-level functions, and project-level functions to override built-in functions, providing a flexible customization system.