Module: LLM::Function::Array
- Defined in:
- lib/llm/function/array.rb
Overview
The Array module extends the array returned by Context#pending_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.
-
#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.
- #-(other) ⇒ LLM::Function::Array
Instance Method Details
#call ⇒ Array<LLM::Function::Return>
Calls all functions in a collection sequentially.
16 17 18 |
# File 'lib/llm/function/array.rb', line 16 def call task(:sequential).wait 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/llm/function/array.rb', line 35 def task(strategy) case strategy when :sequential Sequential::Group.new(map { _1.task(:sequential) }) 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.
70 71 72 |
# File 'lib/llm/function/array.rb', line 70 def wait(strategy) task(strategy).wait end |
#-(other) ⇒ LLM::Function::Array
76 77 78 |
# File 'lib/llm/function/array.rb', line 76 def -(other) super.extend(Array) end |