Class: Kward::Compaction::ConversationSerializer
- Inherits:
-
Object
- Object
- Kward::Compaction::ConversationSerializer
- Defined in:
- lib/kward/compactor.rb
Overview
Compaction support object used by conversation summarization.
Constant Summary collapse
- TOOL_RESULT_LIMIT =
2_000
Instance Method Summary collapse
-
#initialize(tool_result_summarizer: nil) ⇒ ConversationSerializer
constructor
Creates an object for conversation compaction.
- #serialize(messages) ⇒ Object
Constructor Details
#initialize(tool_result_summarizer: nil) ⇒ ConversationSerializer
Creates an object for conversation compaction.
83 84 85 |
# File 'lib/kward/compactor.rb', line 83 def initialize(tool_result_summarizer: nil) @tool_result_summarizer = tool_result_summarizer end |
Instance Method Details
#serialize(messages) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/kward/compactor.rb', line 87 def serialize() tool_calls_by_id = {} Array().map do || role = ().to_s case role when "user" "[User]: #{(())}" when "assistant" serialize_assistant(, tool_calls_by_id) when "tool", "toolResult" serialize_tool_result(, tool_calls_by_id) when "compactionSummary" "[Branch summary/context]: #{()}" when "bash" "[Bash]: #{(())}" when "custom", "branchSummary" "[Custom]: #{(())}" else "[#{role.empty? ? "Message" : role}]: #{(())}" end end.join("\n\n") end |