Class: Legion::LLM::Pipeline::Response

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/llm/pipeline/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent

Returns:

  • (Object)

    the current value of agent



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def agent
  @agent
end

#auditObject (readonly)

Returns the value of attribute audit

Returns:

  • (Object)

    the current value of audit



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def audit
  @audit
end

#billingObject (readonly)

Returns the value of attribute billing

Returns:

  • (Object)

    the current value of billing



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def billing
  @billing
end

#cacheObject (readonly)

Returns the value of attribute cache

Returns:

  • (Object)

    the current value of cache



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def cache
  @cache
end

#callerObject (readonly)

Returns the value of attribute caller

Returns:

  • (Object)

    the current value of caller



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def caller
  @caller
end

#classificationObject (readonly)

Returns the value of attribute classification

Returns:

  • (Object)

    the current value of classification



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def classification
  @classification
end

#conversation_idObject (readonly)

Returns the value of attribute conversation_id

Returns:

  • (Object)

    the current value of conversation_id



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def conversation_id
  @conversation_id
end

#costObject (readonly)

Returns the value of attribute cost

Returns:

  • (Object)

    the current value of cost



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def cost
  @cost
end

#deprecationObject (readonly)

Returns the value of attribute deprecation

Returns:

  • (Object)

    the current value of deprecation



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def deprecation
  @deprecation
end

#enrichmentsObject (readonly)

Returns the value of attribute enrichments

Returns:

  • (Object)

    the current value of enrichments



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def enrichments
  @enrichments
end

#featuresObject (readonly)

Returns the value of attribute features

Returns:

  • (Object)

    the current value of features



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def features
  @features
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def message
  @message
end

#participantsObject (readonly)

Returns the value of attribute participants

Returns:

  • (Object)

    the current value of participants



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def participants
  @participants
end

#predictionsObject (readonly)

Returns the value of attribute predictions

Returns:

  • (Object)

    the current value of predictions



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def predictions
  @predictions
end

#qualityObject (readonly)

Returns the value of attribute quality

Returns:

  • (Object)

    the current value of quality



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def quality
  @quality
end

#rate_limitObject (readonly)

Returns the value of attribute rate_limit

Returns:

  • (Object)

    the current value of rate_limit



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def rate_limit
  @rate_limit
end

#request_idObject (readonly)

Returns the value of attribute request_id

Returns:

  • (Object)

    the current value of request_id



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def request_id
  @request_id
end

#retryObject (readonly)

Returns the value of attribute retry

Returns:

  • (Object)

    the current value of retry



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def retry
  @retry
end

#routingObject (readonly)

Returns the value of attribute routing

Returns:

  • (Object)

    the current value of routing



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def routing
  @routing
end

#safetyObject (readonly)

Returns the value of attribute safety

Returns:

  • (Object)

    the current value of safety



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def safety
  @safety
end

#schema_versionObject (readonly)

Returns the value of attribute schema_version

Returns:

  • (Object)

    the current value of schema_version



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def schema_version
  @schema_version
end

#stopObject (readonly)

Returns the value of attribute stop

Returns:

  • (Object)

    the current value of stop



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def stop
  @stop
end

#streamObject (readonly)

Returns the value of attribute stream

Returns:

  • (Object)

    the current value of stream



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def stream
  @stream
end

#testObject (readonly)

Returns the value of attribute test

Returns:

  • (Object)

    the current value of test



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def test
  @test
end

#thinkingObject (readonly)

Returns the value of attribute thinking

Returns:

  • (Object)

    the current value of thinking



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def thinking
  @thinking
end

#timelineObject (readonly)

Returns the value of attribute timeline

Returns:

  • (Object)

    the current value of timeline



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def timeline
  @timeline
end

#timestampsObject (readonly)

Returns the value of attribute timestamps

Returns:

  • (Object)

    the current value of timestamps



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def timestamps
  @timestamps
end

#tokensObject (readonly)

Returns the value of attribute tokens

Returns:

  • (Object)

    the current value of tokens



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def tokens
  @tokens
