PHP code example of pixelworxio / filament-ai-action

1. Go to this page and download the library: Download pixelworxio/filament-ai-action 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/ */

    

pixelworxio / filament-ai-action example snippets


use Pixelworxio\FilamentAiAction\FilamentAiActionPlugin;

->plugins([
    FilamentAiActionPlugin::make(),
])

use Pixelworxio\FilamentAiAction\AiAction;

AiAction::make()
    ->agent(SummaryAgent::class)

AiAction::make()
    ->agent(SummaryAgent::class)
    ->stream()

AiAction::make()
    ->agent(SummaryAgent::class)
    ->withUserInstruction('What would you like to know about this record?')

AiAction::make()
    ->agent(SummaryAgent::class)
    ->persistResultTo('ai_summary')

AiAction::make()
    ->agent(SummaryAgent::class)
    ->queued('high')

AiAction::make()
    ->agent(SummaryAgent::class)
    ->usingProvider('openai', 'gpt-4o')

use Pixelworxio\LaravelAiAction\DTOs\AgentContext;

AiAction::make()
    ->agent(SummaryAgent::class)
    ->withContext(function (AgentContext $ctx, Model $record): AgentContext {
        return $ctx->withMeta('tenant_id', $record->tenant_id);
    })

use Pixelworxio\FilamentAiAction\AiBulkAction;

AiBulkAction::make()
    ->agent(SummaryAgent::class)
    ->persistResultTo('ai_summary')
    ->queued()
    ->deselectRecordsAfterCompletion()

use Pixelworxio\FilamentAiAction\Infolists\AgentResultEntry;

AgentResultEntry::make('ai_summary')
    ->label('AI Summary')
    ->markdown()
    ->withRefreshAction()

use Pixelworxio\FilamentAiAction\Widgets\AiActionWidget;

// In your panel provider's getWidgets():
protected function getWidgets(): array
{
    return [
        AiActionWidget::agent(DashboardInsightAgent::class)
            ->contextBuilder(fn (): AgentContext => AgentContext::fromRecords(
                Post::latest()->limit(10)->get()->all()
            )),
    ];
}

AiAction::make()
    ->agent(LongFormWriterAgent::class)
    ->stream()

use Pixelworxio\LaravelAiAction\Testing\FakeAgentAction;

beforeEach(fn () => FakeAgentAction::reset());

it('persists the agent result to the model column', function (): void {
    FakeAgentAction::fakeResponse(SummaryAgent::class, 'This is the summary.');

    $record = Post::factory()->create();

    $action = AiAction::make('ai')
        ->agent(SummaryAgent::class)
        ->persistResultTo('ai_summary');

    $action->record($record);

    $reflection = new ReflectionMethod($action, 'runAgent');
    $reflection->setAccessible(true);
    $reflection->invoke($action);

    expect($record->fresh()->ai_summary)->toBe('This is the summary.');
    FakeAgentAction::assertAgentCalled(SummaryAgent::class, 1);
});
bash
php artisan vendor:publish --tag=filament-ai-action-config
bash
php artisan vendor:publish --tag=filament-ai-action-config
bash
php artisan vendor:publish --tag=filament-ai-action-views