From ae29fad050bea3dbe349086172477e94a7d5a944 Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Sun, 18 Aug 2024 09:30:34 -0400 Subject: [PATCH] Move document logic to a class other sources can use --- .../Sources/CreateDocumentFromSource.php | 5 ++--- app/Domains/Sources/DocumentDto.php | 1 - app/Jobs/GetWebContentJob.php | 11 +--------- .../Feature/CreateDocumentFromSourceTest.php | 20 +++++++++---------- tests/Feature/Jobs/GetWebContentJobTest.php | 2 +- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/app/Domains/Sources/CreateDocumentFromSource.php b/app/Domains/Sources/CreateDocumentFromSource.php index db6fee43..08cfb282 100644 --- a/app/Domains/Sources/CreateDocumentFromSource.php +++ b/app/Domains/Sources/CreateDocumentFromSource.php @@ -4,7 +4,6 @@ use App\Domains\Chat\MetaDataDto; use App\Domains\Documents\StatusEnum; -use App\Domains\Documents\TypesEnum; use App\Domains\Messages\RoleEnum; use App\Helpers\ChatHelperTrait; use App\Helpers\TextChunker; @@ -26,10 +25,10 @@ class CreateDocumentFromSource { use ChatHelperTrait, ToolsHelper; - protected Source $source; - public function handle(Source $source, string $content, DocumentDto $documentDto): void { + public function handle(Source $source, string $content, DocumentDto $documentDto): void + { $this->source = $this->checkForChat($source); $promptUsingCollection = Templatizer::appendContext(true) diff --git a/app/Domains/Sources/DocumentDto.php b/app/Domains/Sources/DocumentDto.php index 1efe6cde..8b50b4ea 100644 --- a/app/Domains/Sources/DocumentDto.php +++ b/app/Domains/Sources/DocumentDto.php @@ -7,7 +7,6 @@ class DocumentDto extends Data { - public function __construct( public string $link = '', public string $title = '', diff --git a/app/Jobs/GetWebContentJob.php b/app/Jobs/GetWebContentJob.php index 5c22437d..2a30ce32 100644 --- a/app/Jobs/GetWebContentJob.php +++ b/app/Jobs/GetWebContentJob.php @@ -2,19 +2,14 @@ namespace App\Jobs; -use App\Domains\Chat\MetaDataDto; -use App\Domains\Documents\StatusEnum; use App\Domains\Documents\TypesEnum; -use App\Domains\Messages\RoleEnum; use App\Domains\Sources\DocumentDto; -use Facades\App\Domains\Sources\CreateDocumentFromSource; use App\Domains\Sources\WebSearch\Response\WebResponseDto; use App\Helpers\ChatHelperTrait; -use App\Helpers\TextChunker; use App\Models\Document; -use App\Models\DocumentChunk; use App\Models\Source; use Facades\App\Domains\Orchestration\OrchestrateVersionTwo; +use Facades\App\Domains\Sources\CreateDocumentFromSource; use Facades\App\Domains\Sources\WebSearch\GetPage; use Facades\App\Domains\Tokenizer\Templatizer; use Illuminate\Bus\Batch; @@ -24,11 +19,9 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Log; use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\LlmDriver\ToolsHelper; -use LlmLaraHub\TagFunction\Jobs\TagDocumentJob; class GetWebContentJob implements ShouldQueue { @@ -108,7 +101,6 @@ public function handle(): void * Make this a tool and or pull it out for now in a * shared Class for Sources since it is the same for all of them */ - CreateDocumentFromSource::handle( source: $this->source, content: $htmlResults->content, @@ -123,7 +115,6 @@ public function handle(): void ]) ); - } } } diff --git a/tests/Feature/CreateDocumentFromSourceTest.php b/tests/Feature/CreateDocumentFromSourceTest.php index d390ddb7..c9c1a6c7 100644 --- a/tests/Feature/CreateDocumentFromSourceTest.php +++ b/tests/Feature/CreateDocumentFromSourceTest.php @@ -5,8 +5,6 @@ use App\Domains\Documents\TypesEnum; use App\Domains\Sources\DocumentDto; use App\Models\Source; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Bus; use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\LlmDriver\Responses\CompletionResponse; @@ -38,15 +36,15 @@ public function test_makes_document(): void $handle->handle( $source, $fixture, - DocumentDto::from([ - 'type' => TypesEnum::HTML, - 'link' => "foo.com", - 'title' => "Foo Bar", - 'subject' => "Foo Bar", - 'file_path' => "foo.com", - 'document_md5' => md5($fixture), - 'meta_data' => [], - ])); + DocumentDto::from([ + 'type' => TypesEnum::HTML, + 'link' => 'foo.com', + 'title' => 'Foo Bar', + 'subject' => 'Foo Bar', + 'file_path' => 'foo.com', + 'document_md5' => md5($fixture), + 'meta_data' => [], + ])); $this->assertDatabaseCount('documents', 1); $this->assertDatabaseCount('document_chunks', 17); diff --git a/tests/Feature/Jobs/GetWebContentJobTest.php b/tests/Feature/Jobs/GetWebContentJobTest.php index 86d07bfd..34a7a2fb 100644 --- a/tests/Feature/Jobs/GetWebContentJobTest.php +++ b/tests/Feature/Jobs/GetWebContentJobTest.php @@ -2,12 +2,12 @@ namespace Tests\Feature\Jobs; -use Facades\App\Domains\Sources\CreateDocumentFromSource; use App\Domains\Sources\WebSearch\Response\WebResponseDto; use App\Domains\WebParser\WebContentResultsDto; use App\Jobs\GetWebContentJob; use App\Models\Source; use Facades\App\Domains\Orchestration\OrchestrateVersionTwo; +use Facades\App\Domains\Sources\CreateDocumentFromSource; use Facades\App\Domains\Sources\WebSearch\GetPage; use Illuminate\Support\Facades\Bus; use Laravel\Pennant\Feature;