Class: LlmOrchestrator::Chain
- Inherits:
-
Object
- Object
- LlmOrchestrator::Chain
- Defined in:
- lib/llm_orchestrator/chain.rb
Overview
Chain represents a sequence of processing steps for LLM operations It allows for composing multiple LLM operations together with memory persistence
Instance Method Summary collapse
- #add_step(&block) ⇒ Object
- #clear_memory ⇒ Object
-
#initialize(memory: nil) ⇒ Chain
constructor
A new instance of Chain.
- #run(input) ⇒ Object
Constructor Details
Instance Method Details
#add_step(&block) ⇒ Object
11 12 13 14 |
# File 'lib/llm_orchestrator/chain.rb', line 11 def add_step(&block) @steps << block self end |
#clear_memory ⇒ Object
24 25 26 |
# File 'lib/llm_orchestrator/chain.rb', line 24 def clear_memory @memory.clear end |
#run(input) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/llm_orchestrator/chain.rb', line 16 def run(input) @steps.reduce(input) do |result, step| output = step.call(result, @memory) @memory.("assistant", output) if output.is_a?(String) output end end |