Module: Legion::LLM::Pipeline::GaiaCaller

Extended by:
Legion::Logging::Helper
Defined in:
lib/legion/llm/pipeline/gaia_caller.rb

Class Method Summary collapse

Class Method Details

.chat(message:, phase: 'unknown', tick_trace_id: nil, tick_span_id: nil, caller: nil, **kwargs) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/llm/pipeline/gaia_caller.rb', line 13

def chat(message:, phase: 'unknown', tick_trace_id: nil, tick_span_id: nil, caller: nil, **kwargs)
  log.info("[llm][gaia] chat phase=#{phase} model=#{kwargs[:model] || 'default'}")
  request = Request.build(
    messages: [{ role: :user, content: message }],
    system:   kwargs[:system],
    routing:  { provider: kwargs[:provider], model: kwargs[:model] }.compact,
    caller:   caller || gaia_caller(phase),
    tracing:  gaia_tracing(phase, tick_trace_id, tick_span_id)
  )
  Executor.new(request).call
end

.embed(text:) ⇒ Object



38
39
40
41
# File 'lib/legion/llm/pipeline/gaia_caller.rb', line 38

def embed(text:, **)
  log.info("[llm][gaia] embed text_chars=#{text.to_s.length}")
  LLM.embed(text, **)
end

.gaia_caller(phase) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/legion/llm/pipeline/gaia_caller.rb', line 43

def gaia_caller(phase)
  {
    requested_by: {
      identity:   "gaia:tick:#{phase}",
      type:       :system,
      credential: :internal,
      name:       "GAIA #{phase.to_s.tr('_', ' ').capitalize}"
    }
  }
end

.gaia_tracing(phase, trace_id, span_id) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/legion/llm/pipeline/gaia_caller.rb', line 54

def gaia_tracing(phase, trace_id, span_id)
  {
    trace_id:       trace_id || SecureRandom.hex(16),
    span_id:        SecureRandom.hex(8),
    parent_span_id: span_id,
    correlation_id: "gaia:tick:#{phase}"
  }
end

.structured(message:, schema:, phase: 'unknown', tick_trace_id: nil, tick_span_id: nil, caller: nil, **kwargs) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/legion/llm/pipeline/gaia_caller.rb', line 25

def structured(message:, schema:, phase: 'unknown', tick_trace_id: nil, tick_span_id: nil, caller: nil, **kwargs)
  log.info("[llm][gaia] structured phase=#{phase} model=#{kwargs[:model] || 'default'}")
  request = Request.build(
    messages:        [{ role: :user, content: message }],
    system:          kwargs[:system],
    routing:         { provider: kwargs[:provider], model: kwargs[:model] }.compact,
    response_format: { type: :json_schema, schema: schema },
    caller:          caller || gaia_caller(phase),
    tracing:         gaia_tracing(phase, tick_trace_id, tick_span_id)
  )
  Executor.new(request).call
end