Module: LLM::Function::Array
- Defined in:
- lib/llm/function/array.rb
Overview
The Array module extends the array returned by Context#functions with methods that can call all pending functions sequentially or concurrently. The return values can be reported back to the LLM on the next turn.
Instance Method Summary collapse
-
#call ⇒
Array<LLM::Function::Return>
Calls all functions in a collection sequentially.
-
#spawn(strategy) ⇒
LLM::Function::ThreadGroup, ...
Calls all functions in a collection concurrently.
-
#wait(strategy) ⇒
Array<LLM::Function::Return>
Calls all functions in a collection concurrently and waits for the return values.
Instance Method Details
#call ⇒ Array<LLM::Function::Return>
Calls all functions in a collection sequentially.
15 16 17 |
# File 'lib/llm/function/array.rb', line 15 def call map(&:call) end |
#spawn(strategy) ⇒ LLM::Function::ThreadGroup, ...
Calls all functions in a collection concurrently. This method returns an ThreadGroup, TaskGroup, or FiberGroup that can be waited on to access the return values.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/llm/function/array.rb', line 32 def spawn(strategy) case strategy when :task TaskGroup.new(map { |fn| fn.spawn(:task) }) when :thread ThreadGroup.new(map { |fn| fn.spawn(:thread) }) when :fiber FiberGroup.new(map { |fn| fn.spawn(:fiber) }) else raise ArgumentError, "Unknown strategy: #{strategy.inspect}. Expected :thread, :task, or :fiber" end end |
#wait(strategy) ⇒ Array<LLM::Function::Return>
Calls all functions in a collection concurrently and waits for the return values.
57 58 59 |
# File 'lib/llm/function/array.rb', line 57 def wait(strategy) spawn(strategy).wait end |