chore: Making OpenAI label suggestions optional (#8374)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -21,11 +21,7 @@ module Enterprise::Integrations::OpenaiProcessorService
|
||||
def labels_with_messages
|
||||
conversation = find_conversation
|
||||
|
||||
# return nil if conversation is not present
|
||||
return nil if conversation.nil?
|
||||
|
||||
# return nil if conversation has less than 3 incoming messages
|
||||
return nil if conversation.messages.incoming.count < 3
|
||||
return nil unless valid_conversation?(conversation)
|
||||
|
||||
labels = hook.account.labels.pluck(:title).join(', ')
|
||||
character_count = labels.length
|
||||
@@ -38,6 +34,19 @@ module Enterprise::Integrations::OpenaiProcessorService
|
||||
"Messages:\n#{messages}\nLabels:\n#{labels}"
|
||||
end
|
||||
|
||||
def valid_conversation?(conversation)
|
||||
return false if conversation.nil?
|
||||
return false if conversation.messages.incoming.count < 3
|
||||
|
||||
# Think Mark think, at this point the conversation is beyond saving
|
||||
return false if conversation.messages.count > 100
|
||||
|
||||
# if there are more than 20 messages, only trigger this if the last message is from the client
|
||||
return false if conversation.messages.count > 20 && !conversation.messages.last.incoming?
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def summarize_body
|
||||
{
|
||||
model: self.class::GPT_MODEL,
|
||||
@@ -50,8 +59,10 @@ module Enterprise::Integrations::OpenaiProcessorService
|
||||
end
|
||||
|
||||
def label_suggestion_body
|
||||
return unless label_suggestions_enabled?
|
||||
|
||||
content = labels_with_messages
|
||||
return nil if content.blank?
|
||||
return value_from_cache if content.blank?
|
||||
|
||||
{
|
||||
model: self.class::GPT_MODEL,
|
||||
@@ -64,4 +75,8 @@ module Enterprise::Integrations::OpenaiProcessorService
|
||||
]
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def label_suggestions_enabled?
|
||||
hook.settings['label_suggestion'].present?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user