From 5ede277608f962a8d4ba4ea7c81f27a7a75006d2 Mon Sep 17 00:00:00 2001 From: Ashley Hindle Date: Sat, 7 Sep 2024 18:28:57 +0100 Subject: [PATCH] (feat): adds exclusion support and docs --- README.md | 9 +++++++-- src/AiAutofill.php | 2 +- src/Jobs/AiAutofillJob.php | 9 +++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5a59b5d..3b7537c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This package listens to the `saved` model event, then adds a queued job to autof Example: ```php class Article extends Model { - use AshleyHindle\AiAutofill; + use AshleyHindle\AiAutofill\AiAutofill; protected $autofill = ['tagline' => 'a super click-baity obnoxious tagline']; } @@ -28,15 +28,20 @@ composer require ashleyhindle/laravel-ai-autofill ### Model Trait Usage Simply use the trait in your model, and add the `$autofill` array. +The keys are the properties you want to autofill, and the values are the prompts you want to use to fill them. + +The whole model, minus `$autofillExclude` properties, is provided to the LLM for context, so the prompts in `$autofill` can be very simple. ```php class MeetingNotes extends Model { - use AshleyHindle\AiAutofill; + use AshleyHindle\AiAutofill\AiAutofill; protected $autofill = [ 'summary' => 'executive summary', 'action_items' => 'Flat JSON array of action items (e.g. ["Item 1", "Item 2", "Item 3"])' ]; + + protected $autofillExclude = ['zoom_password']; } ``` diff --git a/src/AiAutofill.php b/src/AiAutofill.php index 17e0a11..40165ae 100755 --- a/src/AiAutofill.php +++ b/src/AiAutofill.php @@ -14,7 +14,7 @@ public static function bootAiAutofill() return; } - AiAutofillJob::dispatch($model, $model->autofill); + AiAutofillJob::dispatch($model, $model->autofill, $model->autofillExclude ?? []); }); } } diff --git a/src/Jobs/AiAutofillJob.php b/src/Jobs/AiAutofillJob.php index ac9c41b..1ae29ef 100644 --- a/src/Jobs/AiAutofillJob.php +++ b/src/Jobs/AiAutofillJob.php @@ -12,7 +12,7 @@ class AiAutofillJob implements ShouldQueue { use Queueable; - public function __construct(protected Model $model, protected array $autofill) {} + public function __construct(protected Model $model, protected array $autofill, protected array $autofillExclude = []) {} public function handle() { @@ -23,6 +23,11 @@ public function handle() $count = count($this->autofill); $jsonAutofill = json_encode($this->autofill); $modelName = class_basename($this->model); + $modelProperties = $this->model->toArray(); + foreach ($this->autofillExclude as $property) { + unset($modelProperties[$property]); + } + $modelContext = json_encode($modelProperties); $systemPrompt = <<model->toJson()} + {$modelContext} ### PROPERTIES & PROMPTS ### {$jsonAutofill}