-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix polling when switching sessions in the frontend, prevent scheduli…
…ng multiple llm tasks for one session Signed-off-by: Julien Veyssier <[email protected]>
- Loading branch information
Showing
6 changed files
with
178 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Assistant\Listener; | ||
|
||
use OCA\Assistant\AppInfo\Application; | ||
use OCA\Assistant\Db\ChattyLLM\Message; | ||
use OCA\Assistant\Db\ChattyLLM\MessageMapper; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\TaskProcessing\Events\TaskSuccessfulEvent; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @template-implements IEventListener<TaskSuccessfulEvent> | ||
*/ | ||
class ChattyLLMTaskListener implements IEventListener { | ||
|
||
public function __construct( | ||
private MessageMapper $messageMapper, | ||
private LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof TaskSuccessfulEvent)) { | ||
return; | ||
} | ||
|
||
$task = $event->getTask(); | ||
$customId = $task->getCustomId(); | ||
$appId = $task->getAppId(); | ||
if ($appId !== (Application::APP_ID . ':chatty-llm') | ||
|| $customId === null | ||
|| !preg_match('/^chatty-llm:(\d+)$/', $customId, $matches) | ||
) { | ||
return; | ||
} | ||
$sessionId = (int)$matches[1]; | ||
|
||
$message = new Message(); | ||
$message->setSessionId($sessionId); | ||
$message->setRole('assistant'); | ||
$message->setContent(trim($task->getOutput()['output'] ?? '')); | ||
$message->setTimestamp(time()); | ||
try { | ||
$this->messageMapper->insert($message); | ||
} catch (\OCP\DB\Exception $e) { | ||
$this->logger->error('Message insertion error in chattyllm task listener', ['exception' => $e]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters