Skip to content

Commit

Permalink
this adds the sync ability for the csv and xl file if the user puts i…
Browse files Browse the repository at this point in the history
…n keys need to surface that to the ui
  • Loading branch information
alnutile committed Jul 23, 2024
1 parent 09c08ec commit ce63d13
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
11 changes: 6 additions & 5 deletions app/Domains/Documents/Transformers/CSVTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(Document $document): array
* BUT by saving the keys we can find any documents not updated
* and delete those
*/
if(collect($row)->has('key')) {
if (collect($row)->has('key')) {
$rowNumber = collect($row)->get('key');
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public function handle(Document $document): array

if ($documentRow->wasRecentlyCreated || $documentRow->wasChanged([
'original_content',
])) {
])) {
foreach ($chunked_chunks as $chunkSection => $chunkContent) {

$guid = md5($chunkContent);
Expand Down Expand Up @@ -126,21 +126,22 @@ public function handle(Document $document): array

Log::info($this->mimeType->name.':Transformer:handle', ['chunks' => count($chunks)]);


$this->cleanUpDeletedRows();

$document->delete();

return $chunks;
}

protected function cleanUpDeletedRows() :void {
protected function cleanUpDeletedRows(): void
{
Document::where('collection_id', $this->document->collection_id)
->whereNotIn('file_path', $this->getKeysWithFileName())
->delete();
}

protected function getKeysWithFileName(): array {
protected function getKeysWithFileName(): array
{
return collect($this->keysFound)->map(function ($rowNumber) {
return $this->getFileName($rowNumber, $this->document->file_path);
})->toArray();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function ($item) {
'audiences' => AudienceResource::collection(Audience::all()),
'system_prompt' => $collection->systemPrompt(),
'settings' => [
'supports_functions' => LlmDriverFacade::driver($chat->getDriver())->hasFunctions(),
'supports_functions' => LlmDriverFacade::driver($chat->getDriver())->hasFunctions(),
],
'messages' => MessageResource::collection($chat->latest_messages),
]);
Expand Down
1 change: 0 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function boot(): void
return false;
});


Feature::define('verification_prompt', function (User $user) {
return false;
});
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/CSVTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function test_updates_keys(): void

$testingDocument = Document::factory()->create([
'collection_id' => $document->collection_id,
'file_path' => 'row_555_strategies_with_keys.txt'
'file_path' => 'row_555_strategies_with_keys.txt',
]);

$results = (new CSVTransformer())->handle($document);
Expand All @@ -104,7 +104,6 @@ public function test_updates_keys(): void
$this->assertStringContainsString('For the front end we focus on simplicity', $testingDocument->refresh()->original_content);
}


protected function tearDown(): void
{
if (! File::exists($this->document->pathToFile())) {
Expand Down

0 comments on commit ce63d13

Please sign in to comment.