feat(ee): Add copilot integration (v1) to the conversation sidebar (#10566)
This commit is contained in:
32
app/services/llm_formatter/conversation_llm_formatter.rb
Normal file
32
app/services/llm_formatter/conversation_llm_formatter.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class LlmFormatter::ConversationLlmFormatter < LlmFormatter::DefaultLlmFormatter
|
||||
def format
|
||||
sections = []
|
||||
sections << "Conversation ID: ##{@record.display_id}"
|
||||
sections << "Channel: #{@record.inbox.channel.name}"
|
||||
sections << 'Message History:'
|
||||
sections << if @record.messages.any?
|
||||
build_messages
|
||||
else
|
||||
'No messages in this conversation'
|
||||
end
|
||||
|
||||
sections.join("\n")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def build_messages
|
||||
return "No messages in this conversation\n" if @record.messages.empty?
|
||||
|
||||
message_text = ''
|
||||
@record.messages.chat.order(created_at: :asc).each do |message|
|
||||
message_text << format_message(message)
|
||||
end
|
||||
message_text
|
||||
end
|
||||
|
||||
def format_message(message)
|
||||
sender = message.message_type == 'incoming' ? 'User' : 'Support agent'
|
||||
"#{sender}: #{message.content}\n"
|
||||
end
|
||||
end
|
||||
9
app/services/llm_formatter/default_llm_formatter.rb
Normal file
9
app/services/llm_formatter/default_llm_formatter.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class LlmFormatter::DefaultLlmFormatter
|
||||
def initialize(record)
|
||||
@record = record
|
||||
end
|
||||
|
||||
def format
|
||||
# override this
|
||||
end
|
||||
end
|
||||
20
app/services/llm_formatter/llm_text_formatter_service.rb
Normal file
20
app/services/llm_formatter/llm_text_formatter_service.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class LlmFormatter::LlmTextFormatterService
|
||||
def initialize(record)
|
||||
@record = record
|
||||
end
|
||||
|
||||
def format
|
||||
formatter_class = find_formatter
|
||||
formatter_class.new(@record).format
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_formatter
|
||||
formatter_name = "LlmFormatter::#{@record.class.name}LlmFormatter"
|
||||
formatter_class = formatter_name.safe_constantize
|
||||
raise FormatterNotFoundError, "No formatter found for #{@record.class.name}" unless formatter_class
|
||||
|
||||
formatter_class
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user