Skip to content

Commit

Permalink
cs:fix, fix psalm issues
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jul 9, 2024
1 parent 555f9d2 commit 2c52e3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
20 changes: 9 additions & 11 deletions lib/Controller/ChattyLLMController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OCA\Assistant\Controller;

use Exception;
use OCA\Assistant\AppInfo\Application;
use OCA\Assistant\Db\ChattyLLM\Message;
use OCA\Assistant\Db\ChattyLLM\MessageMapper;
Expand All @@ -19,6 +18,7 @@
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\TaskProcessing\Exception\Exception;
use OCP\TaskProcessing\Exception\NotFoundException;
use OCP\TaskProcessing\Exception\PreConditionNotMetException;
use OCP\TaskProcessing\Exception\UnauthorizedException;
Expand Down Expand Up @@ -379,9 +379,9 @@ public function checkMessageGenerationTask(int $taskId, int $sessionId): JSONRes
$this->logger->warning('Failed to add a chat message into DB', ['exception' => $e]);
return new JSONResponse(['error' => $this->l10n->t('Failed to add a chat message into DB')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
} else if ($task->getstatus() === Task::STATUS_RUNNING || $task->getstatus() === Task::STATUS_SCHEDULED) {
} elseif ($task->getstatus() === Task::STATUS_RUNNING || $task->getstatus() === Task::STATUS_SCHEDULED) {
return new JSONResponse(['task_status' => $task->getstatus()], Http::STATUS_EXPECTATION_FAILED);
} else if ($task->getstatus() === Task::STATUS_FAILED || $task->getstatus() === Task::STATUS_CANCELLED) {
} 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);
}
return new JSONResponse(['error' => 'unknown_error', 'task_status' => $task->getstatus()], Http::STATUS_BAD_REQUEST);
Expand All @@ -402,8 +402,7 @@ public function checkMessageGenerationTask(int $taskId, int $sessionId): JSONRes
* @throws \OCP\TaskProcessing\Exception\Exception
*/
#[NoAdminRequired]
public function generateTitle(int $sessionId): JSONResponse
{
public function generateTitle(int $sessionId): JSONResponse {
if ($this->userId === null) {
return new JSONResponse(['error' => $this->l10n->t('User not logged in')], Http::STATUS_UNAUTHORIZED);
}
Expand Down Expand Up @@ -482,9 +481,9 @@ public function checkTitleGenerationTask(int $taskId, int $sessionId): JSONRespo
$this->logger->warning('Failed to generate a title for the chat session', ['exception' => $e]);
return new JSONResponse(['error' => $this->l10n->t('Failed to generate a title for the chat session')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
} else if ($task->getstatus() === Task::STATUS_RUNNING || $task->getstatus() === Task::STATUS_SCHEDULED) {
} elseif ($task->getstatus() === Task::STATUS_RUNNING || $task->getstatus() === Task::STATUS_SCHEDULED) {
return new JSONResponse(['task_status' => $task->getstatus()], Http::STATUS_EXPECTATION_FAILED);
} else if ($task->getstatus() === Task::STATUS_FAILED || $task->getstatus() === Task::STATUS_CANCELLED) {
} 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);
}
return new JSONResponse(['error' => 'unknown_error', 'task_status' => $task->getstatus()], Http::STATUS_BAD_REQUEST);
Expand Down Expand Up @@ -524,14 +523,13 @@ private function getStichedMessages(int $sessionId): string {
* Schedule the LLM task
*
* @param string $content
* @return string
* @throws \OCP\TaskProcessing\Exception\Exception
* @throws NotFoundException
* @return int|null
* @throws Exception
* @throws PreConditionNotMetException
* @throws UnauthorizedException
* @throws ValidationException
*/
private function scheduleLLMTask(string $content): string {
private function scheduleLLMTask(string $content): ?int {
$task = new Task(TextToText::ID, ['input' => $content], Application::APP_ID . ':chatty-llm', $this->userId);
$this->taskProcessingManager->scheduleTask($task);
return $task->getId();
Expand Down
6 changes: 3 additions & 3 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</file>
<file src="lib/Controller/ChattyLLMController.php">
<TooManyArguments>
<code><![CDATA[new Task(TextToText::ID, ['input' => $content], Application::APP_ID, $this->userId, 'chatty-llm')]]></code>
<code><![CDATA[new Task(TextToText::ID, ['input' => $content], Application::APP_ID . ':chatty-llm', $this->userId)]]></code>
</TooManyArguments>
</file>
<file src="lib/Service/AssistantService.php">
Expand All @@ -24,10 +24,10 @@
<code><![CDATA[array<AssistantTaskProcessingTaskType>]]></code>
</MoreSpecificReturnType>
<RedundantCondition>
<code><![CDATA[self::DEBUG]]></code>
<code><![CDATA[!self::DEBUG]]></code>
</RedundantCondition>
<TypeDoesNotContainType>
<code><![CDATA[!self::DEBUG]]></code>
<code><![CDATA[self::DEBUG]]></code>
</TypeDoesNotContainType>
</file>
</files>

0 comments on commit 2c52e3b

Please sign in to comment.