add user context in memory
This commit is contained in:
parent
b4bc5d8332
commit
297b8c2a70
|
@ -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.';
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue