PHP code example of use-the-fork / synapse

1. Go to this page and download the library: Download use-the-fork/synapse 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/ */

    

use-the-fork / synapse example snippets


   //config/app.php
   'providers' => [
       ...
       UseTheFork\Synapse\SynapseServiceProvider::class,
       ...
   ];
   

   //bootstrap/providers.php
   
   return [
       App\Providers\AppServiceProvider::class,
       UseTheFork\Synapse\SynapseServiceProvider::class,
   ];
   



use UseTheFork\Synapse\Agent;
use UseTheFork\Synapse\Integrations\OpenAIIntegration;
use UseTheFork\Synapse\Memory\CollectionMemory;
use UseTheFork\Synapse\Contracts\Agent\HasMemory;
use UseTheFork\Synapse\Contracts\Integration;
use UseTheFork\Synapse\Contracts\Memory;

class SimpleAgent extends Agent implements HasMemory
{
    protected string $promptView = 'synapse::Prompts.SimplePrompt';

    public function resolveIntegration(): Integration
    {
        return new OpenAIIntegration();
    }

    public function resolveMemory(): Memory
    {
        return new CollectionMemory();
    }
}

public function resolveMemory(): Memory
{
    return new DatabaseMemory(123);  // Use a specific memory ID
}

public function resolveIntegration(): Integration
{
    return new OpenAIIntegration();
}
bash
   php artisan synapse:install