add user context in memory

This commit is contained in:
Thommy Bucaille 2023-12-22 02:06:33 +01:00
parent b4bc5d8332
commit 297b8c2a70
2 changed files with 10 additions and 2 deletions

View File

@ -847,7 +847,8 @@ class ChatController extends BaseController
private function add_memory($keywords, $content)
{
try {
$res = Memory::add($keywords, $content);
$user = (!Helper::isCLI() && Auth::check()) ? Auth::user() : null;
$res = Memory::add($keywords, $content, $user);
if ($res) {
return 'The memory data has been successfully added.';

View File

@ -7,13 +7,14 @@ class Memory extends BaseModel {
protected $version = '1.0.0';
public static function add(array $keywords, string $content) {
public static function add(array $keywords, string $content, $user = null) {
$keywords = implode(',', $keywords);
$content = strtolower($content);
$memory = new self();
$memory->keywords = $keywords;
$memory->content = $content;
$memory->user = $user;
$memory->save();
return $memory;
@ -51,6 +52,12 @@ class Memory extends BaseModel {
'type' => 'text',
'null' => false
],
[
'name' => 'user',
'type' => 'varchar',
'length' => 255,
'null' => true,
],
]);
parent::install($fields);