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.
188 189 190 |
# File 'lib/kward/compactor.rb', line 188 def initialize(tool_result_summarizer: nil) @tool_result_summarizer = tool_result_summarizer end |
Instance Method Details
#serialize(messages) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/kward/compactor.rb', line 192 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 |