Skip to content

Commit

Permalink
improve displayed agency action names
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jan 7, 2025
1 parent b7ef307 commit 0ea4a5e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/Controller/ChattyLLMController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public function __construct(
private ?string $userId,
) {
parent::__construct($appName, $request);
$this->agencyActionNames = [

Check failure on line 48 in lib/Controller/ChattyLLMController.php

View workflow job for this annotation

GitHub Actions / Psalm check

UndefinedThisPropertyAssignment

lib/Controller/ChattyLLMController.php:48:3: UndefinedThisPropertyAssignment: Instance property OCA\Assistant\Controller\ChattyLLMController::$agencyActionNames is not defined (see https://psalm.dev/040)
'send_message_to_conversation' => $this->l10n->t('Send a message to a Talk conversation'),
'list_talk_conversations' => $this->l10n->t('List Talk conversations'),
'list_messages_in_conversation' => $this->l10n->t('List messages in a Talk conversation'),
'schedule_event' => $this->l10n->t('Schedule a calendar event'),
'list_calendars' => $this->l10n->t('List calendars'),
];
}

private function improveAgencyActionNames(array $actions): array {
return array_map(function ($action) {
if (isset($action->name) && isset($this->agencyActionNames[$action->name])) {
$action->name = $this->agencyActionNames[$action->name];
}
return $action;
}, $actions);
}

/**
Expand Down Expand Up @@ -408,6 +424,7 @@ public function checkMessageGenerationTask(int $taskId, int $sessionId): JSONRes
$jsonMessage['sessionAgencyPendingActions'] = $session->getAgencyPendingActions();
if ($jsonMessage['sessionAgencyPendingActions'] !== null) {
$jsonMessage['sessionAgencyPendingActions'] = json_decode($jsonMessage['sessionAgencyPendingActions']);
$jsonMessage['sessionAgencyPendingActions'] = $this->improveAgencyActionNames($jsonMessage['sessionAgencyPendingActions']);
}
// do not insert here, it is done by the listener
return new JSONResponse($jsonMessage);
Expand Down Expand Up @@ -462,6 +479,7 @@ public function checkSession(int $sessionId): JSONResponse {
$pendingActions = $session->getAgencyPendingActions();
if ($pendingActions !== null) {
$pendingActions = json_decode($pendingActions);
$pendingActions = $this->improveAgencyActionNames($pendingActions);
}
$responseData = [
'messageTaskId' => null,
Expand Down

0 comments on commit 0ea4a5e

Please sign in to comment.