-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on JSON left as is not easy answer to this one
- Loading branch information
Showing
17 changed files
with
297 additions
and
90 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
62 changes: 62 additions & 0 deletions
62
Modules/LlmDriver/app/Functions/Reports/SummarizeReport.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,62 @@ | ||
<?php | ||
|
||
namespace LlmLaraHub\LlmDriver\Functions\Reports; | ||
|
||
use App\Domains\Messages\RoleEnum; | ||
use App\Domains\Prompts\ReportingSummaryPrompt; | ||
use App\Models\Report; | ||
use LlmLaraHub\LlmDriver\LlmDriverFacade; | ||
use LlmLaraHub\LlmDriver\Responses\CompletionResponse; | ||
use LlmLaraHub\LlmDriver\ToolsHelper; | ||
|
||
class SummarizeReport | ||
{ | ||
use ToolsHelper; | ||
|
||
protected array $promptHistory = []; | ||
|
||
public function handle(Report $report) | ||
{ | ||
$message = $report->message; | ||
|
||
notify_ui($message->getChat(), 'Building Summary'); | ||
|
||
$response = $this->summarizeReport($report); | ||
|
||
$assistantMessage = $message->getChat()->addInput( | ||
message: $response->content, | ||
role: RoleEnum::Assistant, | ||
systemPrompt: $message->getChat()->getChatable()->systemPrompt(), | ||
show_in_thread: true, | ||
meta_data: $message->meta_data, | ||
tools: $message->tools | ||
); | ||
|
||
$this->savePromptHistory($assistantMessage, | ||
implode("\n", $this->promptHistory)); | ||
|
||
$report->message_id = $assistantMessage->id; | ||
$report->save(); | ||
|
||
notify_ui($message->getChat(), 'Building Solutions list'); | ||
notify_ui_report($report, 'Building Solutions list'); | ||
notify_ui_complete($report->getChat()); | ||
} | ||
|
||
protected function summarizeReport(Report $report): CompletionResponse | ||
{ | ||
$sectionContent = $report->refresh()->sections->pluck('content')->toArray(); | ||
$sectionContent = implode("\n", $sectionContent); | ||
|
||
$prompt = ReportingSummaryPrompt::prompt($sectionContent); | ||
|
||
$this->promptHistory = [$prompt]; | ||
|
||
/** @var CompletionResponse $response */ | ||
$response = LlmDriverFacade::driver( | ||
$report->getChatable()->getDriver() | ||
)->completion($prompt); | ||
|
||
return $response; | ||
} | ||
} |
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
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,40 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Report; | ||
use Facades\LlmLaraHub\LlmDriver\Functions\Reports\SummarizeReport; | ||
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 ReportingToolSummarizeReportJob implements ShouldQueue | ||
{ | ||
use Batchable; | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public Report $report) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
if ($this->batch()->cancelled()) { | ||
// Determine if the batch has been cancelled... | ||
|
||
return; | ||
} | ||
|
||
SummarizeReport::handle($this->report); | ||
} | ||
} |
Oops, something went wrong.