belongsTo(WebSocketDialog::class, 'dialog_id'); } /** * @param $sessionId * @param WebSocketDialogMsg $dialogMsg * @return void */ public static function updateTitle($sessionId, $dialogMsg) { if (!$sessionId) { return; } if ($dialogMsg->type != 'text') { return; } if ($dialogMsg->msg['text'] === '...') { return; } $cacheKey = 'dialog_session_title_' . $sessionId; if (Cache::has($cacheKey)) { return; } $title = $dialogMsg->key ?: WebSocketDialogMsg::previewTextMsg($dialogMsg->msg) ?: 'Untitled'; $session = self::whereId($sessionId)->first(); if (!$session) { return; } $session->title = $title; $session->save(); Cache::forever($cacheKey, true); Task::deliver(new UpdateSessionTitleViaAiTask($session->id, $dialogMsg->msg['text'])); } }