end

#toolsObject (readonly)

Returns the value of attribute tools

Returns:

  • (Object)

    the current value of tools



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def tools
  @tools
end

#tracingObject (readonly)

Returns the value of attribute tracing

Returns:

  • (Object)

    the current value of tracing



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def tracing
  @tracing
end

#validationObject (readonly)

Returns the value of attribute validation

Returns:

  • (Object)

    the current value of validation



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def validation
  @validation
end

#warningsObject (readonly)

Returns the value of attribute warnings

Returns:

  • (Object)

    the current value of warnings



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def warnings
  @warnings
end

#wireObject (readonly)

Returns the value of attribute wire

Returns:

  • (Object)

    the current value of wire



6
7
8
# File 'lib/legion/llm/pipeline/response.rb', line 6

def wire
  @wire
end

Class Method Details

.build(**kwargs) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/legion/llm/pipeline/response.rb', line 15

def self.build(**kwargs)
  new(
    id:              kwargs.fetch(:id) { "resp_#{SecureRandom.hex(12)}" },
    request_id:      kwargs.fetch(:request_id),
    conversation_id: kwargs.fetch(:conversation_id),
    schema_version:  kwargs.fetch(:schema_version, '1.0.0'),
    message:         kwargs.fetch(:message),
    routing:         kwargs.fetch(:routing, {}),
    tokens:          kwargs.fetch(:tokens, {}),
    thinking:        kwargs[:thinking],
    stop:            kwargs.fetch(:stop, {}),
    tools:           kwargs.fetch(:tools, []),
    stream:          kwargs.fetch(:stream, false),
    cache:           kwargs.fetch(:cache, {}),
    retry:           kwargs[:retry],
    timestamps:      kwargs.fetch(:timestamps, {}),
    cost:            kwargs.fetch(:cost, {}),
    quality:         kwargs[:quality],
    validation:      kwargs[:validation],
    safety:          kwargs[:safety],
    rate_limit:      kwargs[:rate_limit],
    features:        kwargs[:features],
    deprecation:     kwargs[:deprecation],
    enrichments:     kwargs.fetch(:enrichments, {}),
    predictions:     kwargs.fetch(:predictions, {}),
    audit:           kwargs.fetch(:audit, {}),
    timeline:        kwargs.fetch(:timeline, []),
    participants:    kwargs.fetch(:participants, []),
    warnings:        kwargs.fetch(:warnings, []),
    wire:            kwargs[:wire],
    tracing:         kwargs[:tracing],
    caller:          kwargs[:caller],
    classification:  kwargs[:classification],
    agent:           kwargs[:agent],
    billing:         kwargs[:billing],
    test:            kwargs[:test]
  )
end

.from_ruby_llm(msg, request_id:, conversation_id:, provider: nil, model: nil, **extra) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/legion/llm/pipeline/response.rb', line 54

def self.from_ruby_llm(msg, request_id:, conversation_id:, provider: nil, model: nil, **extra)
  input  = msg.respond_to?(:input_tokens) ? msg.input_tokens.to_i : 0
  output = msg.respond_to?(:output_tokens) ? msg.output_tokens.to_i : 0

  stop_reason = if msg.respond_to?(:stop_reason)
                  msg.stop_reason&.to_sym || :end_turn
                elsif msg.respond_to?(:tool_calls) && msg.tool_calls&.any?
                  :tool_use
                else
                  :end_turn
                end

  build(
    request_id:      request_id,
    conversation_id: conversation_id,
    message:         { role: :assistant, content: msg.content },
    routing:         { provider: provider, model: model || (msg.respond_to?(:model_id) ? msg.model_id : nil) },
    tokens:          { input: input, output: output, total: input + output },
    stop:            { reason: stop_reason },
    **extra
  )
end

Instance Method Details

#with(**updates) ⇒ Object



77
78
79
# File 'lib/legion/llm/pipeline/response.rb', line 77

def with(**updates)
  self.class.build(**to_h, **updates)
end