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
- #-(other) ⇒ LLM::Function::Array
-
#call ⇒ Array<LLM::Function::Return>
Calls all functions in a collection sequentially.
-
#task(strategy) ⇒ LLM::Function::Sequential::Group, ...
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
#-(other) ⇒ LLM::Function::Array
75 76 77 |
# File 'lib/llm/function/array.rb', line 75 def -(other) super.extend(Array) end |
#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 |
#task(strategy) ⇒ LLM::Function::Sequential::Group, ...
Calls all functions in a collection concurrently. This method returns an execution group that can be waited on to access the return values.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/llm/function/array.rb', line 34 def task(strategy) case strategy when :sequential Sequential::Group.new(self) when :async LLM.require "async" unless defined?(::Async) Async::Group.new(map { |fn| fn.task(:async) }) when :thread Thread::Group.new(map { |fn| fn.task(:thread) }) when :fiber Fiber::Group.new(map { |fn| fn.task(:fiber) }) when :fork Fork::Group.new(map { |fn| fn.task(:fork) }) when :ractor Ractor::Group.new(map { |fn| fn.task(:ractor) }) else raise ArgumentError, "Unknown strategy: #{strategy.inspect}. Expected :sequential, :thread, :async, :fiber, :fork, or :ractor" end end |
#wait(strategy) ⇒ Array<LLM::Function::Return>
Calls all functions in a collection concurrently and waits for the return values.
69 70 71 |
# File 'lib/llm/function/array.rb', line 69 def wait(strategy) task(strategy).wait end |