LettreAI Documentation
  • Home
  • User Guide
  • Nutshell
  • Manual
  • Examples
  • API
  1. Examples
  2. Production Examples
  • 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
  1. Examples
  2. Production Examples

Production Examples

Production Examples

This section provides practical examples of using productions in AI Task.

Basic Production Setup

Example: Customer Profile Analysis

This example demonstrates how to set up a production for analyzing customer profiles:

# profile_analysis.ai
name: "Customer Profile Analysis"
description: "Analyzes customer profiles to extract key insights"

production:
  name: "profiles"
  home: "./productions"
  id_format: "{name}_{id:05d}"

pipe:
  - type: llm
    name: "profile_analysis"
    tmpl: |
      Analyze the following customer profile and extract key information:
      
      {{pipe.pipein-text}}
      
      Please provide:
      1. Customer demographics (age, location, etc.)
      2. Key interests and preferences
      3. Potential product recommendations
      4. Customer segment category
    model: gemini-2.0-flash
    output_file: "{{production.instance_dir}}/analysis.txt"
    
  - type: llm
    name: "summary"
    tmpl: |
      Based on this analysis:
      
      {{pipe.pipeout-text}}
      
      Create a concise executive summary in bullet points.
    model: gemini-2.0-flash
    output_file: "{{production.instance_dir}}/summary.txt"

Running the Production

To process a customer profile:

# Create a new instance and process a profile
aitask profile_analysis.ai --production-new "Customer profile text..." 

# Process another profile in a new instance
aitask profile_analysis.ai --production-new "Another customer profile..."

# List all processed profiles
aitask --production-list profiles

Advanced Production Example

Multi-Stage Document Processing

This example shows a more complex production with multiple processing stages:

# document_processing.ai
name: "Document Processing Pipeline"
description: "Multi-stage document processing workflow"

production:
  name: "documents"
  home: "./productions"
  id_format: "doc_{id:05d}"
  
pipe:
  - type: function
    name: "extract_text"
    func: extract_text_from_file
    args:
      input_file: "{{pipe.pipein-text}}"
    output_file: "{{production.instance_dir}}/extracted_text.txt"
    
  - type: llm
    name: "analyze"
    tmpl_file: document_analysis.j2
    vars:
      doc_type: "report"
    model: gemini-2.0-flash
    output_file: "{{production.instance_dir}}/analysis.json"
    
  - type: function
    name: "generate_report"
    func: create_pdf_report
    args:
      analysis_file: "{{production.instance_dir}}/analysis.json"
      template: "report_template.html"
    output_file: "{{production.instance_dir}}/final_report.pdf"

Production with Batch Processing

This example demonstrates how to process multiple items in batch:

# batch_reviews.ai
name: "Batch Review Analysis"
description: "Process multiple reviews in batch"

production:
  name: "reviews"
  home: "./productions"
  id_format: "review_{id:05d}"
  
pipe:
  - type: function
    name: "load_reviews"
    func: load_reviews_from_csv
    args:
      csv_file: "{{pipe.pipein-text}}"
    
  - type: llm
    name: "analyze_reviews"
    tmpl: |
      Analyze the following product review:
      
      {{item}}
      
      Provide:
      1. Sentiment (positive, negative, neutral)
      2. Key points mentioned
      3. Product aspects discussed
      4. Suggested improvements
    model: gemini-2.0-flash
    batch: true
    batch_var: "item"
    batch_source: "pipe.pipeout-items"
    output_file: "{{production.instance_dir}}/review_{{batch_index}}.json"
    
  - type: function
    name: "aggregate_results"
    func: aggregate_review_analyses
    args:
      review_dir: "{{production.instance_dir}}"
    output_file: "{{production.instance_dir}}/aggregate_report.json"

Managing Production Data

Accessing Production Metadata

This example shows how to access and use production metadata:

# metadata_example.ai
name: "Production Metadata Example"
description: "Demonstrates accessing production metadata"

production:
  name: "reports"
  home: "./productions"
  id_format: "report_{id:05d}"
  
pipe:
  - type: function
    name: "load_metadata"
    func: load_production_metadata
    args:
      production_name: "reports"
    
  - type: llm
    name: "generate_overview"
    tmpl: |
      Based on the following production metadata:
      
      {{pipe.pipeout-text}}
      
      Generate a summary report of all processed instances.
      Include:
      1. Total number of instances
      2. Processing dates range
      3. Success/failure statistics
      4. Average processing time
    model: gemini-2.0-flash
    output_file: "{{production.instance_dir}}/overview.txt"

Best Practices for Productions

  1. Consistent naming: Use clear, consistent naming for productions and their outputs
  2. Proper organization: Keep related productions in logical groups
  3. Metadata management: Store relevant metadata for each instance
  4. Error handling: Implement proper error handling and logging
  5. Cleanup policies: Define policies for archiving or removing old production data
Instruction Examples
AI Task Reports

LettreAI Documentation

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