Skip to content

Commit

Permalink
add verification to the document chunk summary
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 30, 2024
1 parent ea2a5fb commit a885ebc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 22 additions & 1 deletion app/Jobs/SummarizeDataJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Jobs;

use App\Domains\Agents\VerifyPromptInputDto;
use App\Domains\Agents\VerifyPromptOutputDto;
use App\Domains\Documents\StatusEnum;
use App\Models\DocumentChunk;
use Facades\App\Domains\Agents\VerifyResponseAgent;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -62,8 +65,26 @@ public function handle(): void
$this->documentChunk->getDriver()
)->completion($prompt);

$verifyPrompt = <<<'PROMPT'
This the content from a chunk of data in a document.
Can you verify the summary is correct?
PROMPT;

$dto = VerifyPromptInputDto::from(
[
'chattable' => $this->documentChunk,
'originalPrompt' => $prompt,
'context' => $content,
'llmResponse' => $results->content,
'verifyPrompt' => $verifyPrompt,
]
);

/** @var VerifyPromptOutputDto $response */
$response = VerifyResponseAgent::verify($dto);

$this->documentChunk->update([
'summary' => $results->content,
'summary' => $response->response,
'status_summary' => StatusEnum::Complete,
]);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/SummarizeDataJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public function test_gets_data(): void
'summary' => null,
]);

$this->fakeVerify($documentChunk);

$job = new SummarizeDataJob($documentChunk);
$job->handle();

$this->assertEquals('Foo bar', $documentChunk->refresh()->summary);
$this->assertEquals('verified yay!', $documentChunk->refresh()->summary);
}
}

0 comments on commit a885ebc

Please sign in to comment.