Skip to content

Commit

Permalink
fixup! feat: request tasks and show summary
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Nov 22, 2024
1 parent 74543f5 commit b1f5b93
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ import { useSettingsStore } from '../../stores/settings.js'
import { fetchClipboardContent } from '../../utils/clipboard.js'
import { parseSpecialSymbols } from '../../utils/textParse.ts'

const canSummarizeChat = hasTalkFeature('local', 'chat-summary-api')

export default {
name: 'NewMessage',

Expand Down Expand Up @@ -473,7 +471,7 @@ export default {
},

showChatSummary() {
return canSummarizeChat && this.chatExtrasStore.hasChatSummaryTaskRequested(this.token)
return this.chatExtrasStore.hasChatSummaryTaskRequested(this.token)
},

isMobileDevice() {
Expand Down
8 changes: 6 additions & 2 deletions src/components/NewMessage/NewMessageChatSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import IconChevronUp from 'vue-material-design-icons/ChevronUp.vue'
import IconMessageBulleted from 'vue-material-design-icons/MessageBulleted.vue'

import { showError } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand Down Expand Up @@ -116,6 +117,8 @@ watch(token, (newValue, oldValue) => {
getTaskInterval = undefined
}
if (newValue) {
loading.value = true
chatSummaryMessage.value = ''
checkScheduledTasks(newValue)
}
}, { immediate: true })
Expand Down Expand Up @@ -163,7 +166,7 @@ async function getTask(token: string, request: TaskProcessingCancelableRequest['
switch (status) {
case TASK_PROCESSING.STATUS.SUCCESSFUL: {
// Task is completed, proceed to the next task
const summary = response.data.ocs.data.task.output?.output ?? t('spreed', 'Empty summary response')
const summary = response.data.ocs.data.task.output?.output || ''
chatExtrasStore.storeChatSummary(token, task.fromMessageId, summary)
clearInterval(getTaskInterval)
getTaskInterval = undefined
Expand All @@ -174,7 +177,8 @@ async function getTask(token: string, request: TaskProcessingCancelableRequest['
case TASK_PROCESSING.STATUS.UNKNOWN:
case TASK_PROCESSING.STATUS.CANCELLED: {
// Task is likely failed, proceed to the next task
chatExtrasStore.storeChatSummary(token, task.fromMessageId, t('spreed', 'Generating of summary failed'))
chatExtrasStore.storeChatSummary(token, task.fromMessageId, t('spreed', 'Error occurred during a summary generation'))
showError(t('spreed', 'Error occurred during a summary generation'))
clearInterval(getTaskInterval)
getTaskInterval = undefined
checkScheduledTasks(token)
Expand Down
2 changes: 1 addition & 1 deletion src/stores/chatExtras.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const useChatExtrasStore = defineStore('chatExtras', {

getChatSummary: (state) => (token) => {
return Object.values(Object(state.chatSummary[token])).map(task => task.summary).join('\n\n')
|| t('spreed', 'Empty summary response')
|| t('spreed', 'Error occurred during a summary generation')
},
},

Expand Down

0 comments on commit b1f5b93

Please sign in to comment.