LettreAI Documentation
  • Home
  • User Guide
  • Nutshell
  • Manual
  • Examples
  • API
    • Getting Started
      • AI Task Documentation
      • Installation
      • Quick Start
    • User Guide
      • User Guide
    • Nutshell
      • AI-Task in a Nutshell
    • Manual
      • Core Concepts
      • Configuration
      • Instructions
      • Productions
      • Functions
      • LLM Integration - Claude
    • Examples
      • Basic Examples
      • Advanced Examples
      • Instruction Examples
      • Production Examples
    • Reports
      • AI Task Reports
    • API Reference
      • Pipeline API
      • Engine API
      • Functions API
    • Development
      • Contributing
      • Architecture

    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```"

    count_tags

    Counts occurrences of a specific tag in the content.

    Parameters: - tag: Tag name to count (required)

    Example:

    - name: count_speakers
      type: function
      function: count_tags
      params:
        tag: "speaker"

    Media Processing

    youtube_download

    Downloads a YouTube video and adds it to the production.

    Parameters: - url: YouTube URL (required) - production_id: Production ID to associate with the video (required) - production_dir: Base production directory (optional) - resolution: Desired video resolution (optional, default: “720p”)

    Example:

    - name: download_video
      type: function
      function: youtube_download
      params:
        url: "https://www.youtube.com/watch?v=example"
        production_id: "nepi_001"

    extract_slides

    Extracts slide images from a video based on timestamps in a slide detection file.

    Parameters: - slide_file: Path to file containing slide timestamps (required) - video_file: Path to video file (required if not in pipe_data) - output_dir: Directory to save slide images (required) - format: Image format (optional, default: “jpg”)

    Example:

    - name: extract_slide_images
      type: function
      function: extract_slides
      params:
        slide_file: "profile/profile_{{id}}/slide/INQUA2_{{id}}_slide_01.txt"
        video_file: "profile/profile_{{id}}/video/document_{{id}}.mp4"
        output_dir: "profile/profile_{{id}}/slide/images"
        format: "jpg"

    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:

    1. Project-level: function/ directory in your project root
    2. 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.

    LettreAI Documentation

     
    • Edit this page
    • Report an issue
    • License: MIT