A Laravel package that enables LLM processing for any Eloquent model without requiring modifications to those models. The package allows defining LLM processes that specify which model and relations to work with, then processes data from those models through AI prompts.
You can install the package via composer:
composer require lanos/llm-processorPublish and run the migrations:
php artisan vendor:publish --tag=llm-processor-migrations
php artisan migratePublish the configuration file:
php artisan vendor:publish --tag=llm-processor-configThe package can be configured by editing the config/llm-processor.php configuration file. You can set your OpenRouter API key and other settings:
return [
'openrouter' => [
'api_key' => env('OPENROUTER_API_KEY'),
// ... other settings
],
// ... other configuration options
];Don't forget to add your OpenRouter API key to your .env file:
OPENROUTER_API_KEY=your-api-key-hereFirst, create an LLM process that defines how to process your models:
use Lanos\LLMProcessor\Models\LLMProcess;
$process = LLMProcess::create([
'name' => 'Extract Property Insights',
'slug' => 'property-insights',
'model_class' => 'App\Models\Property',
'dependencies' => ['images', 'owner.profile', 'listings'],
'system_prompt' => 'You are analyzing property {{id}} located at {{address}}',
'user_prompt' => 'Analyse {{description}} and images at {{images.0.url}}',
'model' => 'openai/gpt-4',
'temperature' => 0.7,
'max_output_tokens' => 4096,
'is_active' => true,
]);To process a model with an LLM process, use the facade:
use Lanos\LLMProcessor\Facades\LLMProcessor;
// Process asynchronously (default)
$interaction = LLMProcessor::process($process->id, $propertyId);
// Process synchronously
$interaction = LLMProcessor::processSync($process->id, $propertyId);You can check the status of an interaction:
$interaction = LLMProcessor::getInteraction($interactionId);
if ($interaction->status === 'completed') {
echo $interaction->response;
}You can specify attachments in your process configuration:
$process = LLMProcess::create([
// ... other fields
'attachments' => ['images.0.url', 'documents.0.file_url'],
]);You can request structured JSON output:
$process = LLMProcess::create([
// ... other fields
'output_type' => 'json',
'structured_output_schema' => [
'name' => 'property_analysis',
'schema' => [
'type' => 'object',
'properties' => [
'property_value' => ['type' => 'string'],
'recommendations' => [
'type' => 'array',
'items' => ['type' => 'string']
]
],
'required' => ['property_value', 'recommendations']
]
],
]);Enable web search and reasoning capabilities:
$process = LLMProcess::create([
// ... other fields
'use_web_search' => true,
'use_reasoning' => true,
]);To run the tests:
composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.