perf: AI机器人支持多会话

This commit is contained in:
kuaifan
2025-02-10 16:48:08 +09:00
parent da0fa31181
commit 501235ef12
5 changed files with 186 additions and 14 deletions

View File

@@ -2,6 +2,9 @@
namespace App\Models;
use App\Module\Base;
use Cache;
/**
* App\Models\WebSocketDialogSession
*
@@ -48,4 +51,35 @@ class WebSocketDialogSession extends AbstractModel
{
return $this->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;
}
$cacheKey = 'dialog_session_title_' . $sessionId;
if (Cache::has($cacheKey)) {
return;
}
$session = self::whereId($sessionId)->first();
if (!$session) {
return;
}
$title = Base::cutStr($dialogMsg->key ?: $dialogMsg->msg['text'], 100);
if (empty($title)) {
return;
}
$session->title = $title;
$session->save();
// todo 通过AI生成标题
Cache::forever($cacheKey, true);
}
}