chore: Making OpenAI label suggestions optional (#8374)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2023-11-17 19:54:15 -08:00
committed by GitHub
parent 2c5a0abcce
commit 7380f0e7ce
6 changed files with 65 additions and 15 deletions

View File

@@ -16,3 +16,23 @@
width: 100%; width: 100%;
} }
} }
.integration-hooks {
.formulate-input[data-type='checkbox'] {
.formulate-input-wrapper {
@apply flex;
.formulate-input-element {
@apply pr-2;
input {
@apply mb-0;
}
}
}
.formulate-input-element-decorator {
@apply hidden;
}
}
}

View File

@@ -340,7 +340,7 @@ export default {
// method available in mixin, need to ensure that integrations are present // method available in mixin, need to ensure that integrations are present
await this.fetchIntegrationsIfRequired(); await this.fetchIntegrationsIfRequired();
if (!this.isAIIntegrationEnabled) { if (!this.isLabelSuggestionFeatureEnabled) {
return; return;
} }

View File

@@ -15,18 +15,26 @@ export default {
currentChat: 'getSelectedChat', currentChat: 'getSelectedChat',
replyMode: 'draftMessages/getReplyEditorMode', replyMode: 'draftMessages/getReplyEditorMode',
}), }),
isAIIntegrationEnabled() { aiIntegration() {
return !!this.appIntegrations.find( return this.appIntegrations.find(
integration => integration.id === 'openai' && !!integration.hooks.length integration => integration.id === 'openai' && !!integration.hooks.length
); ).hooks[0];
},
isAIIntegrationEnabled() {
return !!this.aiIntegration;
},
isLabelSuggestionFeatureEnabled() {
if (this.aiIntegration) {
const { settings = {} } = this.aiIntegration || {};
return settings.label_suggestion;
}
return false;
}, },
isFetchingAppIntegrations() { isFetchingAppIntegrations() {
return this.uiFlags.isFetching; return this.uiFlags.isFetching;
}, },
hookId() { hookId() {
return this.appIntegrations.find( return this.aiIntegration.id;
integration => integration.id === 'openai' && !!integration.hooks.length
).hooks[0].id;
}, },
draftMessage() { draftMessage() {
return this.$store.getters['draftMessages/get'](this.draftKey); return this.$store.getters['draftMessages/get'](this.draftKey);

View File

@@ -1,6 +1,6 @@
<!-- eslint-disable vue/v-slot-style --> <!-- eslint-disable vue/v-slot-style -->
<template> <template>
<div class="flex flex-col h-auto overflow-auto"> <div class="flex flex-col h-auto overflow-auto integration-hooks">
<woot-modal-header <woot-modal-header
:header-title="integration.name" :header-title="integration.name"
:header-content="integration.description" :header-content="integration.description"

View File

@@ -139,6 +139,7 @@ openai:
"type": "object", "type": "object",
"properties": { "properties": {
"api_key": { "type": "string" }, "api_key": { "type": "string" },
"label_suggestion": { "type": "boolean" },
}, },
"required": ["api_key"], "required": ["api_key"],
"additionalProperties": false, "additionalProperties": false,
@@ -150,5 +151,11 @@ openai:
"name": "api_key", "name": "api_key",
"validation": "required", "validation": "required",
}, },
{
"label": "Show label suggestions",
"type": "checkbox",
"name": "label_suggestion",
"validation": "",
},
] ]
visible_properties: ['api_key'] visible_properties: ['api_key', 'label_suggestion']

View File

@@ -21,11 +21,7 @@ module Enterprise::Integrations::OpenaiProcessorService
def labels_with_messages def labels_with_messages
conversation = find_conversation conversation = find_conversation
# return nil if conversation is not present return nil unless valid_conversation?(conversation)
return nil if conversation.nil?
# return nil if conversation has less than 3 incoming messages
return nil if conversation.messages.incoming.count < 3
labels = hook.account.labels.pluck(:title).join(', ') labels = hook.account.labels.pluck(:title).join(', ')
character_count = labels.length character_count = labels.length
@@ -38,6 +34,19 @@ module Enterprise::Integrations::OpenaiProcessorService
"Messages:\n#{messages}\nLabels:\n#{labels}" "Messages:\n#{messages}\nLabels:\n#{labels}"
end 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 def summarize_body
{ {
model: self.class::GPT_MODEL, model: self.class::GPT_MODEL,
@@ -50,8 +59,10 @@ module Enterprise::Integrations::OpenaiProcessorService
end end
def label_suggestion_body def label_suggestion_body
return unless label_suggestions_enabled?
content = labels_with_messages content = labels_with_messages
return nil if content.blank? return value_from_cache if content.blank?
{ {
model: self.class::GPT_MODEL, model: self.class::GPT_MODEL,
@@ -64,4 +75,8 @@ module Enterprise::Integrations::OpenaiProcessorService
] ]
}.to_json }.to_json
end end
def label_suggestions_enabled?
hook.settings['label_suggestion'].present?
end
end end