1. Go to this page and download the library: Download rmh/laravel-openui 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/ */
rmh / laravel-openui example snippets
// app/Providers/AppServiceProvider.php
use RMH\OpenUI\Middleware\InjectOpenUIPrompt;
use Laravel\Ai\Facades\Ai;
public function boot(): void
{
Ai::middleware([InjectOpenUIPrompt::class]);
}
Route::post('/chat', function (Request $request) {
return MyAgent::make()
->stream($request->input('message'))
->usingVercelDataProtocol();
});
use RMH\OpenUI\Concerns\GeneratesUI;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Promptable;
class HotelSearchAgent implements Agent
{
use Promptable, GeneratesUI;
protected function agentInstructions(): string
{
return 'You are a helpful hotel search assistant.';
}
}
// UI enabled (default)
HotelSearchAgent::make()->prompt('Find hotels in Paris');
// UI disabled for this call
HotelSearchAgent::make()->withoutUI()->prompt('Find hotels in Paris');
use RMH\OpenUI\Middleware\InjectOpenUIPrompt;
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasMiddleware;
use Laravel\Ai\Promptable;
class HotelSearchAgent implements Agent, HasMiddleware
{
use Promptable;
public function instructions(): string
{
return 'You are a helpful hotel search assistant.';
}
public function middleware(): array
{
return [new InjectOpenUIPrompt];
}
}
use RMH\OpenUI\Facades\OpenUI;
use function Laravel\Ai\{agent};
$response = agent(
instructions: 'You are a travel assistant.' . "\n\n" . OpenUI::systemPrompt(),
)->prompt('Find hotels in Paris');
use RMH\OpenUI\Facades\OpenUI;
// Register one component
OpenUI::component('PriceTag', [
'amount' => 'string',
'currency' => 'string?',
]);
// Register many at once
OpenUI::library([
'Chart' => ['type' => 'enum:bar|line|pie', 'data' => 'array'],
'MapPin' => ['lat' => 'float', 'lng' => 'float', 'label' => 'string?'],
]);
use RMH\OpenUI\Facades\OpenUI;
use App\Ai\OpenUI\Components\CardComponent;
OpenUI::component((new CardComponent)->name(), (new CardComponent)->props());