-
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.
Lots of updates when using ollama to batch the jobs so they can wait …
…else the jobs stack up and timeout Signed-off-by: alnutile <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,041 additions
and
43 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
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
35 changes: 35 additions & 0 deletions
35
Modules/LlmDriver/app/SimpleSearchAndSummarizeOrchestrate.php
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,35 @@ | ||
<?php | ||
|
||
namespace LlmLaraHub\LlmDriver; | ||
|
||
use App\Events\ChatUiUpdateEvent; | ||
use App\Models\Chat; | ||
use Facades\App\Domains\Messages\SearchOrSummarizeChatRepo; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class SimpleSearchAndSummarizeOrchestrate | ||
{ | ||
protected string $response = ''; | ||
|
||
protected bool $requiresFollowup = false; | ||
|
||
public function handle(string $message, Chat $chat): ?string | ||
{ | ||
Log::info('[LaraChain] Skipping over functions doing search and summarize'); | ||
|
||
ChatUiUpdateEvent::dispatch( | ||
$chat->chatable, | ||
$chat, | ||
'Searching data now to summarize content' | ||
); | ||
|
||
$response = SearchOrSummarizeChatRepo::search($chat, $message); | ||
|
||
return $response; | ||
} | ||
|
||
protected function hasFunctions(array $functions): bool | ||
{ | ||
return is_array($functions) && count($functions) > 0; | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
app/Domains/Documents/Transformers/PowerPointTransformer.php
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,71 @@ | ||
<?php | ||
|
||
namespace App\Domains\Documents\Transformers; | ||
|
||
use App\Domains\Collections\CollectionStatusEnum; | ||
use App\Events\CollectionStatusEvent; | ||
use App\Jobs\SummarizeDataJob; | ||
use App\Jobs\VectorlizeDataJob; | ||
use App\Models\Document; | ||
use App\Models\DocumentChunk; | ||
use Illuminate\Support\Facades\Log; | ||
use PhpOffice\PhpPresentation\IOFactory; | ||
use PhpOffice\PhpPresentation\Shape\RichText; | ||
|
||
class PowerPointTransformer | ||
{ | ||
protected Document $document; | ||
|
||
public function handle(Document $document): array | ||
{ | ||
$this->document = $document; | ||
|
||
$filePath = $this->document->pathToFile(); | ||
|
||
$parser = IOFactory::createReader('PowerPoint2007'); | ||
if (! $parser->canRead($filePath)) { | ||
throw new \Exception('Can not read the document '.$filePath); | ||
} | ||
|
||
$oPHPPresentation = $parser->load($filePath); | ||
|
||
$chunks = []; | ||
foreach ($oPHPPresentation->getAllSlides() as $page_number => $page) { | ||
try { | ||
foreach ($page->getShapeCollection() as $shape) { | ||
// Check if shape contains text | ||
if ($shape instanceof RichText) { | ||
// Get the text from the shape | ||
$page_number = $page_number + 1; | ||
$pageContent = $shape->getPlainText(); | ||
$guid = $filePath.'_'.$page_number; | ||
$DocumentChunk = DocumentChunk::updateOrCreate( | ||
[ | ||
'guid' => $guid, | ||
'document_id' => $this->document->id, | ||
], | ||
[ | ||
'content' => $pageContent, | ||
'sort_order' => $page_number, | ||
] | ||
); | ||
|
||
$chunks[] = [ | ||
new VectorlizeDataJob($DocumentChunk), | ||
new SummarizeDataJob($DocumentChunk), | ||
//new TagDataJob($this->document), | ||
//then mark it all as done and notify the ui | ||
]; | ||
} | ||
} | ||
CollectionStatusEvent::dispatch($document->collection, CollectionStatusEnum::PROCESSING); | ||
} catch (\Exception $e) { | ||
Log::error('Error parsing PDF', ['error' => $e->getMessage()]); | ||
} | ||
} | ||
|
||
Log::info('PowerPointTransformer:handle', ['chunks' => count($chunks)]); | ||
|
||
return $chunks; | ||
} | ||
} |
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
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,44 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Document; | ||
use Facades\App\Domains\Documents\Transformers\PowerPointTransformer; | ||
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 ParsePowerPointJob implements ShouldQueue | ||
{ | ||
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
$chunks = PowerPointTransformer::handle($this->document); | ||
|
||
foreach ($chunks as $chunk) { | ||
$this->batch()->add($chunk); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.