PHP code example of sharifuddin / laravel-ai-bridge
1. Go to this page and download the library: Download sharifuddin/laravel-ai-bridge 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/ */
namespace App\AiTools;
use Sharifuddin\LaravelAiBridge\Execution\ExecutionContext;
use Sharifuddin\LaravelAiBridge\Tools\AbstractTool;
class ListUsersTool extends AbstractTool
{
public function name(): string { return 'list_users'; }
public function category(): string { return 'users'; }
public function description(): string
{
return 'List application users with pagination, search, status filtering and role filtering.';
}
public function parametersSchema(): array
{
return [
'search' => ['type' => 'string', 'Service::class)->list($arguments, $context);
}
}
use Sharifuddin\LaravelAiBridge\Facades\AI;
AI::tool(\App\AiTools\ListUsersTool::class);
namespace App\AiTools;
use Sharifuddin\LaravelAiBridge\Execution\ExecutionContext;
use Sharifuddin\LaravelAiBridge\Tools\AbstractTool;
class WeatherTool extends AbstractTool
{
public function name(): string
{
return 'get_weather';
}
public function category(): string
{
return 'weather';
}
public function description(): string
{
return 'Get the current weather for a city using the app weather service.';
}
public function parametersSchema(): array
{
return [
'city' => [
'type' => 'string',
' 'action' => 'lookup',
];
}
public function execute(array $arguments, ExecutionContext $context): mixed
{
$city = $arguments['city'];
$unit = $arguments['unit'] ?? 'celsius';
return app(\App\Services\WeatherService::class)->getForCity($city, $unit);
}
}
'tools' => [
\App\AiTools\WeatherTool::class,
],
use Sharifuddin\LaravelAiBridge\Facades\AI;
AI::tool(\App\AiTools\WeatherTool::class);