PHP code example of iamgerwin / nova-ai-context-aware-input
1. Go to this page and download the library: Download iamgerwin/nova-ai-context-aware-input 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/ */
iamgerwin / nova-ai-context-aware-input example snippets
use Iamgerwin\NovaAiContextAwareInput\Fields\TextImprove;
public function fields(Request $request)
{
return [
TextImprove::make('Description')
->style('professional')
->trigger('blur'),
];
}
// Automatically pe (e.g., "Article", "Product")
// - Resource ID
// - Common fields (title, name, description, category, type, status)
// config/nova-ai-context-aware-input.php
'policy_hints' => [
'Avoid using profanity or offensive language.',
'Maintain professional tone and clarity.',
'Preserve factual accuracy of the original text.',
],
use Iamgerwin\NovaAiContextAwareInput\Context\PolicyHintsProvider;
TextImprove::make('Comment')
->context([
(new PolicyHintsProvider())->addHints([
'Be respectful and constructive.',
'Avoid personal attacks.',
])
]);
TextImprove::make('Content')
->rateLimit('user:10,1'); // 10 requests per user per minute
// Cache key is based on: hash(input + context + style)
// Same input with same context = cache hit
use Iamgerwin\NovaAiContextAwareInput\Events\TextImproved;
class LogTextImprovement
{
public function handle(TextImproved $event): void
{
// $event->originalText
// $event->improvedText
// $event->provider
// $event->style
// $event->user
}
}
use Iamgerwin\NovaAiContextAwareInput\Events\SuggestionDiscarded;
class LogDiscardedSuggestion
{
public function handle(SuggestionDiscarded $event): void
{
// $event->originalText
// $event->suggestedText
// $event->user
}
}
// config/nova-ai-context-aware-input.php
'templates' => [
'system' => <<<'TXT'
You are an expert editor improving business text for clarity and professionalism.
Your task is to enhance the given text while:
- Preserving all factual information
- Respecting domain-specific terminology
- Maintaining the original intent and meaning
- Following the specified style guidelines
Return ONLY the improved text without explanations, quotes, or additional commentary.
TXT,
'user' => <<<'TXT'
Please improve the following text:
{{ user_input }}
Context: {{ context }}
Desired Style: {{ style }}
Language: {{ language }}
TXT,
],
bash
php artisan nova:publish
bash
composer analyse
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.