Class: LlmOrchestrator::Memory
- Inherits:
-
Object
- Object
- LlmOrchestrator::Memory
- Defined in:
- lib/llm_orchestrator/memory.rb
Overview
Memory manages conversation history and context for LLM interactions Handles message storage, token limits, and context management
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #add_message(role, content) ⇒ Object
- #clear ⇒ Object
- #context_string ⇒ Object
-
#initialize(max_tokens: 2000) ⇒ Memory
constructor
Input prompts of 4-6K are ideal.
Constructor Details
#initialize(max_tokens: 2000) ⇒ Memory
Input prompts of 4-6K are ideal
10 11 12 13 |
# File 'lib/llm_orchestrator/memory.rb', line 10 def initialize(max_tokens: 2000) @messages = [] @max_tokens = max_tokens # Adjust based on your needs end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
7 8 9 |
# File 'lib/llm_orchestrator/memory.rb', line 7 def @messages end |
Instance Method Details
#add_message(role, content) ⇒ Object
15 16 17 18 |
# File 'lib/llm_orchestrator/memory.rb', line 15 def (role, content) @messages << { role: role, content: content } if exceeds_token_limit? end |
#clear ⇒ Object
20 21 22 |
# File 'lib/llm_orchestrator/memory.rb', line 20 def clear @messages.clear end |
#context_string ⇒ Object
24 25 26 |
# File 'lib/llm_orchestrator/memory.rb', line 24 def context_string @messages.map { |msg| "#{msg[:role]}: #{msg[:content]}" }.join("\n") end |