Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Controller/ChattyLLMController.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,13 @@ public function regenerateForSession(int $sessionId, int $messageId): JSONRespon
}

/**
* Check the status of a generation task
* Check the status of a generation task. The value of slow_pickup will be set to true if the task is not being picked up.
*
* Used by the frontend to poll a generation task status. If the task succeeds, a new message is stored and returned.
*
* @param int $taskId The message generation task ID
* @param int $sessionId The chat session ID
* @return JSONResponse<Http::STATUS_OK, AssistantChatAgencyMessage, array{}>|JSONResponse<Http::STATUS_EXPECTATION_FAILED, array{task_status: int}, array{}>|JSONResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_UNAUTHORIZED|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{error: string}, array{}>
* @return JSONResponse<Http::STATUS_OK, AssistantChatAgencyMessage, array{}>|JSONResponse<Http::STATUS_EXPECTATION_FAILED, array{task_status: int, slow_pickup: bool}, array{}>|JSONResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_UNAUTHORIZED|Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{error: string}, array{}>
Comment thread
lukasdotcom marked this conversation as resolved.
* @throws MultipleObjectsReturnedException
* @throws \OCP\DB\Exception
*
Expand Down Expand Up @@ -710,7 +710,9 @@ public function checkMessageGenerationTask(int $taskId, int $sessionId): JSONRes
return new JSONResponse(['task_status' => $task->getstatus()], Http::STATUS_EXPECTATION_FAILED);
}
} elseif ($task->getstatus() === Task::STATUS_RUNNING || $task->getstatus() === Task::STATUS_SCHEDULED) {
return new JSONResponse(['task_status' => $task->getstatus()], Http::STATUS_EXPECTATION_FAILED);
$startTime = $task->getStartedAt() ?? time();
$slowPickup = ($task->getScheduledAt() + (60 * 5)) < $startTime;
return new JSONResponse(['task_status' => $task->getstatus(), 'slow_pickup' => $slowPickup], Http::STATUS_EXPECTATION_FAILED);
} elseif ($task->getstatus() === Task::STATUS_FAILED || $task->getstatus() === Task::STATUS_CANCELLED) {
return new JSONResponse(['error' => 'task_failed_or_canceled', 'task_status' => $task->getstatus()], Http::STATUS_BAD_REQUEST);
}
Expand Down
8 changes: 6 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@
"/ocs/v2.php/apps/assistant/chat/check_generation": {
"get": {
"operationId": "chattyllm-check-message-generation-task",
"summary": "Check the status of a generation task",
"summary": "Check the status of a generation task. The value of slow_pickup will be set to true if the task is not being picked up.",
"description": "Used by the frontend to poll a generation task status. If the task succeeds, a new message is stored and returned.",
"tags": [
"chat_api"
Expand Down Expand Up @@ -3607,12 +3607,16 @@
"schema": {
"type": "object",
"required": [
"task_status"
"task_status",
"slow_pickup"
],
"properties": {
"task_status": {
"type": "integer",
"format": "int64"
},
"slow_pickup": {
"type": "boolean"
}
}
}
Expand Down
31 changes: 23 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
"@nextcloud/event-bus": "^3.1.0",
"@nextcloud/files": "^3.11.0",
"@nextcloud/initial-state": "^2.0.0",
"@nextcloud/l10n": "^3.1.0",
"@nextcloud/l10n": "~3.3.0",
"@nextcloud/moment": "^1.3.1",
"@nextcloud/router": "^3.0.0",
"@nextcloud/vue": "^9.0.0-rc.2",
"@nextcloud/vue": "^9.0.0-rc.5",
"extendable-media-recorder": "^9.2.11",
"extendable-media-recorder-wav-encoder": "^7.0.129",
"moment": "^2.30.1",
Expand Down
36 changes: 18 additions & 18 deletions src/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ export async function openAssistantForm({
lastTask = task
view.selectedTaskId = lastTask?.id
view.expectedRuntime = (lastTask?.completionExpectedAt - lastTask?.scheduledAt) || null
const setProgress = (progress) => {
view.progress = progress
}
pollTask(task.id, setProgress).then(finishedTask => {

pollTask(task.id, view).then(finishedTask => {
console.debug('pollTask.then', finishedTask)
if (finishedTask.status === TASK_STATUS_STRING.successful) {
if (closeOnResult) {
Expand All @@ -139,7 +137,7 @@ export async function openAssistantForm({
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
showError(
t('assistant', 'The server failed to process your task with ID {id}', { id: finishedTask.id })
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
)
console.error('[assistant] Task failed', finishedTask)
view.outputs = null
Expand Down Expand Up @@ -215,18 +213,15 @@ export async function openAssistantForm({
view.progress = null
view.expectedRuntime = (updatedTask?.completionExpectedAt - updatedTask?.scheduledAt) || null

const setProgress = (progress) => {
view.progress = progress
}
pollTask(updatedTask.id, setProgress).then(finishedTask => {
pollTask(updatedTask.id, view).then(finishedTask => {
console.debug('pollTask.then', finishedTask)
if (finishedTask.status === TASK_STATUS_STRING.successful) {
view.outputs = finishedTask?.output
view.selectedTaskId = finishedTask?.id
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
showError(
t('assistant', 'The server failed to process your task with ID {id}', { id: finishedTask.id })
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
+ '. ' + t('assistant', 'Please inform the server administrators of this issue.'),
)
console.error('[assistant] Task failed', finishedTask)
view.outputs = null
Expand Down Expand Up @@ -287,7 +282,15 @@ export async function openAssistantForm({
})
}

export async function pollTask(taskId, setProgress) {
function updateTask(task, object) {
if (task?.status === TASK_STATUS_STRING.running) {
object.progress = task?.progress * 100
}
object.taskStatus = task?.status
object.scheduledAt = task?.scheduledAt
}

export async function pollTask(taskId, obj, callback = updateTask) {
return new Promise((resolve, reject) => {
window.assistantPollTimerId = setInterval(() => {
getTask(taskId).then(response => {
Expand All @@ -296,8 +299,8 @@ export async function pollTask(taskId, setProgress) {
reject(new Error('pollTask cancelled'))
return
}
if (task?.status === TASK_STATUS_STRING.running) {
setProgress(task?.progress * 100)
if (obj) {
callback(task, obj)
}
if (![TASK_STATUS_STRING.scheduled, TASK_STATUS_STRING.running].includes(task?.status)) {
// stop polling
Expand Down Expand Up @@ -548,7 +551,7 @@ export async function openAssistantTask(
lastTask = task
view.selectedTaskId = lastTask?.id
view.expectedRuntime = (lastTask?.completionExpectedAt - lastTask?.scheduledAt) || null
pollTask(task.id).then(finishedTask => {
pollTask(task.id, view).then(finishedTask => {
if (finishedTask.status === TASK_STATUS_STRING.successful) {
view.outputs = finishedTask?.output
} else if (finishedTask.status === TASK_STATUS_STRING.failed) {
Expand Down Expand Up @@ -627,10 +630,7 @@ export async function openAssistantTask(
view.progress = null
view.expectedRuntime = (updatedTask?.completionExpectedAt - updatedTask?.scheduledAt) || null

const setProgress = (progress) => {
view.progress = progress
}
pollTask(updatedTask.id, setProgress).then(finishedTask => {
pollTask(updatedTask.id, view).then(finishedTask => {
console.debug('pollTask.then', finishedTask)
if (finishedTask.status === TASK_STATUS_STRING.successful) {
view.outputs = finishedTask?.output
Expand Down
10 changes: 10 additions & 0 deletions src/components/AssistantTextProcessingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
:progress="progress"
:expected-runtime="expectedRuntime"
:is-notify-enabled="isNotifyEnabled"
:task-status="taskStatus"
:scheduled-at="scheduledAt"
@background-notify="$emit('background-notify', $event)"
@cancel="$emit('cancel-task')" />
<NcAppContent v-else class="session-area">
Expand Down Expand Up @@ -238,6 +240,14 @@ export default {
type: [Array, null],
default: null,
},
taskStatus: {
type: [String, null],
default: null,
},
scheduledAt: {
type: [Number, null],
default: null,
},
},
emits: [
'sync-submit',
Expand Down
4 changes: 4 additions & 0 deletions src/components/AssistantTextProcessingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
:expected-runtime="expectedRuntime"
:is-notify-enabled="isNotifyEnabled"
:task-type-id-list="taskTypeIdList"
:task-status="taskStatus"
:scheduled-at="scheduledAt"
@sync-submit="onSyncSubmit"
@action-button-clicked="onActionButtonClicked"
@try-again="onTryAgain"
Expand Down Expand Up @@ -117,6 +119,8 @@ export default {
closeButtonLabel: t('assistant', 'Close Nextcloud Assistant'),
modalSize: 'large',
progress: null,
taskStatus: null,
scheduledAt: null,
loading: false,
expectedRuntime: null,
isNotifyEnabled: false,
Expand Down
4 changes: 4 additions & 0 deletions src/components/ChattyLLM/ChattyLLMInputForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
</div>
<ConversationBox :messages="messages"
:loading="loading"
:slow-pickup="slowPickup"
@regenerate="runRegenerationTask"
@delete="deleteMessage" />
<div v-if="messages != null && messages.length > 0 && !loading.llmGeneration && !loading.newHumanMessage && messages[messages.length - 1]?.role === 'human'" class="session-area__chat-area__active-session__utility-button">
Expand Down Expand Up @@ -252,6 +253,7 @@
pollMessageGenerationTimerId: null,
pollTitleGenerationTimerId: null,
autoplayAudioChat: loadState('assistant', 'autoplay_audio_chat', true),
slowPickup: false,
}
},

Expand Down Expand Up @@ -586,7 +588,7 @@
this.loading.initialMessages = false
this.messagesAxiosController = null
} catch (error) {
if (axios.isCancel(error)) {

Check warning on line 591 in src/components/ChattyLLM/ChattyLLMInputForm.vue

View workflow job for this annotation

GitHub Actions / NPM build

Caution: `axios` also has a named export `isCancel`. Check if you meant to write `import {isCancel} from '@nextcloud/axios'` instead

Check warning on line 591 in src/components/ChattyLLM/ChattyLLMInputForm.vue

View workflow job for this annotation

GitHub Actions / NPM build

Caution: `axios` also has a named export `isCancel`. Check if you meant to write `import {isCancel} from '@nextcloud/axios'` instead

Check warning on line 591 in src/components/ChattyLLM/ChattyLLMInputForm.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Caution: `axios` also has a named export `isCancel`. Check if you meant to write `import {isCancel} from '@nextcloud/axios'` instead
console.debug('fetchMessages cancelled')
return
}
Expand Down Expand Up @@ -665,6 +667,7 @@

async runGenerationTask(sessionId, agencyConfirm = null) {
try {
this.slowPickup = false
this.loading.llmGeneration = true
const params = {
sessionId,
Expand Down Expand Up @@ -748,6 +751,7 @@
reject(new Error('Message generation task check failed'))
} else {
console.debug('checkTaskPolling, task is still scheduled or running')
this.slowPickup = error.response.data.slow_pickup
}
})
}, 2000)
Expand Down
6 changes: 5 additions & 1 deletion src/components/ChattyLLM/ConversationBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
:information-source-names="informationSourceNames"
@regenerate="regenerate(message.id)"
@delete="deleteMessage(message.id)" />
<LoadingPlaceholder v-if="loading.llmGeneration" />
<LoadingPlaceholder v-if="loading.llmGeneration" :slow-pickup="slowPickup" />
</div>
</div>
</template>
Expand Down Expand Up @@ -79,6 +79,10 @@ export default {
sessionDelete: false,
}),
},
slowPickup: {
type: Boolean,
default: false,
},
},

emits: ['delete', 'regenerate'],
Expand Down
15 changes: 15 additions & 0 deletions src/components/ChattyLLM/LoadingPlaceholder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@
</div>
<div v-if="type === 'messages'" class="placeholder-item__info" />
</li>
<NcNoteCard
v-if="slowPickup"
type="warning">
{{ t('assistant', 'This chat response is taking longer to start generating than expected. Please contact your administrator to ensure that Assistant is correctly configured.') }}
</NcNoteCard>
</ul>
</template>

<script>
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'

const AVATAR = {
SIZE: {
EXTRA_SMALL: 22,
Expand All @@ -34,6 +41,10 @@ const AVATAR = {
export default {
name: 'LoadingPlaceholder',

components: {
NcNoteCard,
},

props: {
type: {
type: String,
Expand All @@ -46,6 +57,10 @@ export default {
type: Number,
default: 1,
},
slowPickup: {
type: Boolean,
default: false,
},
},

computed: {
Expand Down
Loading
Loading