Class: Legion::LLM::Types::Chunk

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/llm/types/chunk.rb

Constant Summary collapse

CHUNK_TYPES =
%i[content_delta thinking_delta tool_call_delta
usage done error].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_block_indexObject (readonly)

Returns the value of attribute content_block_index

Returns:

  • (Object)

    the current value of content_block_index



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def content_block_index
  @content_block_index
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/types/chunk.rb', line 6

def conversation_id
  @conversation_id
end

#deltaObject (readonly)

Returns the value of attribute delta

Returns:

  • (Object)

    the current value of delta



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def delta
  @delta
end

#exchange_idObject (readonly)

Returns the value of attribute exchange_id

Returns:

  • (Object)

    the current value of exchange_id



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def exchange_id
  @exchange_id
end

#indexObject (readonly)

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def index
  @index
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/types/chunk.rb', line 6

def request_id
  @request_id
end

#stop_reasonObject (readonly)

Returns the value of attribute stop_reason

Returns:

  • (Object)

    the current value of stop_reason



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def stop_reason
  @stop_reason
end

#timestampObject (readonly)

Returns the value of attribute timestamp

Returns:

  • (Object)

    the current value of timestamp



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def timestamp
  @timestamp
end

#tool_callObject (readonly)

Returns the value of attribute tool_call

Returns:

  • (Object)

    the current value of tool_call



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def tool_call
  @tool_call
end

#tracingObject (readonly)

Returns the value of attribute tracing

Returns:

  • (Object)

    the current value of tracing



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def tracing
  @tracing
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def type
  @type
end

#usageObject (readonly)

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



6
7
8
# File 'lib/legion/llm/types/chunk.rb', line 6

def usage
  @usage
end

Class Method Details

.content_delta(delta:, request_id:, conversation_id: nil, exchange_id: nil, index: 0) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/legion/llm/types/chunk.rb', line 12

def self.content_delta(delta:, request_id:, conversation_id: nil, exchange_id: nil, index: 0)
  new(type: :content_delta, delta: delta, index: index,
      request_id: request_id, conversation_id: conversation_id,
      exchange_id: exchange_id, content_block_index: nil,
      tool_call: nil, usage: nil, stop_reason: nil,
      tracing: nil, timestamp: Time.now)
end

.done(request_id:, usage: nil, stop_reason: nil, conversation_id: nil, exchange_id: nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/legion/llm/types/chunk.rb', line 20

def self.done(request_id:, usage: nil, stop_reason: nil, conversation_id: nil, exchange_id: nil)
  new(type: :done, request_id: request_id,
      conversation_id: conversation_id, exchange_id: exchange_id,
      usage: usage, stop_reason: stop_reason,
      index: nil, content_block_index: nil,
      delta: nil, tool_call: nil, tracing: nil, timestamp: Time.now)
end

Instance Method Details

#content?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/legion/llm/types/chunk.rb', line 28

def content?
  type == :content_delta
end

#done?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/legion/llm/types/chunk.rb', line 32

def done?
  type == :done
end

#to_hObject



36
37
38
# File 'lib/legion/llm/types/chunk.rb', line 36

def to_h
  super.compact
end