Class: LlmConductor::DataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_conductor/data_builder.rb

Overview

Base class for building structured data from source objects for LLM consumption. Provides helper methods for data extraction, formatting, and safe handling of nested data.

Examples:

Basic usage

class CompanyDataBuilder < LlmConductor::DataBuilder
  def build
    {
      id: source_object.id,
      name: source_object.name,
      metrics: build_metrics
    }
  end

  private

  def build_metrics
    {
      employees: safe_extract(:employee_count, default: 'Unknown')
    }
  end
end

builder = CompanyDataBuilder.new(company)
data = builder.build

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_object) ⇒ DataBuilder

Returns a new instance of DataBuilder.



31
32
33
# File 'lib/llm_conductor/data_builder.rb', line 31

def initialize(source_object)
  @source_object = source_object
end

Instance Attribute Details

#source_objectObject (readonly)

Returns the value of attribute source_object.



29
30
31
# File 'lib/llm_conductor/data_builder.rb', line 29

def source_object
  @source_object
end

Instance Method Details

#buildHash

Abstract method to be implemented by subclasses

Returns:

  • (Hash)

    The built data structure

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/llm_conductor/data_builder.rb', line 37

def build
  raise NotImplementedError, "#{self.class} must implement the #build method"
end