PHP code example of gwhthompson / filament-ai-forms
1. Go to this page and download the library: Download gwhthompson/filament-ai-forms 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/ */
gwhthompson / filament-ai-forms example snippets
use Gwhthompson\FilamentAiForms\FilamentAiFormsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugin(FilamentAiFormsPlugin::make());
}
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Gwhthompson\FilamentAiForms\Actions\AiGenerateAction;
public static function form(Form $form): Form
{
return $form->schema([
TextInput::make('name')
->aiSchema(description: 'The company name'),
Textarea::make('description')
->aiSchema(
description: 'A marketing description',
prompt: 'Write 2-3 sentences',
),
]);
}
protected function getHeaderActions(): array
{
return [
AiGenerateAction::make(),
];
}
AiGenerateAction::make()
->systemPrompt('You are a business data specialist.')
->contextProvider(fn ($action) => [
'url' => $action->getRecord()->website_url,
])
Textarea::make('bio')
->aiSchema(description: 'Professional biography')
->suffixAction(
AiChatAction::make()
->systemPrompt('You are a professional copywriter.')
->initialPrompt('Help me write a compelling bio')
)
use Laravel\Ai\Contracts\Agent;
use Laravel\Ai\Contracts\HasStructuredOutput;
use Laravel\Ai\Contracts\HasTools;
use Laravel\Ai\Promptable;
use Laravel\Ai\Attributes\Provider;
use Laravel\Ai\Attributes\Model;
use Laravel\Ai\Attributes\Temperature;
#[Provider('openai')]
#[Model('gpt-4o')]
#[Temperature(0.1)]
class MyGenerationAgent implements Agent, HasStructuredOutput, HasTools
{
use Promptable;
public function tools(): array
{
return [
new \Laravel\Ai\Tools\WebSearch,
];
}
}
use Laravel\Ai\Facades\Agent;
Agent::fake([
['name' => 'Acme Corp', 'description' => 'A test company'],
]);
// ... trigger the action ...
Agent::assertPrompted(fn ($prompt) => str_contains($prompt, 'company name'));