PHP code example of gridwb / laravel-mem0

1. Go to this page and download the library: Download gridwb/laravel-mem0 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gridwb / laravel-mem0 example snippets


use Gridwb\LaravelMem0\Facades\Mem0;

$data = [
    'user_id'  => 'alex',
    'messages' => [
        [
            'role'    => 'user',
            'content' => '<user-message>'
        ],
        [
            'role'    => 'assistant',
            'content' => '<assistant-message>'
        ]
    ]
];

$result = Mem0::memories()->addAsync($data);
$result = Mem0::memories()->addSync($data);

$result = Mem0::memories()->search([
    'query'   => 'What do you know about me?',
    'filters' => [
        'OR' => [
            [
                'user_id' => 'alex',
            ],
            [
                'agent_id' => [
                    'in' => [
                        'travel-assistant',
                        'customer-support'
                    ]
                ]
            ]
        ]
    ]
]);
bash
    php artisan vendor:publish --tag="mem0-config"
    
bash
    MEM0_API_URL=https://api.mem0.ai
    MEM0_API_KEY=your-api-key-here