Installation
composer require jiten14/jitone-ai
php artisan jitone-ai:install
jitone-ai and openai-php/laravel, and sets up storage symlinks.Configure API Key
Add your OpenAI API key to .env:
OPENAI_API_KEY=your_api_key_here
Basic Integration In a Filament form, add the AI-powered field:
use Jitone\AI\Facades\JitoneAI;
JitoneAI::text('ai_generated_content')
->label('AI-Generated Content')
->required()
->rules(['required', 'string']);
Trigger AI Generation
Use the generate() method in your form's save() or a custom action:
public function save(Form $form): void
{
$form->fill(JitoneAI::generate('ai_generated_content'));
parent::save($form);
}
Replace manual input with AI-generated suggestions for:
Dynamic Field Generation Use AI to auto-fill fields based on existing form data:
JitoneAI::text('summary')
->generateFrom(['title', 'content'])
->label('Auto-Generated Summary');
Conditional AI Triggers Only generate content when specific conditions are met:
if ($form->get('is_premium')) {
JitoneAI::generate('custom_message');
}
Bulk Processing Process multiple records with AI in a queue job:
foreach ($records as $record) {
dispatch(new GenerateAiContent($record));
}
Filament Resource Integration
Extend Filament\Resources\Resource to include AI fields in both create/update forms:
public static function form(Form $form): Form
{
return $form
->schema([
JitoneAI::text('ai_field')->generate(),
// ... other fields
]);
}
Custom Prompts Override default prompts via config:
'prompts' => [
'default' => 'Write a {field_name} for {context}',
],
Fallback Logic Handle API failures gracefully:
try {
$aiResponse = JitoneAI::generate('field_name');
} catch (\Exception $e) {
$aiResponse = 'Default fallback content';
}
Caching Responses Cache AI-generated content to reduce API calls:
JitoneAI::text('cached_field')->cacheFor(seconds: 3600);
API Rate Limits
Cost Management
JitoneAI::logUsage('field_name', $response);
Field Validation
if (!JitoneAI::validate('field_name')) {
$form->addError('field_name', 'AI-generated content failed validation');
}
Configuration Overrides
php artisan vendor:publish --tag=jitone-ai-config
Enable Debugging
Set JITONE_AI_DEBUG=true in .env to log API requests/responses.
Common Errors
Invalid API Key: Verify .env and OpenAI account.Rate Limit Exceeded: Check usage at OpenAI Dashboard.Field Not Found: Ensure field names match exactly in generate() calls.Custom AI Providers Extend the package to support other AI services (e.g., Anthropic, Mistral):
JitoneAI::extend('anthropic', function () {
return new AnthropicService();
});
Hooks for Post-Generation Add callbacks after AI generation:
JitoneAI::text('field_name')->afterGenerate(function ($response) {
// Modify or log the response
});
Local Testing Use mock responses for local development:
JitoneAI::mockResponses([
'field_name' => 'Mocked AI response',
]);
Prompt Engineering Fine-tune prompts for better results:
JitoneAI::text('description')
->generateWithPrompt('Write a {field_name} for a {product_type} targeting {audience}.');
Performance
Use generateInBackground() for non-critical fields to avoid blocking the UI.
User Feedback Allow users to edit AI-generated content and log improvements to refine prompts over time.
How can I help you explore Laravel packages today?