PHP code example of mappweb / laravel-neuron-ai

1. Go to this page and download the library: Download mappweb/laravel-neuron-ai 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/ */

    

mappweb / laravel-neuron-ai example snippets




declare(strict_types=1);

namespace App\Agents;

use NeuronAI\Agent;
use NeuronAI\Providers\AIProviderInterface;
use NeuronAI\Providers\OpenAIProvider;

class ChatAgent extends Agent
{
    public function provider(): AIProviderInterface
    {
        return OpenAIProvider::make();
    }

    public function instructions(): string
    {
        return 'You are a helpful AI assistant.';
    }
}



namespace App\Http\Controllers;

use App\Agents\ChatAgent;
use Illuminate\Http\Request;

class ChatController extends Controller
{
    public function chat(Request $request)
    {
        $agent = new ChatAgent();
        
        $response = $agent->chat($request->input('message'));
        
        return response()->json([
            'response' => $response
        ]);
    }
}

use Mappweb\LaravelNeuronAi\Facades\NeuronAI;

// Basic usage
$agent = NeuronAI::make()
    ->provider(OpenAIProvider::make())
    ->instructions('You are a helpful assistant');

$response = $agent->chat('Hello!');

// With configuration from config
$agent = NeuronAI::make()
    ->provider(config('neuron-ai.default_provider'))
    ->instructions(config('neuron-ai.agents.default_instructions'));

return [
    // Default provider
    'default_provider' => env('NEURON_AI_DEFAULT_PROVIDER', 'openai'),
    
    // Providers configuration
    'providers' => [
        'openai' => [
            'api_key' => env('OPENAI_API_KEY'),
            'model' => env('OPENAI_MODEL', 'gpt-4'),
            'max_tokens' => env('OPENAI_MAX_TOKENS', 2048),
            'temperature' => env('OPENAI_TEMPERATURE', 0.7),
        ],
        // ... other providers
    ],
    
    // Agents configuration
    'agents' => [
        'default_instructions' => env('NEURON_AI_DEFAULT_INSTRUCTIONS', 'You are a helpful AI assistant.'),
        'default_namespace' => 'App\\Agents',
        'timeout' => env('NEURON_AI_TIMEOUT', 30),
    ],
    
    // Logging and cache
    'logging' => [
        'enabled' => env('NEURON_AI_LOGGING_ENABLED', true),
        'channel' => env('NEURON_AI_LOG_CHANNEL', 'default'),
    ],
    
    'cache' => [
        'enabled' => env('NEURON_AI_CACHE_ENABLED', false),
        'ttl' => env('NEURON_AI_CACHE_TTL', 3600),
    ],
];



declare(strict_types=1);

namespace App\Agents\Prompts;

use Mappweb\LaravelNeuronAi\Prompts\PromptInterface;

class BlogPrompt implements PromptInterface
{
    public function __construct(
        public string $topic = 'Technology',
        public int $wordCount = 500,
        public array $keywords = [],
    ) {
        //
    }

    public function __toString(): string
    {
        return "Write a {$this->wordCount}-word blog post about {$this->topic}. Include keywords: " . implode(', ', $this->keywords);
    }
}
bash
# Basic prompt
php artisan make:prompt ChatPrompt

# Complete prompt
php artisan make:prompt GreetingPrompt --content="Hello! I'm {$this->name}, your assistant."

# Prompt with custom path
php artisan make:prompt CustomPrompt --path="Custom\\Prompts"