PHP code example of m-tech-stack / laravel-ai-engine
1. Go to this page and download the library: Download m-tech-stack/laravel-ai-engine 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/ */
m-tech-stack / laravel-ai-engine example snippets
'assistant' => [
'model_routes' => [
'routes' => [
'orchestration' => [
'engine' => 'openai',
'model' => 'gpt-4o',
'fallback_engine' => 'openai',
'fallback_model' => 'gpt-4o-mini',
'' => 'vector',
'vector' => ['collection' => 'ai_assistant_scoped_knowledge'],
],
],
use LaravelAIEngine\DTOs\StructuredCollectionDefinition;
$collection = StructuredCollectionDefinition::make('lead_capture')
->addText('name', �دئ']],
['value' => 'advanced', 'labels' => ['en' => 'Advanced', 'ar' => 'متقدم']],
])
->addTextarea('notes')
->withPreview('html')
->confirmBeforeComplete()
->closeOnComplete()
->callbackUrl('https://app.test/api/ai/lead-callback');
use LaravelAIEngine\Contracts\AgentCapabilityProvider;
use LaravelAIEngine\DTOs\AgentCapabilityDocument;
class BusinessCapabilityProvider implements AgentCapabilityProvider
{
public function capabilities(): iterable
{
yield new AgentCapabilityDocument(
id: 'business_action:create_invoice',
text: 'Create invoice. Requires customer, invoice date, due date, and line items. Use prepare then execute after confirmation.',
payload: [
'type' => 'agent_capability',
'capability_type' => 'business_action',
'action_id' => 'create_invoice',
'tools' => ['prepare_business_action', 'execute_business_action'],
],
metadata: [
'model_class' => 'agent_capability',
'model_id' => 'business_action:create_invoice',
]
);
}
}
'capability_providers' => [
'business' => \App\AI\Capabilities\BusinessCapabilityProvider::class,
],
'business_actions' => [
'create_invoice' => [
'module' => 'sales',
'operation' => 'create',
'teInvoiceAction::class, 'execute'],
],
],
'business_action_providers' => [
\App\AI\Actions\SalesActionProvider::class,
],
'business_action_relation_resolvers' => [
\App\AI\Actions\BusinessRelationResolver::class,
],
'generic_module_actions' => [
'project_task' => [
'module' => 'projects',
'label' => 'project task',
'class' => \App\Models\ProjectTask::class,
'actions' => ['create', 'update'],
'permissions' => ['create' => 'manage-ai-agent', 'update' => 'manage-ai-agent'],
'lookup' => ['id', 'title'],
'create_ 'class' => \App\Models\Project::class,
'lookup' => ['project_name' => 'name'],
],
],
],
],
'generic_module_actions_ownership' => [
'owner_fields' => ['created_by', 'creator_id', 'owner_id', 'user_id'],
'owner_id_resolver' => fn ($actor) => $actor->tenant_owner_id ?? $actor->id,
],
use LaravelAIEngine\DTOs\UnifiedActionContext;
'handler' => function (array $params, UnifiedActionContext $context): array {
return app(\App\Services\AI\DraftService::class)->patch(
sessionId: $context->sessionId,
userId: (int) $context->userId,
patch: (array) ($params['payload_patch'] ?? [])
);
},
Engine::learn()
->fromDesignSlug('bmw-m')
->scope(workspaceId: $workspaceId)
->index()
->save();
$matches = Engine::learn()->search('design a premium automotive landing page', [
'workspace_id' => $workspaceId,
], type: 'design');
$preview = Engine::learn()->generateDesign('Create a billing dashboard with invoice review and AI chat actions.', [
'scope' => ['workspace_id' => $workspaceId],
'format' => 'html',
'engine' => 'openai',
'model' => 'gpt-4o-mini',
'source_context_chars' => 12000,
'media_url' => 'https://example.com/neutral-workspace-photo.jpg',
]);
$response = Engine::openai()
->model('gpt-4o-mini')
->generate('Summarize this ticket');
$image = Engine::fal()
->model('fal-ai/flux-pro')
->generateImage('A clean product mockup on a white desk');
$response = Engine::openrouter()
->model('openai/gpt-4o-mini')
->withProviderOptions([
'provider' => [
'only' => ['openai', 'anthropic'],
'data_collection' => 'deny',
'
$request = AIRequest::make('Continue the previous analysis', 'openai', 'gpt-4o')
->setConversationId('thread-123')
->withMetadata(['openai_responses_api' => true])
->withProviderOptions(['use_previous_response' => true], 'openai');
'additional_input_unit_rates' => [
'fal_ai' => [
'default' => ['image' => 0.25],
'models' => [
'fal-ai/nano-banana-2/edit' => [
'image' => 0.5,
],
'fal-ai/kling-video/o3/standard/reference-to-video' => [
'image' => 0.5,
],
'bytedance/seedance-2.0/reference-to-video' => [
'image' => 0.75,
],
],
],
],
bash
composer vendor:publish --tag=ai-engine-config
php artisan vendor:publish --tag=ai-engine-migrations
php artisan vendor:publish --tag=ai-engine-collection-ui
php artisan migrate
bash
php artisan ai:models:seed # import the shipped catalog into ai_models
php artisan ai:models:seed --fresh # overwrite existing rows back to catalog values
php artisan ai:sync-models --provider=all
php artisan ai:list-models
bash
php artisan vendor:publish --tag=ai-engine-assistant-client
php artisan ai:assistant-readiness
php artisan ai:assistant-readiness orchestration --json
php artisan ai:assistant-knowledge-index --force --json
bash
php artisan ai:decision-feedback:report
php artisan ai:decision-policy:evaluate --window-hours=48
php artisan ai:decision-policy:create v2 --activate
php artisan ai:decision-policy:activate 2
bash
AI_ENGINE_RUN_OPENROUTER_LIVE_TESTS=true \
php vendor/bin/phpunit -c phpunit.xml.dist tests/Feature/Live/OpenRouterLiveFeatureTest.php
bash
php artisan ai:pricing-audit --json
php artisan ai:pricing-audit --fail-on-warning
php artisan ai:pricing-simulate fal_ai fal-ai/kling-video/o3/standard/image-to-video --parameters='{"image_url":"https://example.test/product.png"}'
bash
php artisan vendor:publish --tag=ai-engine-config --force
php artisan optimize:clear