mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 04:27:53 +00:00
feat: Reply suggestion and summary generation using OpenAI (#7029)
Add `reply_suggestions` and `summary_generation` options for OpenAI integration Fixes: https://linear.app/chatwoot/issue/CW-1595/frontend-for-generating-conversation-summary Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -7,14 +7,22 @@ class OpenAIAPI extends ApiClient {
|
|||||||
super('integrations', { accountScoped: true });
|
super('integrations', { accountScoped: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
processEvent({ name = 'rephrase', content, tone, hookId }) {
|
processEvent({ type = 'rephrase', content, tone, conversationId, hookId }) {
|
||||||
|
let data = {
|
||||||
|
tone,
|
||||||
|
content,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (type === 'reply_suggestion' || type === 'summarize') {
|
||||||
|
data = {
|
||||||
|
conversation_display_id: conversationId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return axios.post(`${this.url}/hooks/${hookId}/process_event`, {
|
return axios.post(`${this.url}/hooks/${hookId}/process_event`, {
|
||||||
event: {
|
event: {
|
||||||
name: name,
|
name: type,
|
||||||
data: {
|
data,
|
||||||
tone,
|
|
||||||
content,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ $button-sizes: (tiny: var(--font-size-micro),
|
|||||||
default: var(--font-size-small),
|
default: var(--font-size-small),
|
||||||
large: var(--font-size-medium));
|
large: var(--font-size-medium));
|
||||||
$button-palette: $foundation-palette;
|
$button-palette: $foundation-palette;
|
||||||
$button-opacity-disabled: 0.25;
|
$button-opacity-disabled: 0.4;
|
||||||
$button-background-hover-lightness: -20%;
|
$button-background-hover-lightness: -20%;
|
||||||
$button-hollow-hover-lightness: -50%;
|
$button-hollow-hover-lightness: -50%;
|
||||||
$button-transition: background-color 0.25s ease-out,
|
$button-transition: background-color 0.25s ease-out,
|
||||||
|
|||||||
@@ -6,7 +6,11 @@
|
|||||||
:disabled="isDisabled || isLoading"
|
:disabled="isDisabled || isLoading"
|
||||||
@click="handleClick"
|
@click="handleClick"
|
||||||
>
|
>
|
||||||
<spinner v-if="isLoading" size="small" />
|
<spinner
|
||||||
|
v-if="isLoading"
|
||||||
|
size="small"
|
||||||
|
:color-scheme="showDarkSpinner ? 'dark' : ''"
|
||||||
|
/>
|
||||||
<emoji-or-icon
|
<emoji-or-icon
|
||||||
v-else-if="icon || emoji"
|
v-else-if="icon || emoji"
|
||||||
class="icon"
|
class="icon"
|
||||||
@@ -108,6 +112,14 @@ export default {
|
|||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
showDarkSpinner() {
|
||||||
|
return (
|
||||||
|
this.colorScheme === 'secondary' ||
|
||||||
|
this.variant === 'clear' ||
|
||||||
|
this.variant === 'link' ||
|
||||||
|
this.variant === 'hollow'
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleClick(evt) {
|
handleClick(evt) {
|
||||||
|
|||||||
@@ -1,45 +1,70 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="isAIIntegrationEnabled" class="position-relative">
|
<div v-if="isAIIntegrationEnabled" class="position-relative">
|
||||||
<woot-button
|
<div v-if="!message">
|
||||||
v-tooltip.top-end="$t('INTEGRATION_SETTINGS.OPEN_AI.TITLE')"
|
<woot-button
|
||||||
icon="wand"
|
v-if="isPrivateNote"
|
||||||
color-scheme="secondary"
|
v-tooltip.top-end="$t('INTEGRATION_SETTINGS.OPEN_AI.SUMMARY_TITLE')"
|
||||||
variant="smooth"
|
icon="book-pulse"
|
||||||
size="small"
|
color-scheme="secondary"
|
||||||
@click="toggleDropdown"
|
variant="smooth"
|
||||||
/>
|
size="small"
|
||||||
<div
|
:is-loading="uiFlags.summarize"
|
||||||
v-if="showDropdown"
|
@click="processEvent('summarize')"
|
||||||
v-on-clickaway="closeDropdown"
|
/>
|
||||||
class="dropdown-pane dropdown-pane--open ai-modal"
|
<woot-button
|
||||||
>
|
v-else
|
||||||
<h4 class="sub-block-title margin-top-1">
|
v-tooltip.top-end="$t('INTEGRATION_SETTINGS.OPEN_AI.REPLY_TITLE')"
|
||||||
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.TITLE') }}
|
icon="wand"
|
||||||
</h4>
|
color-scheme="secondary"
|
||||||
<p>
|
variant="smooth"
|
||||||
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.SUBTITLE') }}
|
size="small"
|
||||||
</p>
|
:is-loading="uiFlags.reply_suggestion"
|
||||||
<label>
|
@click="processEvent('reply_suggestion')"
|
||||||
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.TONE.TITLE') }}
|
/>
|
||||||
</label>
|
</div>
|
||||||
<div class="tone__item">
|
|
||||||
<select v-model="activeTone" class="status--filter small">
|
<div v-else>
|
||||||
<option v-for="tone in tones" :key="tone.key" :value="tone.key">
|
<woot-button
|
||||||
{{ tone.value }}
|
v-tooltip.top-end="$t('INTEGRATION_SETTINGS.OPEN_AI.TITLE')"
|
||||||
</option>
|
icon="text-grammar-wand"
|
||||||
</select>
|
color-scheme="secondary"
|
||||||
</div>
|
variant="smooth"
|
||||||
<div class="modal-footer flex-container align-right">
|
size="small"
|
||||||
<woot-button variant="clear" size="small" @click="closeDropdown">
|
@click="toggleDropdown"
|
||||||
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.CANCEL') }}
|
/>
|
||||||
</woot-button>
|
<div
|
||||||
<woot-button
|
v-if="showDropdown"
|
||||||
:is-loading="isGenerating"
|
v-on-clickaway="closeDropdown"
|
||||||
size="small"
|
class="dropdown-pane dropdown-pane--open ai-modal"
|
||||||
@click="processText"
|
>
|
||||||
>
|
<h4 class="sub-block-title margin-top-1">
|
||||||
{{ buttonText }}
|
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.TITLE') }}
|
||||||
</woot-button>
|
</h4>
|
||||||
|
<p>
|
||||||
|
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.SUBTITLE') }}
|
||||||
|
</p>
|
||||||
|
<label>
|
||||||
|
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.TONE.TITLE') }}
|
||||||
|
</label>
|
||||||
|
<div class="tone__item">
|
||||||
|
<select v-model="activeTone" class="status--filter small">
|
||||||
|
<option v-for="tone in tones" :key="tone.key" :value="tone.key">
|
||||||
|
{{ tone.value }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer flex-container align-right">
|
||||||
|
<woot-button variant="clear" size="small" @click="closeDropdown">
|
||||||
|
{{ $t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.CANCEL') }}
|
||||||
|
</woot-button>
|
||||||
|
<woot-button
|
||||||
|
:is-loading="uiFlags.rephrase"
|
||||||
|
size="small"
|
||||||
|
@click="processEvent('rephrase')"
|
||||||
|
>
|
||||||
|
{{ buttonText }}
|
||||||
|
</woot-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -61,10 +86,18 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
isPrivateNote: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isGenerating: false,
|
uiFlags: {
|
||||||
|
rephrase: false,
|
||||||
|
reply_suggestion: false,
|
||||||
|
summarize: false,
|
||||||
|
},
|
||||||
showDropdown: false,
|
showDropdown: false,
|
||||||
activeTone: 'professional',
|
activeTone: 'professional',
|
||||||
tones: [
|
tones: [
|
||||||
@@ -94,7 +127,7 @@ export default {
|
|||||||
).hooks[0].id;
|
).hooks[0].id;
|
||||||
},
|
},
|
||||||
buttonText() {
|
buttonText() {
|
||||||
return this.isGenerating
|
return this.uiFlags.isRephrasing
|
||||||
? this.$t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.GENERATING')
|
? this.$t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.GENERATING')
|
||||||
: this.$t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.GENERATE');
|
: this.$t('INTEGRATION_SETTINGS.OPEN_AI.BUTTONS.GENERATE');
|
||||||
},
|
},
|
||||||
@@ -111,14 +144,15 @@ export default {
|
|||||||
closeDropdown() {
|
closeDropdown() {
|
||||||
this.showDropdown = false;
|
this.showDropdown = false;
|
||||||
},
|
},
|
||||||
async processText() {
|
async processEvent(type = 'rephrase') {
|
||||||
this.isGenerating = true;
|
this.uiFlags[type] = true;
|
||||||
try {
|
try {
|
||||||
const result = await OpenAPI.processEvent({
|
const result = await OpenAPI.processEvent({
|
||||||
hookId: this.hookId,
|
hookId: this.hookId,
|
||||||
type: 'rephrase',
|
type,
|
||||||
content: this.message,
|
content: this.message,
|
||||||
tone: this.activeTone,
|
tone: this.activeTone,
|
||||||
|
conversationId: this.conversationId,
|
||||||
});
|
});
|
||||||
const {
|
const {
|
||||||
data: { message: generatedMessage },
|
data: { message: generatedMessage },
|
||||||
@@ -128,7 +162,7 @@ export default {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.showAlert(this.$t('INTEGRATION_SETTINGS.OPEN_AI.GENERATE_ERROR'));
|
this.showAlert(this.$t('INTEGRATION_SETTINGS.OPEN_AI.GENERATE_ERROR'));
|
||||||
} finally {
|
} finally {
|
||||||
this.isGenerating = false;
|
this.uiFlags[type] = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -38,12 +38,12 @@
|
|||||||
</file-upload>
|
</file-upload>
|
||||||
<woot-button
|
<woot-button
|
||||||
v-if="showAudioRecorderButton"
|
v-if="showAudioRecorderButton"
|
||||||
|
v-tooltip.top-end="$t('CONVERSATION.REPLYBOX.TIP_AUDIORECORDER_ICON')"
|
||||||
:icon="!isRecordingAudio ? 'microphone' : 'microphone-off'"
|
:icon="!isRecordingAudio ? 'microphone' : 'microphone-off'"
|
||||||
emoji="🎤"
|
emoji="🎤"
|
||||||
:color-scheme="!isRecordingAudio ? 'secondary' : 'alert'"
|
:color-scheme="!isRecordingAudio ? 'secondary' : 'alert'"
|
||||||
variant="smooth"
|
variant="smooth"
|
||||||
size="small"
|
size="small"
|
||||||
:title="$t('CONVERSATION.REPLYBOX.TIP_AUDIORECORDER_ICON')"
|
|
||||||
@click="toggleAudioRecorder"
|
@click="toggleAudioRecorder"
|
||||||
/>
|
/>
|
||||||
<woot-button
|
<woot-button
|
||||||
@@ -92,8 +92,8 @@
|
|||||||
:conversation-id="conversationId"
|
:conversation-id="conversationId"
|
||||||
/>
|
/>
|
||||||
<AIAssistanceButton
|
<AIAssistanceButton
|
||||||
v-if="message"
|
|
||||||
:conversation-id="conversationId"
|
:conversation-id="conversationId"
|
||||||
|
:is-private-note="isOnPrivateNote"
|
||||||
:message="message"
|
:message="message"
|
||||||
@replace-text="replaceText"
|
@replace-text="replaceText"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -84,6 +84,8 @@
|
|||||||
},
|
},
|
||||||
"OPEN_AI": {
|
"OPEN_AI": {
|
||||||
"TITLE": "Improve With AI",
|
"TITLE": "Improve With AI",
|
||||||
|
"SUMMARY_TITLE": "Summary with AI",
|
||||||
|
"REPLY_TITLE": "Reply suggestion with AI",
|
||||||
"SUBTITLE": "An improved reply will be generated using AI, based on your current draft.",
|
"SUBTITLE": "An improved reply will be generated using AI, based on your current draft.",
|
||||||
"TONE": {
|
"TONE": {
|
||||||
"TITLE": "Tone",
|
"TITLE": "Tone",
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
"book-contacts-outline": "M15.5 12.25a.75.75 0 0 0-.75-.75h-5a.75.75 0 0 0-.75.75v.5c0 1 1.383 1.75 3.25 1.75s3.25-.75 3.25-1.75v-.5ZM14 8.745C14 7.78 13.217 7 12.25 7s-1.75.779-1.75 1.745a1.75 1.75 0 1 0 3.5 0ZM4 4.5A2.5 2.5 0 0 1 6.5 2H18a2.5 2.5 0 0 1 2.5 2.5v14.25a.75.75 0 0 1-.75.75H5.5a1 1 0 0 0 1 1h13.25a.75.75 0 0 1 0 1.5H6.5A2.5 2.5 0 0 1 4 19.5v-15Zm1.5 0V18H19V4.5a1 1 0 0 0-1-1H6.5a1 1 0 0 0-1 1Z",
|
"book-contacts-outline": "M15.5 12.25a.75.75 0 0 0-.75-.75h-5a.75.75 0 0 0-.75.75v.5c0 1 1.383 1.75 3.25 1.75s3.25-.75 3.25-1.75v-.5ZM14 8.745C14 7.78 13.217 7 12.25 7s-1.75.779-1.75 1.745a1.75 1.75 0 1 0 3.5 0ZM4 4.5A2.5 2.5 0 0 1 6.5 2H18a2.5 2.5 0 0 1 2.5 2.5v14.25a.75.75 0 0 1-.75.75H5.5a1 1 0 0 0 1 1h13.25a.75.75 0 0 1 0 1.5H6.5A2.5 2.5 0 0 1 4 19.5v-15Zm1.5 0V18H19V4.5a1 1 0 0 0-1-1H6.5a1 1 0 0 0-1 1Z",
|
||||||
"book-open-globe-outline": "M3.5 5.75a.25.25 0 0 1 .25-.25H10c.69 0 1.25.56 1.25 1.25v8.959a6.49 6.49 0 0 1 1.5-2.646V6.75c0-.69.56-1.25 1.25-1.25h6.25a.25.25 0 0 1 .25.25v5.982A6.518 6.518 0 0 1 22 12.81V5.75A1.75 1.75 0 0 0 20.25 4H14c-.788 0-1.499.331-2 .863A2.742 2.742 0 0 0 10 4H3.75A1.75 1.75 0 0 0 2 5.75v12.5c0 .966.784 1.75 1.75 1.75H10c.495 0 .96-.13 1.36-.36a6.473 6.473 0 0 1-.343-1.663A1.248 1.248 0 0 1 10 18.5H3.75a.25.25 0 0 1-.25-.25V5.75ZM16.007 17c.04-1.415.248-2.669.553-3.585.171-.513.364-.893.554-1.134.195-.247.329-.281.386-.281.057 0 .192.034.386.281.19.241.383.62.554 1.134.305.916.513 2.17.553 3.585h-2.986Zm-.396-3.9c.108-.323.23-.622.368-.887A5.504 5.504 0 0 0 12.023 17h2.984c.04-1.5.26-2.866.604-3.9Zm3.778 0a6.133 6.133 0 0 0-.368-.887A5.504 5.504 0 0 1 22.978 17h-2.985c-.04-1.5-.26-2.866-.604-3.9Zm.604 4.9h2.985a5.504 5.504 0 0 1-3.957 4.787c.138-.265.26-.564.368-.886.345-1.035.564-2.4.604-3.901Zm-2.107 4.719c-.194.247-.329.281-.386.281-.057 0-.191-.034-.386-.281-.19-.241-.383-.62-.554-1.135-.305-.915-.513-2.17-.553-3.584h2.986c-.04 1.415-.248 2.669-.553 3.584-.171.514-.364.894-.554 1.135ZM12.023 18a5.504 5.504 0 0 0 3.956 4.787 6.133 6.133 0 0 1-.367-.886c-.346-1.035-.565-2.4-.605-3.901h-2.984Z",
|
"book-open-globe-outline": "M3.5 5.75a.25.25 0 0 1 .25-.25H10c.69 0 1.25.56 1.25 1.25v8.959a6.49 6.49 0 0 1 1.5-2.646V6.75c0-.69.56-1.25 1.25-1.25h6.25a.25.25 0 0 1 .25.25v5.982A6.518 6.518 0 0 1 22 12.81V5.75A1.75 1.75 0 0 0 20.25 4H14c-.788 0-1.499.331-2 .863A2.742 2.742 0 0 0 10 4H3.75A1.75 1.75 0 0 0 2 5.75v12.5c0 .966.784 1.75 1.75 1.75H10c.495 0 .96-.13 1.36-.36a6.473 6.473 0 0 1-.343-1.663A1.248 1.248 0 0 1 10 18.5H3.75a.25.25 0 0 1-.25-.25V5.75ZM16.007 17c.04-1.415.248-2.669.553-3.585.171-.513.364-.893.554-1.134.195-.247.329-.281.386-.281.057 0 .192.034.386.281.19.241.383.62.554 1.134.305.916.513 2.17.553 3.585h-2.986Zm-.396-3.9c.108-.323.23-.622.368-.887A5.504 5.504 0 0 0 12.023 17h2.984c.04-1.5.26-2.866.604-3.9Zm3.778 0a6.133 6.133 0 0 0-.368-.887A5.504 5.504 0 0 1 22.978 17h-2.985c-.04-1.5-.26-2.866-.604-3.9Zm.604 4.9h2.985a5.504 5.504 0 0 1-3.957 4.787c.138-.265.26-.564.368-.886.345-1.035.564-2.4.604-3.901Zm-2.107 4.719c-.194.247-.329.281-.386.281-.057 0-.191-.034-.386-.281-.19-.241-.383-.62-.554-1.135-.305-.915-.513-2.17-.553-3.584h2.986c-.04 1.415-.248 2.669-.553 3.584-.171.514-.364.894-.554 1.135ZM12.023 18a5.504 5.504 0 0 0 3.956 4.787 6.133 6.133 0 0 1-.367-.886c-.346-1.035-.565-2.4-.605-3.901h-2.984Z",
|
||||||
"book-outline": "M4 4.5A2.5 2.5 0 0 1 6.5 2H18a2.5 2.5 0 0 1 2.5 2.5v14.25a.75.75 0 0 1-.75.75H5.5a1 1 0 0 0 1 1h13.25a.75.75 0 0 1 0 1.5H6.5A2.5 2.5 0 0 1 4 19.5v-15ZM5.5 18H19V4.5a1 1 0 0 0-1-1H6.5a1 1 0 0 0-1 1V18Z",
|
"book-outline": "M4 4.5A2.5 2.5 0 0 1 6.5 2H18a2.5 2.5 0 0 1 2.5 2.5v14.25a.75.75 0 0 1-.75.75H5.5a1 1 0 0 0 1 1h13.25a.75.75 0 0 1 0 1.5H6.5A2.5 2.5 0 0 1 4 19.5v-15ZM5.5 18H19V4.5a1 1 0 0 0-1-1H6.5a1 1 0 0 0-1 1V18Z",
|
||||||
|
"book-pulse-outline": [
|
||||||
|
"M11.69 7.458a.75.75 0 0 0-1.36-.043L8.785 10.5H7.75a.75.75 0 0 0 0 1.5h1.5a.75.75 0 0 0 .67-.415l1.023-2.044 2.116 5.001a.75.75 0 0 0 1.339.086L15.93 12h.819a.75.75 0 0 0 0-1.5H15.5a.75.75 0 0 0-.648.372l-.995 1.706-2.166-5.12Z",
|
||||||
|
"M6.5 2A2.5 2.5 0 0 0 4 4.5v15A2.5 2.5 0 0 0 6.5 22h13.25a.75.75 0 0 0 0-1.5H6.5a1 1 0 0 1-1-1h14.25a.75.75 0 0 0 .75-.75V4.5A2.5 2.5 0 0 0 18 2H6.5ZM19 18H5.5V4.5a1 1 0 0 1 1-1H18a1 1 0 0 1 1 1V18Z"
|
||||||
|
],
|
||||||
"bot-outline": "M17.753 14a2.25 2.25 0 0 1 2.25 2.25v.905a3.75 3.75 0 0 1-1.307 2.846C17.13 21.345 14.89 22 12 22c-2.89 0-5.128-.656-6.691-2a3.75 3.75 0 0 1-1.306-2.843v-.908A2.25 2.25 0 0 1 6.253 14h11.5Zm0 1.5h-11.5a.75.75 0 0 0-.75.75v.908c0 .655.286 1.278.784 1.706C7.545 19.945 9.44 20.502 12 20.502c2.56 0 4.458-.557 5.719-1.64a2.25 2.25 0 0 0 .784-1.706v-.906a.75.75 0 0 0-.75-.75ZM11.898 2.008 12 2a.75.75 0 0 1 .743.648l.007.102V3.5h3.5a2.25 2.25 0 0 1 2.25 2.25v4.505a2.25 2.25 0 0 1-2.25 2.25h-8.5a2.25 2.25 0 0 1-2.25-2.25V5.75A2.25 2.25 0 0 1 7.75 3.5h3.5v-.749a.75.75 0 0 1 .648-.743L12 2l-.102.007ZM16.25 5h-8.5a.75.75 0 0 0-.75.75v4.505c0 .414.336.75.75.75h8.5a.75.75 0 0 0 .75-.75V5.75a.75.75 0 0 0-.75-.75Zm-6.5 1.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Zm4.492 0a1.25 1.25 0 1 1 0 2.499 1.25 1.25 0 0 1 0-2.499Z",
|
"bot-outline": "M17.753 14a2.25 2.25 0 0 1 2.25 2.25v.905a3.75 3.75 0 0 1-1.307 2.846C17.13 21.345 14.89 22 12 22c-2.89 0-5.128-.656-6.691-2a3.75 3.75 0 0 1-1.306-2.843v-.908A2.25 2.25 0 0 1 6.253 14h11.5Zm0 1.5h-11.5a.75.75 0 0 0-.75.75v.908c0 .655.286 1.278.784 1.706C7.545 19.945 9.44 20.502 12 20.502c2.56 0 4.458-.557 5.719-1.64a2.25 2.25 0 0 0 .784-1.706v-.906a.75.75 0 0 0-.75-.75ZM11.898 2.008 12 2a.75.75 0 0 1 .743.648l.007.102V3.5h3.5a2.25 2.25 0 0 1 2.25 2.25v4.505a2.25 2.25 0 0 1-2.25 2.25h-8.5a2.25 2.25 0 0 1-2.25-2.25V5.75A2.25 2.25 0 0 1 7.75 3.5h3.5v-.749a.75.75 0 0 1 .648-.743L12 2l-.102.007ZM16.25 5h-8.5a.75.75 0 0 0-.75.75v4.505c0 .414.336.75.75.75h8.5a.75.75 0 0 0 .75-.75V5.75a.75.75 0 0 0-.75-.75Zm-6.5 1.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Zm4.492 0a1.25 1.25 0 1 1 0 2.499 1.25 1.25 0 0 1 0-2.499Z",
|
||||||
"brand-facebook-outline": "M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z",
|
"brand-facebook-outline": "M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z",
|
||||||
"brand-instagram-outline": "M 8 3 C 5.243 3 3 5.243 3 8 L 3 16 C 3 18.757 5.243 21 8 21 L 16 21 C 18.757 21 21 18.757 21 16 L 21 8 C 21 5.243 18.757 3 16 3 L 8 3 z M 8 5 L 16 5 C 17.654 5 19 6.346 19 8 L 19 16 C 19 17.654 17.654 19 16 19 L 8 19 C 6.346 19 5 17.654 5 16 L 5 8 C 5 6.346 6.346 5 8 5 z M 17 6 A 1 1 0 0 0 16 7 A 1 1 0 0 0 17 8 A 1 1 0 0 0 18 7 A 1 1 0 0 0 17 6 z M 12 7 C 9.243 7 7 9.243 7 12 C 7 14.757 9.243 17 12 17 C 14.757 17 17 14.757 17 12 C 17 9.243 14.757 7 12 7 z M 12 9 C 13.654 9 15 10.346 15 12 C 15 13.654 13.654 15 12 15 C 10.346 15 9 13.654 9 12 C 9 10.346 10.346 9 12 9 z",
|
"brand-instagram-outline": "M 8 3 C 5.243 3 3 5.243 3 8 L 3 16 C 3 18.757 5.243 21 8 21 L 16 21 C 18.757 21 21 18.757 21 16 L 21 8 C 21 5.243 18.757 3 16 3 L 8 3 z M 8 5 L 16 5 C 17.654 5 19 6.346 19 8 L 19 16 C 19 17.654 17.654 19 16 19 L 8 19 C 6.346 19 5 17.654 5 16 L 5 8 C 5 6.346 6.346 5 8 5 z M 17 6 A 1 1 0 0 0 16 7 A 1 1 0 0 0 17 8 A 1 1 0 0 0 18 7 A 1 1 0 0 0 17 6 z M 12 7 C 9.243 7 7 9.243 7 12 C 7 14.757 9.243 17 12 17 C 14.757 17 17 14.757 17 12 C 17 9.243 14.757 7 12 7 z M 12 9 C 13.654 9 15 10.346 15 12 C 15 13.654 13.654 15 12 15 C 10.346 15 9 13.654 9 12 C 9 10.346 10.346 9 12 9 z",
|
||||||
@@ -175,6 +179,10 @@
|
|||||||
"M8.78 1.22a.75.75 0 0 0-1.06 1.06l.72.72H6.25A3.25 3.25 0 0 0 3 6.25v2.19l-.72-.72a.75.75 0 0 0-1.06 1.06l2 2a.748.748 0 0 0 1.06 0l2-2a.747.747 0 0 0 0-1.06.75.75 0 0 0-1.06 0l-.72.72V6.25c0-.966.784-1.75 1.75-1.75h2.19l-.72.72a.75.75 0 0 0 .78 1.237.75.75 0 0 0 .28-.177l2-2a.75.75 0 0 0 0-1.06l-2-2Z",
|
"M8.78 1.22a.75.75 0 0 0-1.06 1.06l.72.72H6.25A3.25 3.25 0 0 0 3 6.25v2.19l-.72-.72a.75.75 0 0 0-1.06 1.06l2 2a.748.748 0 0 0 1.06 0l2-2a.747.747 0 0 0 0-1.06.75.75 0 0 0-1.06 0l-.72.72V6.25c0-.966.784-1.75 1.75-1.75h2.19l-.72.72a.75.75 0 0 0 .78 1.237.75.75 0 0 0 .28-.177l2-2a.75.75 0 0 0 0-1.06l-2-2Z",
|
||||||
"M11.832 3a1.755 1.755 0 0 1 0 1.5H14v4h-4V6.475l-.513.512a1.742 1.742 0 0 1-.987.495V8.5H7.482c-.052.361-.217.71-.495.987L6.475 10H8.5v4h-4v-2.168a1.755 1.755 0 0 1-1.5 0v5.918A3.25 3.25 0 0 0 6.25 21h11.5A3.25 3.25 0 0 0 21 17.75V6.25A3.25 3.25 0 0 0 17.75 3h-5.918ZM10 14v-4h4v4h-4Zm5.5 0v-4h4v4h-4ZM14 15.5v4h-4v-4h4Zm1.5 4v-4h4v2.25a1.75 1.75 0 0 1-1.75 1.75H15.5Zm0-11v-4h2.25c.966 0 1.75.784 1.75 1.75V8.5h-4Zm-11 7h4v4H6.25a1.75 1.75 0 0 1-1.75-1.75V15.5Z"
|
"M11.832 3a1.755 1.755 0 0 1 0 1.5H14v4h-4V6.475l-.513.512a1.742 1.742 0 0 1-.987.495V8.5H7.482c-.052.361-.217.71-.495.987L6.475 10H8.5v4h-4v-2.168a1.755 1.755 0 0 1-1.5 0v5.918A3.25 3.25 0 0 0 6.25 21h11.5A3.25 3.25 0 0 0 21 17.75V6.25A3.25 3.25 0 0 0 17.75 3h-5.918ZM10 14v-4h4v4h-4Zm5.5 0v-4h4v4h-4ZM14 15.5v4h-4v-4h4Zm1.5 4v-4h4v2.25a1.75 1.75 0 0 1-1.75 1.75H15.5Zm0-11v-4h2.25c.966 0 1.75.784 1.75 1.75V8.5h-4Zm-11 7h4v4H6.25a1.75 1.75 0 0 1-1.75-1.75V15.5Z"
|
||||||
],
|
],
|
||||||
|
"text-grammar-wand-outline": [
|
||||||
|
"M2.75 17h7.775l-1.5 1.5H2.75a.75.75 0 0 1-.102-1.493L2.75 17ZM2.75 14.5h7.564a1.745 1.745 0 0 1-.241-1.5H2.75l-.102.007A.75.75 0 0 0 2.75 14.5ZM12.72 16.22a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06-1.06l4.5-4.5ZM2.75 9h10.5a.75.75 0 0 1 .102 1.493l-.102.007H2.75a.75.75 0 0 1-.102-1.493L2.75 9ZM2.75 5h18.5a.75.75 0 0 1 .102 1.493l-.102.007H2.75a.75.75 0 0 1-.102-1.493L2.75 5Z",
|
||||||
|
"M16.5 8a.75.75 0 0 1 .744.658l.14 1.13a3.25 3.25 0 0 0 2.828 2.829l1.13.139a.75.75 0 0 1 0 1.488l-1.13.14a3.25 3.25 0 0 0-2.829 2.828l-.139 1.13a.75.75 0 0 1-1.488 0l-.14-1.13a3.25 3.25 0 0 0-2.828-2.829l-1.13-.139a.75.75 0 0 1 0-1.488l1.13-.14a3.25 3.25 0 0 0 2.829-2.828l.139-1.13A.75.75 0 0 1 16.5 8Zm0 3.774a4.761 4.761 0 0 1-1.726 1.726 4.761 4.761 0 0 1 1.726 1.726 4.761 4.761 0 0 1 1.726-1.726 4.761 4.761 0 0 1-1.726-1.726Z"
|
||||||
|
],
|
||||||
"translate-outline": "M16.953 5.303a1 1 0 0 0-1.906-.606c-.124.389-.236.899-.324 1.344-.565.012-1.12 0-1.652-.038a1 1 0 1 0-.142 1.995c.46.032.934.048 1.416.047a25.649 25.649 0 0 0-.24 1.698c-1.263.716-2.142 1.684-2.636 2.7-.624 1.283-.7 2.857.239 3.883.675.736 1.704.758 2.499.588.322-.068.654-.176.988-.32a1 1 0 0 0 1.746-.93 13.17 13.17 0 0 0-.041-.115 8.404 8.404 0 0 0 2.735-4.06c.286.251.507.55.658.864.284.594.334 1.271.099 1.91-.234.633-.78 1.313-1.84 1.843a1 1 0 0 0 .895 1.789c1.44-.72 2.385-1.758 2.821-2.94a4.436 4.436 0 0 0-.17-3.464 4.752 4.752 0 0 0-2.104-2.165C19.998 9.22 20 9.11 20 9a1 1 0 0 0-1.974-.23 5.984 5.984 0 0 0-1.796.138c.047-.305.102-.626.166-.964a20.142 20.142 0 0 0 2.842-.473 1 1 0 0 0-.476-1.942c-.622.152-1.286.272-1.964.358.048-.208.1-.409.155-.584Zm-3.686 8.015c.166-.34.414-.697.758-1.037.02.348.053.67.098.973.083.56.207 1.048.341 1.477a3.41 3.41 0 0 1-.674.227c-.429.092-.588.019-.614.006l-.004-.001c-.162-.193-.329-.774.095-1.645Zm4.498-2.562a6.362 6.362 0 0 1-1.568 2.73 7.763 7.763 0 0 1-.095-.525 10.294 10.294 0 0 1-.088-1.904c.033-.013.067-.024.1-.036l1.651-.265Zm0 0-1.651.265c.602-.212 1.155-.29 1.651-.265ZM7.536 6.29a6.342 6.342 0 0 0-4.456.331 1 1 0 0 0 .848 1.811 4.342 4.342 0 0 1 3.049-.222c.364.107.568.248.69.37.12.123.203.27.257.454.067.225.087.446.09.69a8.195 8.195 0 0 0-.555-.117c-1.146-.199-2.733-.215-4.262.64-1.271.713-1.796 2.168-1.682 3.448.12 1.326.94 2.679 2.572 3.136 1.48.414 2.913-.045 3.877-.507l.08-.04a1 1 0 0 0 1.96-.281V10.5c0-.053.002-.12.005-.2.012-.417.034-1.16-.168-1.838a3.043 3.043 0 0 0-.755-1.29c-.394-.398-.91-.694-1.547-.881h-.003Zm-.419 5.288c.344.06.647.143.887.222v2.197a7.021 7.021 0 0 1-.905.524c-.792.38-1.682.605-2.473.384-.698-.195-1.06-.742-1.119-1.389-.062-.693.243-1.286.667-1.523.987-.553 2.06-.569 2.943-.415Z",
|
"translate-outline": "M16.953 5.303a1 1 0 0 0-1.906-.606c-.124.389-.236.899-.324 1.344-.565.012-1.12 0-1.652-.038a1 1 0 1 0-.142 1.995c.46.032.934.048 1.416.047a25.649 25.649 0 0 0-.24 1.698c-1.263.716-2.142 1.684-2.636 2.7-.624 1.283-.7 2.857.239 3.883.675.736 1.704.758 2.499.588.322-.068.654-.176.988-.32a1 1 0 0 0 1.746-.93 13.17 13.17 0 0 0-.041-.115 8.404 8.404 0 0 0 2.735-4.06c.286.251.507.55.658.864.284.594.334 1.271.099 1.91-.234.633-.78 1.313-1.84 1.843a1 1 0 0 0 .895 1.789c1.44-.72 2.385-1.758 2.821-2.94a4.436 4.436 0 0 0-.17-3.464 4.752 4.752 0 0 0-2.104-2.165C19.998 9.22 20 9.11 20 9a1 1 0 0 0-1.974-.23 5.984 5.984 0 0 0-1.796.138c.047-.305.102-.626.166-.964a20.142 20.142 0 0 0 2.842-.473 1 1 0 0 0-.476-1.942c-.622.152-1.286.272-1.964.358.048-.208.1-.409.155-.584Zm-3.686 8.015c.166-.34.414-.697.758-1.037.02.348.053.67.098.973.083.56.207 1.048.341 1.477a3.41 3.41 0 0 1-.674.227c-.429.092-.588.019-.614.006l-.004-.001c-.162-.193-.329-.774.095-1.645Zm4.498-2.562a6.362 6.362 0 0 1-1.568 2.73 7.763 7.763 0 0 1-.095-.525 10.294 10.294 0 0 1-.088-1.904c.033-.013.067-.024.1-.036l1.651-.265Zm0 0-1.651.265c.602-.212 1.155-.29 1.651-.265ZM7.536 6.29a6.342 6.342 0 0 0-4.456.331 1 1 0 0 0 .848 1.811 4.342 4.342 0 0 1 3.049-.222c.364.107.568.248.69.37.12.123.203.27.257.454.067.225.087.446.09.69a8.195 8.195 0 0 0-.555-.117c-1.146-.199-2.733-.215-4.262.64-1.271.713-1.796 2.168-1.682 3.448.12 1.326.94 2.679 2.572 3.136 1.48.414 2.913-.045 3.877-.507l.08-.04a1 1 0 0 0 1.96-.281V10.5c0-.053.002-.12.005-.2.012-.417.034-1.16-.168-1.838a3.043 3.043 0 0 0-.755-1.29c-.394-.398-.91-.694-1.547-.881h-.003Zm-.419 5.288c.344.06.647.143.887.222v2.197a7.021 7.021 0 0 1-.905.524c-.792.38-1.682.605-2.473.384-.698-.195-1.06-.742-1.119-1.389-.062-.693.243-1.286.667-1.523.987-.553 2.06-.569 2.943-.415Z",
|
||||||
"eye-show-outline": "M12 9.005a4 4 0 1 1 0 8 4 4 0 0 1 0-8Zm0 1.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5ZM12 5.5c4.613 0 8.596 3.15 9.701 7.564a.75.75 0 1 1-1.455.365 8.503 8.503 0 0 0-16.493.004.75.75 0 0 1-1.455-.363A10.003 10.003 0 0 1 12 5.5Z",
|
"eye-show-outline": "M12 9.005a4 4 0 1 1 0 8 4 4 0 0 1 0-8Zm0 1.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5ZM12 5.5c4.613 0 8.596 3.15 9.701 7.564a.75.75 0 1 1-1.455.365 8.503 8.503 0 0 0-16.493.004.75.75 0 0 1-1.455-.363A10.003 10.003 0 0 1 12 5.5Z",
|
||||||
"eye-hide-outline": "M2.22 2.22a.75.75 0 0 0-.073.976l.073.084 4.034 4.035a9.986 9.986 0 0 0-3.955 5.75.75.75 0 0 0 1.455.364 8.49 8.49 0 0 1 3.58-5.034l1.81 1.81A4 4 0 0 0 14.8 15.86l5.919 5.92a.75.75 0 0 0 1.133-.977l-.073-.084-6.113-6.114.001-.002-1.2-1.198-2.87-2.87h.002L8.719 7.658l.001-.002-1.133-1.13L3.28 2.22a.75.75 0 0 0-1.06 0Zm7.984 9.045 3.535 3.536a2.5 2.5 0 0 1-3.535-3.535ZM12 5.5c-1 0-1.97.148-2.889.425l1.237 1.236a8.503 8.503 0 0 1 9.899 6.272.75.75 0 0 0 1.455-.363A10.003 10.003 0 0 0 12 5.5Zm.195 3.51 3.801 3.8a4.003 4.003 0 0 0-3.801-3.8Z",
|
"eye-hide-outline": "M2.22 2.22a.75.75 0 0 0-.073.976l.073.084 4.034 4.035a9.986 9.986 0 0 0-3.955 5.75.75.75 0 0 0 1.455.364 8.49 8.49 0 0 1 3.58-5.034l1.81 1.81A4 4 0 0 0 14.8 15.86l5.919 5.92a.75.75 0 0 0 1.133-.977l-.073-.084-6.113-6.114.001-.002-1.2-1.198-2.87-2.87h.002L8.719 7.658l.001-.002-1.133-1.13L3.28 2.22a.75.75 0 0 0-1.06 0Zm7.984 9.045 3.535 3.536a2.5 2.5 0 0 1-3.535-3.535ZM12 5.5c-1 0-1.97.148-2.889.425l1.237 1.236a8.503 8.503 0 0 1 9.899 6.272.75.75 0 0 0 1.455-.363A10.003 10.003 0 0 0 12 5.5Zm.195 3.51 3.801 3.8a4.003 4.003 0 0 0-3.801-3.8Z",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<span class="spinner" :class="size" />
|
<span class="spinner" :class="`${size} ${colorScheme}`" />
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
@@ -8,6 +8,10 @@ export default {
|
|||||||
type: String,
|
type: String,
|
||||||
default: 'small',
|
default: 'small',
|
||||||
},
|
},
|
||||||
|
colorScheme: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -32,8 +36,8 @@ export default {
|
|||||||
margin-top: -$space-one;
|
margin-top: -$space-one;
|
||||||
margin-left: -$space-one;
|
margin-left: -$space-one;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
border: 2px solid rgba(255, 255, 255, 0.7);
|
border: 2px solid rgba(255, 255, 255, 0.8);
|
||||||
border-top-color: rgba(255, 255, 255, 0.2);
|
border-top-color: rgba(255, 255, 255, 0.3);
|
||||||
animation: spinner 0.9s linear infinite;
|
animation: spinner 0.9s linear infinite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,5 +88,10 @@ export default {
|
|||||||
margin-top: -$space-small + $space-micro;
|
margin-top: -$space-small + $space-micro;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.dark::before {
|
||||||
|
border-color: rgba(0, 0, 0, 0.7);
|
||||||
|
border-top-color: rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
exports[`Spinner matches snapshot 1`] = `
|
exports[`Spinner matches snapshot 1`] = `
|
||||||
<span
|
<span
|
||||||
class="spinner small"
|
class="spinner small "
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -35,20 +35,48 @@ class Integrations::Openai::ProcessorService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def conversation_messages(in_array_format: false)
|
def conversation_messages(in_array_format: false)
|
||||||
conversation = hook.account.conversations.find_by(display_id: event['data']['conversation_display_id'])
|
conversation = find_conversation
|
||||||
messages = in_array_format ? [] : ''
|
messages = init_messages_body(in_array_format)
|
||||||
|
|
||||||
|
add_messages_until_token_limit(conversation, messages, in_array_format)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_conversation
|
||||||
|
hook.account.conversations.find_by(display_id: event['data']['conversation_display_id'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_messages_until_token_limit(conversation, messages, in_array_format)
|
||||||
character_count = 0
|
character_count = 0
|
||||||
|
|
||||||
conversation.messages.chat.reorder('id desc').each do |message|
|
conversation.messages.chat.reorder('id desc').each do |message|
|
||||||
character_count += message.content.length
|
character_count, message_added = add_message_if_within_limit(character_count, message, messages, in_array_format)
|
||||||
break if character_count > TOKEN_LIMIT
|
break unless message_added
|
||||||
|
|
||||||
formatted_message = format_message(message, in_array_format)
|
|
||||||
messages.prepend(formatted_message)
|
|
||||||
end
|
end
|
||||||
messages
|
messages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_message_if_within_limit(character_count, message, messages, in_array_format)
|
||||||
|
if valid_message?(message, character_count)
|
||||||
|
add_message_to_list(message, messages, in_array_format)
|
||||||
|
character_count += message.content.length
|
||||||
|
[character_count, true]
|
||||||
|
else
|
||||||
|
[character_count, false]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_message?(message, character_count)
|
||||||
|
message.content.present? && character_count + message.content.length <= TOKEN_LIMIT
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_message_to_list(message, messages, in_array_format)
|
||||||
|
formatted_message = format_message(message, in_array_format)
|
||||||
|
messages.prepend(formatted_message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def init_messages_body(in_array_format)
|
||||||
|
in_array_format ? [] : ''
|
||||||
|
end
|
||||||
|
|
||||||
def format_message(message, in_array_format)
|
def format_message(message, in_array_format)
|
||||||
in_array_format ? format_message_in_array(message) : format_message_in_string(message)
|
in_array_format ? format_message_in_array(message) : format_message_in_string(message)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user