Skip to content

Commit

Permalink
Move document logic to a class other sources can use
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Aug 18, 2024
1 parent 625c509 commit ae29fad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 26 deletions.
5 changes: 2 additions & 3 deletions app/Domains/Sources/CreateDocumentFromSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion app/Domains/Sources/DocumentDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class DocumentDto extends Data
{

public function __construct(
public string $link = '',
public string $title = '',
Expand Down
11 changes: 1 addition & 10 deletions app/Jobs/GetWebContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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,
Expand All @@ -123,7 +115,6 @@ public function handle(): void
])
);


}
}
}
20 changes: 9 additions & 11 deletions tests/Feature/CreateDocumentFromSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Jobs/GetWebContentJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ae29fad

Please sign in to comment.