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'));
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);
}
}