diff --git a/Modules/LlmDriver/app/Functions/SearchAndSummarize.php b/Modules/LlmDriver/app/Functions/SearchAndSummarize.php index c4d9ff17..0bc7e716 100644 --- a/Modules/LlmDriver/app/Functions/SearchAndSummarize.php +++ b/Modules/LlmDriver/app/Functions/SearchAndSummarize.php @@ -2,7 +2,6 @@ namespace LlmLaraHub\LlmDriver\Functions; -use App\Models\Chat; use LlmLaraHub\LlmDriver\HasDrivers; use LlmLaraHub\LlmDriver\Responses\FunctionResponse; @@ -19,6 +18,7 @@ public function handle( { /** * @TODO + * * @see https://github.com/orgs/LlmLaraHub/projects/1/views/1?pane=issue&itemId=59671259 */ return FunctionResponse::from( diff --git a/Modules/LlmDriver/app/Functions/SummarizeCollection.php b/Modules/LlmDriver/app/Functions/SummarizeCollection.php index 4f26fda4..d701347c 100644 --- a/Modules/LlmDriver/app/Functions/SummarizeCollection.php +++ b/Modules/LlmDriver/app/Functions/SummarizeCollection.php @@ -46,7 +46,7 @@ public function handle( /** * @TODO - * We assume chat model + * We assume chat model */ $model->addInput( message: $results->content, diff --git a/Modules/LlmDriver/app/HasDrivers.php b/Modules/LlmDriver/app/HasDrivers.php index 19443de1..d806131d 100644 --- a/Modules/LlmDriver/app/HasDrivers.php +++ b/Modules/LlmDriver/app/HasDrivers.php @@ -8,9 +8,9 @@ public function getDriver(): string; public function getEmbeddingDriver(): string; - public function getSummary() : string; + public function getSummary(): string; - public function getId() : int; + public function getId(): int; - public function getType() : string; + public function getType(): string; } diff --git a/Modules/TagFunction/app/Contracts/TaggableContract.php b/Modules/TagFunction/app/Contracts/TaggableContract.php index ed46735c..ff917f14 100644 --- a/Modules/TagFunction/app/Contracts/TaggableContract.php +++ b/Modules/TagFunction/app/Contracts/TaggableContract.php @@ -1,4 +1,4 @@ -getSummary(); - $tags = data_get($functionCallDto->arguments, 'tags', "no limit"); + $tags = data_get($functionCallDto->arguments, 'tags', 'no limit'); $prompt = << $prompt, 'role' => 'user', @@ -48,7 +49,7 @@ public function handle( $tags = json_decode($results->content, true); - foreach($tags as $tag) { + foreach ($tags as $tag) { $model->addTag($tag); } @@ -73,4 +74,4 @@ protected function getProperties(): array ), ]; } -} \ No newline at end of file +} diff --git a/Modules/TagFunction/app/Helpers/Taggable.php b/Modules/TagFunction/app/Helpers/Taggable.php index ddff9cd4..d7b40935 100644 --- a/Modules/TagFunction/app/Helpers/Taggable.php +++ b/Modules/TagFunction/app/Helpers/Taggable.php @@ -1,23 +1,20 @@ -morphToMany(Tag::class, 'taggable'); } - public function addTag(string $tag) : void + public function addTag(string $tag): void { $tag = Tag::firstOrCreate(['name' => $tag]); $this->tags()->attach($tag->id); } } - diff --git a/Modules/TagFunction/app/Models/Tag.php b/Modules/TagFunction/app/Models/Tag.php index da9e6906..8576f7cf 100644 --- a/Modules/TagFunction/app/Models/Tag.php +++ b/Modules/TagFunction/app/Models/Tag.php @@ -5,9 +5,8 @@ use App\Models\Collection; use App\Models\Document; use App\Models\DocumentChunk; -use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; -use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphToMany; use LlmLaraHub\TagFunction\Database\Factories\TagFactory; @@ -27,7 +26,6 @@ public function document_chunks(): MorphToMany return $this->morphedByMany(DocumentChunk::class, 'taggable'); } - public function documents(): MorphToMany { return $this->morphedByMany(Document::class, 'taggable'); @@ -37,5 +35,4 @@ public function collections(): MorphToMany { return $this->morphedByMany(Collection::class, 'taggable'); } - } diff --git a/Modules/TagFunction/database/factories/TagFactory.php b/Modules/TagFunction/database/factories/TagFactory.php index 393ffc08..ba0312f1 100644 --- a/Modules/TagFunction/database/factories/TagFactory.php +++ b/Modules/TagFunction/database/factories/TagFactory.php @@ -2,7 +2,6 @@ namespace LlmLaraHub\TagFunction\Database\Factories; -use App\Models\DocumentChunk; use Illuminate\Database\Eloquent\Factories\Factory; class TagFactory extends Factory @@ -22,7 +21,7 @@ public function definition(): array ]; } - /** + /** * Associate the tag with a taggable model. */ public function taggable($modelType, $modelId) @@ -35,4 +34,3 @@ public function taggable($modelType, $modelId) }); } } - diff --git a/Modules/TagFunction/tests/Feature/TagFunctionTest.php b/Modules/TagFunction/tests/Feature/TagFunctionTest.php index bc9343b6..bedd224b 100644 --- a/Modules/TagFunction/tests/Feature/TagFunctionTest.php +++ b/Modules/TagFunction/tests/Feature/TagFunctionTest.php @@ -16,13 +16,13 @@ class TagFunctionTest extends TestCase */ public function test_talks_to_llm(): void { - $tags = get_fixture("taggings_results_from_llm.json"); + $tags = get_fixture('taggings_results_from_llm.json'); LlmDriverFacade::shouldReceive('driver->chat')->once()->andReturn( CompletionResponse::from([ 'content' => $tags, ]) ); - $content = << "tagging_function", - "arguments" => "[]" + 'function_name' => 'tagging_function', + 'arguments' => '[]', ]) ); diff --git a/Modules/TagFunction/tests/Feature/TagTest.php b/Modules/TagFunction/tests/Feature/TagTest.php index d48cde12..bb7a40c7 100644 --- a/Modules/TagFunction/tests/Feature/TagTest.php +++ b/Modules/TagFunction/tests/Feature/TagTest.php @@ -3,10 +3,8 @@ namespace LlmLaraHub\TagFunction\tests\Feature; use App\Models\Document; -use Tests\TestCase; -use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Foundation\Testing\RefreshDatabase; use LlmLaraHub\TagFunction\Models\Tag; +use Tests\TestCase; class TagTest extends TestCase { @@ -16,7 +14,7 @@ class TagTest extends TestCase public function test_tag_model(): void { $document = Document::factory() - ->has(Tag::factory(), 'tags')->create(); + ->has(Tag::factory(), 'tags')->create(); $this->assertNotEmpty($document->tags); @@ -28,7 +26,8 @@ public function test_tag_model(): void ); } - public function test_add_tag_new() { + public function test_add_tag_new() + { $document = Document::factory()->create(); $tag = Tag::factory()->create(); @@ -40,11 +39,12 @@ public function test_add_tag_new() { } - public function test_add_tag_existing() { + public function test_add_tag_existing() + { $document = Document::factory()->create(); $this->assertDatabaseCount('tags', 0); - $document->addTag("foobar"); + $document->addTag('foobar'); $this->assertNotEmpty($document->tags); $this->assertDatabaseCount('tags', 1); diff --git a/app/Models/Chat.php b/app/Models/Chat.php index 63957fce..ddf298a8 100644 --- a/app/Models/Chat.php +++ b/app/Models/Chat.php @@ -27,7 +27,6 @@ public function getDriver(): string return $this->chatable->getDriver(); } - public function getSummary(): string { return $this->chatable->description; diff --git a/app/Models/Collection.php b/app/Models/Collection.php index c20200b1..c4ab199f 100644 --- a/app/Models/Collection.php +++ b/app/Models/Collection.php @@ -9,8 +9,8 @@ use Illuminate\Database\Eloquent\Relations\MorphMany; use LlmLaraHub\LlmDriver\DriversEnum; use LlmLaraHub\LlmDriver\HasDrivers; -use LlmLaraHub\TagFunction\Helpers\Taggable; use LlmLaraHub\TagFunction\Contracts\TaggableContract; +use LlmLaraHub\TagFunction\Helpers\Taggable; /** * Class Project diff --git a/app/Models/Document.php b/app/Models/Document.php index dfb124dd..3e54f145 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -9,8 +9,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use LlmLaraHub\LlmDriver\HasDrivers; -use LlmLaraHub\TagFunction\Helpers\Taggable; use LlmLaraHub\TagFunction\Contracts\TaggableContract; +use LlmLaraHub\TagFunction\Helpers\Taggable; /** * Class Document diff --git a/app/Models/DocumentChunk.php b/app/Models/DocumentChunk.php index f52121cb..c29b5553 100644 --- a/app/Models/DocumentChunk.php +++ b/app/Models/DocumentChunk.php @@ -6,8 +6,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use LlmLaraHub\LlmDriver\HasDrivers; -use LlmLaraHub\TagFunction\Helpers\Taggable; use LlmLaraHub\TagFunction\Contracts\TaggableContract; +use LlmLaraHub\TagFunction\Helpers\Taggable; use Pgvector\Laravel\Vector; /** @@ -79,5 +79,4 @@ public function getSummary(): string { return $this->summary; } - } diff --git a/tests/Feature/Http/Controllers/ReindexCollectionControllerTest.php b/tests/Feature/Http/Controllers/ReindexCollectionControllerTest.php index 134e2715..ad5bd15c 100644 --- a/tests/Feature/Http/Controllers/ReindexCollectionControllerTest.php +++ b/tests/Feature/Http/Controllers/ReindexCollectionControllerTest.php @@ -28,8 +28,8 @@ public function test_reindex(): void ]); Document::factory() ->has(DocumentChunk::factory(), 'document_chunks')->create([ - 'collection_id' => $collection->id, - ]); + 'collection_id' => $collection->id, + ]); /** * @TODO Policy in place by now */