-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
252 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Helpers\TextChunker; | ||
use App\Models\Document; | ||
use App\Models\DocumentChunk; | ||
use Illuminate\Bus\Batch; | ||
use Illuminate\Support\Facades\Bus; | ||
use Illuminate\Support\Facades\Log; | ||
use LlmLaraHub\LlmDriver\LlmDriverFacade; | ||
use LlmLaraHub\TagFunction\Jobs\TagDocumentJob; | ||
|
||
trait WebHelperTrait | ||
{ | ||
protected function processDocument(Document $document): void | ||
{ | ||
$jobs = []; | ||
|
||
$page_number = 1; | ||
|
||
$html = $document->original_content; | ||
|
||
$chunked_chunks = TextChunker::handle($html); | ||
|
||
foreach ($chunked_chunks as $chunkSection => $chunkContent) { | ||
|
||
$guid = md5($chunkContent); | ||
|
||
$DocumentChunk = DocumentChunk::updateOrCreate( | ||
[ | ||
'document_id' => $document->id, | ||
'sort_order' => $page_number, | ||
'section_number' => $chunkSection, | ||
], | ||
[ | ||
'guid' => $guid, | ||
'content' => to_utf8($chunkContent), //still having issues. | ||
] | ||
); | ||
|
||
Log::info('[LaraChain] adding to new batch'); | ||
|
||
$jobs[] = [ | ||
new VectorlizeDataJob($DocumentChunk), | ||
new TagDocumentJob($document), | ||
new SummarizeDocumentJob($document), | ||
]; | ||
|
||
$page_number++; | ||
} | ||
|
||
if (! empty($jobs)) { | ||
Bus::batch($jobs) | ||
->name('Web Pages to Documents - '.$document->subject) | ||
->finally(function (Batch $batch) use ($document) { | ||
DocumentProcessingCompleteJob::dispatch($document); | ||
}) | ||
->allowFailures() | ||
->onQueue(LlmDriverFacade::driver($document->collection->getDriver())->onQueue()) | ||
->dispatch(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Document; | ||
use Illuminate\Bus\Batch; | ||
use Illuminate\Bus\Batchable; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class WebPageDocumentJob implements ShouldQueue | ||
{ | ||
use Batchable; | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
use WebHelperTrait; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public Document $document) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
if ($this->batch()->cancelled()) { | ||
// Determine if the batch has been cancelled... | ||
|
||
return; | ||
} | ||
|
||
$this->processDocument($this->document); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.