Skip to content

Commit

Permalink
Ok Source works for EmailSource and Prompting now to move it to all o…
Browse files Browse the repository at this point in the history
…ther Soruces
  • Loading branch information
alnutile committed Jul 21, 2024
1 parent 345972a commit 685e59c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
6 changes: 1 addition & 5 deletions app/Domains/Sources/EmailSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Facades\App\Domains\EmailParser\Client;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Log;
use Laravel\Prompts\Prompt;
use LlmLaraHub\LlmDriver\LlmDriverFacade;

class EmailSource extends BaseSource
Expand Down Expand Up @@ -63,16 +62,13 @@ public function handle(Source $source): void
'prompt' => $prompt,
]);


$chat = $source->chat;



$results = LlmDriverFacade::driver(
$source->getDriver()
)->completion($prompt);

if($this->ifNotActionRequired($results->content)) {
if ($this->ifNotActionRequired($results->content)) {
Log::info('[LaraChain] - Email Source Skipping', [
'prompt' => $prompt,
]);
Expand Down
5 changes: 3 additions & 2 deletions app/Helpers/ChatHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function getUserId(Collection $collection): ?int
return $collection->team?->user_id;
}

public function ifNotActionRequired(string $results): bool {
public function ifNotActionRequired(string $results): bool
{
// @NOTE llms sometimes do not return the right
// string for example.
// false becomes false, "false" or "False" etc.
Expand All @@ -46,6 +47,6 @@ public function ifNotActionRequired(string $results): bool {
->remove("'")
->toString();

return $results == "false";
return $results == 'false';
}
}
11 changes: 5 additions & 6 deletions app/Jobs/ChunkDocumentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function handle(): void
return;
}


Log::info('[LaraChain] - Chunking Document', [
'document' => $this->document->id,
]);

$document = $this->document;

$chunks = [];

$page_number = 0;

$pageContent = $this->document->original_content;
Expand Down Expand Up @@ -80,9 +81,7 @@ public function handle(): void
];
}

$name = sprintf($document->type->name, $document->id);


$name = sprintf("Chunking Document Type %s id %d ", $document->type->name, $document->id);

Bus::batch($chunks)
->name($name)
Expand All @@ -94,9 +93,9 @@ public function handle(): void
new SummarizeDocumentJob($document),
new TagDocumentJob($document),
new DocumentProcessingCompleteJob($document),
]
],
])
->name(sprintf("Final Document Steps Document %s id %d", $document->type->name, $document->id))
->name(sprintf('Final Document Steps Document %s id %d', $document->type->name, $document->id))
->allowFailures()
->dispatch();
})
Expand Down
3 changes: 1 addition & 2 deletions tests/Feature/EmailSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public function tests_creates_chat_and_message()
Bus::assertBatchCount(1);
}


public function test_no_action_required()
{
Bus::fake();
Expand Down Expand Up @@ -170,7 +169,7 @@ public function test_no_action_required()

$this->assertDatabaseCount('documents', 0);
$this->assertDatabaseCount('chats', 1);
$this->assertDatabaseCount('messages', 1);
$this->assertDatabaseCount('messages', 0);

$this->assertNotNull($source->chat_id);

Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Jobs/ChunkDocumentJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public function test_chunking(): void

$this->assertDatabaseCount('document_chunks', 0);


[$job, $batch] = (new ChunkDocumentJob($document))->withFakeBatch();


$job->handle();

$this->assertDatabaseCount('document_chunks', 1);
Expand Down

0 comments on commit 685e59c

Please sign in to comment.