Class: OmniAI::Chat::ToolCallList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/omniai/chat/tool_call_list.rb

Overview

An ‘OmniAI::Chat::ToolCallList` is a collection designed to handle the merging of multiple tool call arrays. LLMs provide a subset of tool call items when chunking, so merging requires the use of the tool call index to combine.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries: []) ⇒ ToolCallList

Returns a new instance of ToolCallList.

Parameters:

  • entries (Array<ToolCall>) (defaults to: [])


11
12
13
# File 'lib/omniai/chat/tool_call_list.rb', line 11

def initialize(entries: [])
  @entries = entries
end

Class Method Details

.deserialize(data, context: nil) ⇒ ToolCallList

Usage:

ToolCallList.deserialize([]) # => #<ToolCallList ...>

Parameters:

  • data (Array)
  • context (Context) (defaults to: nil)

    optional

Returns:



23
24
25
26
27
# File 'lib/omniai/chat/tool_call_list.rb', line 23

def self.deserialize(data, context: nil)
  return unless data

  new(entries: data.map { |subdata| ToolCall.deserialize(subdata, context:) })
end

Instance Method Details

#each {|toolcall| ... } ⇒ Object

Yields:

  • toolcall

Yield Parameters:



47
48
49
# File 'lib/omniai/chat/tool_call_list.rb', line 47

def each(&)
  @entries.each(&)
end

#inspectString

Returns:

  • (String)


41
42
43
# File 'lib/omniai/chat/tool_call_list.rb', line 41

def inspect
  "#<#{self.class.name} entries=#{@entries.inspect}>"
end

#serialize(context: nil) ⇒ Array<Hash>

Usage:

tool_call_list.serialize # => [...]

Parameters:

  • context (Context) (defaults to: nil)

    optional

Returns:

  • (Array<Hash>)


36
37
38
# File 'lib/omniai/chat/tool_call_list.rb', line 36

def serialize(context: nil)
  @entries.compact.map { |tool_call| tool_call.serialize(context:) }
end