feat: new Captain Editor (#13235)
Co-authored-by: Aakash Bakhle <48802744+aakashb95@users.noreply.github.com> Co-authored-by: Vishnu Narayanan <iamwishnu@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: aakashb95 <aakashbakhle@gmail.com>
This commit is contained in:
@@ -26,10 +26,18 @@ class LlmFormatter::ConversationLlmFormatter < LlmFormatter::DefaultLlmFormatter
|
||||
def build_messages(config = {})
|
||||
return "No messages in this conversation\n" if @record.messages.empty?
|
||||
|
||||
message_text = ''
|
||||
messages = @record.messages.where.not(message_type: :activity).order(created_at: :asc)
|
||||
messages = @record.messages.where.not(message_type: [:activity, :template])
|
||||
|
||||
messages.each do |message|
|
||||
if config[:token_limit]
|
||||
build_limited_messages(messages, config)
|
||||
else
|
||||
build_all_messages(messages, config)
|
||||
end
|
||||
end
|
||||
|
||||
def build_all_messages(messages, config)
|
||||
message_text = ''
|
||||
messages.order(created_at: :asc).each do |message|
|
||||
# Skip private messages unless explicitly included in config
|
||||
next if message.private? && !config[:include_private_messages]
|
||||
|
||||
@@ -38,6 +46,24 @@ class LlmFormatter::ConversationLlmFormatter < LlmFormatter::DefaultLlmFormatter
|
||||
message_text
|
||||
end
|
||||
|
||||
def build_limited_messages(messages, config)
|
||||
selected = []
|
||||
character_count = 0
|
||||
|
||||
messages.reorder(created_at: :desc).each do |message|
|
||||
# Skip private messages unless explicitly included in config
|
||||
next if message.private? && !config[:include_private_messages]
|
||||
|
||||
formatted = format_message(message)
|
||||
break if character_count + formatted.length > config[:token_limit]
|
||||
|
||||
selected.prepend(formatted)
|
||||
character_count += formatted.length
|
||||
end
|
||||
|
||||
selected.join
|
||||
end
|
||||
|
||||
def format_message(message)
|
||||
sender = case message.sender_type
|
||||
when 'User'
|
||||
|
||||
Reference in New Issue
Block a user