From 82104f5bc6652f112cf0a293fbcfd73a7a61393f Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Tue, 9 Jul 2024 14:44:18 -0400 Subject: [PATCH] making progress on the reporting tool --- .../LlmDriver/app/Functions/ReportingTool.php | 17 +++++++---------- Modules/LlmDriver/app/LlmDriverClient.php | 3 ++- Modules/LlmDriver/app/LlmServiceProvider.php | 1 - Modules/LlmDriver/app/Orchestrate.php | 2 -- app/Http/Middleware/HandleInertiaRequests.php | 1 - app/Models/Message.php | 4 ++-- .../2024_07_09_170405_create_sections_table.php | 8 ++++---- tests/Feature/Models/SectionTest.php | 2 -- tests/Feature/OrchestrateTest.php | 2 +- tests/Feature/ReportingToolTest.php | 7 ++----- 10 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Modules/LlmDriver/app/Functions/ReportingTool.php b/Modules/LlmDriver/app/Functions/ReportingTool.php index ee975b5f..71a3db76 100644 --- a/Modules/LlmDriver/app/Functions/ReportingTool.php +++ b/Modules/LlmDriver/app/Functions/ReportingTool.php @@ -3,14 +3,12 @@ namespace LlmLaraHub\LlmDriver\Functions; use App\Domains\Prompts\ReportBuildingFindRequirementsPrompt; -use App\Domains\Prompts\StandardsCheckerPrompt; use App\Domains\Reporting\ReportTypeEnum; use App\Models\Message; use App\Models\Report; use App\Models\Section; use Illuminate\Support\Facades\Log; use LlmLaraHub\LlmDriver\LlmDriverFacade; -use LlmLaraHub\LlmDriver\Requests\MessageInDto; use LlmLaraHub\LlmDriver\Responses\FunctionResponse; class ReportingTool extends FunctionContract @@ -51,14 +49,13 @@ public function handle( 'type' => ReportTypeEnum::RFP, ]); - $documents = $message->getChatable()->documents; notify_ui($message->getChat(), 'Going through all the documents to check requirements'); $this->results = []; - foreach($documents->chunk(3) as $index => $databaseChunk) { + foreach ($documents->chunk(3) as $index => $databaseChunk) { try { $prompts = []; $documents = []; @@ -89,17 +86,17 @@ public function handle( //make the sections per the results coming back. $content = $result->content; $content = json_decode($content, true); - foreach($content as $sectionIndex =>$sectionText) { - $title = data_get($sectionText, 'title', "NOT TITLE GIVEN"); - $content = data_get($sectionText, 'content', "NOT CONTENT GIVEN"); + foreach ($content as $sectionIndex => $sectionText) { + $title = data_get($sectionText, 'title', 'NOT TITLE GIVEN'); + $content = data_get($sectionText, 'content', 'NOT CONTENT GIVEN'); $section = Section::updateOrCreate([ 'document_id' => $document->id, 'report_id' => $report->id, 'sort_order' => $sectionIndex, - ],[ - 'subject' => $title, - 'content' => $content, + ], [ + 'subject' => $title, + 'content' => $content, ]); } diff --git a/Modules/LlmDriver/app/LlmDriverClient.php b/Modules/LlmDriver/app/LlmDriverClient.php index 1a9d476a..34b7534c 100644 --- a/Modules/LlmDriver/app/LlmDriverClient.php +++ b/Modules/LlmDriver/app/LlmDriverClient.php @@ -67,9 +67,10 @@ public function getFunctions(): array public function getFunctionsForUi(): array { return collect($this->getFunctions()) - ->map(function($item) { + ->map(function ($item) { $item = $item->toArray(); $item['name_formatted'] = str($item['name'])->headline()->toString(); + return $item; })->toArray(); } diff --git a/Modules/LlmDriver/app/LlmServiceProvider.php b/Modules/LlmDriver/app/LlmServiceProvider.php index d4b9c2cd..0b8c39cb 100644 --- a/Modules/LlmDriver/app/LlmServiceProvider.php +++ b/Modules/LlmDriver/app/LlmServiceProvider.php @@ -73,7 +73,6 @@ public function boot(): void return new ReportingTool(); }); - } /** diff --git a/Modules/LlmDriver/app/Orchestrate.php b/Modules/LlmDriver/app/Orchestrate.php index 2db0e0be..5eb5d760 100644 --- a/Modules/LlmDriver/app/Orchestrate.php +++ b/Modules/LlmDriver/app/Orchestrate.php @@ -9,7 +9,6 @@ use App\Models\Message; use App\Models\PromptHistory; use Facades\App\Domains\Messages\SearchAndSummarizeChatRepo; -use Facades\LlmLaraHub\LlmDriver\Functions\StandardsChecker; use Illuminate\Support\Facades\Log; use LlmLaraHub\LlmDriver\Functions\FunctionCallDto; use LlmLaraHub\LlmDriver\Helpers\CreateReferencesTrait; @@ -44,7 +43,6 @@ public function handle( */ $messagesArray = $message->getLatestMessages(); - $filter = $message->meta_data?->filter; if ($filter) { diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index f590da4d..c12c4140 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -6,7 +6,6 @@ use Illuminate\Http\Request; use Inertia\Middleware; use Laravel\Pennant\Feature; -use LlmLaraHub\LlmDriver\LlmDriverClient; use LlmLaraHub\LlmDriver\LlmDriverFacade; class HandleInertiaRequests extends Middleware diff --git a/app/Models/Message.php b/app/Models/Message.php index 2e032baa..6e1e32bf 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -158,11 +158,11 @@ public function getChat(): ?Chat return $this->chat; } - public function getReferenceCollection() : ?Collection + public function getReferenceCollection(): ?Collection { $id = data_get($this->meta_data, 'reference_collection_id', null); - if($id) { + if ($id) { return Collection::find($id); } diff --git a/database/migrations/2024_07_09_170405_create_sections_table.php b/database/migrations/2024_07_09_170405_create_sections_table.php index 6577f1ee..2880729d 100644 --- a/database/migrations/2024_07_09_170405_create_sections_table.php +++ b/database/migrations/2024_07_09_170405_create_sections_table.php @@ -13,10 +13,10 @@ public function up(): void { Schema::create('sections', function (Blueprint $table) { $table->id(); - $table->string("subject")->nullable(); - $table->longText("content")->nullable(); - $table->longText("response")->nullable(); - $table->integer("sort_order")->default(0); + $table->string('subject')->nullable(); + $table->longText('content')->nullable(); + $table->longText('response')->nullable(); + $table->integer('sort_order')->default(0); $table->foreignIdFor(\App\Models\Report::class)->constrained()->onDelete('cascade'); $table->foreignIdFor(\App\Models\Document::class)->constrained()->onDelete('cascade'); $table->timestamps(); diff --git a/tests/Feature/Models/SectionTest.php b/tests/Feature/Models/SectionTest.php index 5e79c3ae..e5c53f4a 100644 --- a/tests/Feature/Models/SectionTest.php +++ b/tests/Feature/Models/SectionTest.php @@ -2,8 +2,6 @@ namespace Tests\Feature\Models; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; class SectionTest extends TestCase diff --git a/tests/Feature/OrchestrateTest.php b/tests/Feature/OrchestrateTest.php index 261fb341..701e1047 100644 --- a/tests/Feature/OrchestrateTest.php +++ b/tests/Feature/OrchestrateTest.php @@ -9,9 +9,9 @@ use App\Models\Message; use App\Models\User; use Facades\App\Domains\Messages\SearchAndSummarizeChatRepo; -use LlmLaraHub\LlmDriver\Functions\StandardsChecker; use Illuminate\Support\Facades\Event; use LlmLaraHub\LlmDriver\Functions\SearchAndSummarize; +use LlmLaraHub\LlmDriver\Functions\StandardsChecker; use LlmLaraHub\LlmDriver\Functions\SummarizeCollection; use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\LlmDriver\Orchestrate; diff --git a/tests/Feature/ReportingToolTest.php b/tests/Feature/ReportingToolTest.php index f53ea9d8..38b59588 100644 --- a/tests/Feature/ReportingToolTest.php +++ b/tests/Feature/ReportingToolTest.php @@ -9,7 +9,6 @@ use LlmLaraHub\LlmDriver\Functions\ParametersDto; use LlmLaraHub\LlmDriver\Functions\PropertyDto; use LlmLaraHub\LlmDriver\Functions\ReportingTool; -use LlmLaraHub\LlmDriver\Functions\StandardsChecker; use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\LlmDriver\Requests\MessageInDto; use LlmLaraHub\LlmDriver\Responses\CompletionResponse; @@ -93,15 +92,14 @@ public function test_asks() Document::factory(5) ->has(DocumentChunk::factory(), 'document_chunks') ->create([ - 'collection_id' => $collection->id, - ]); + 'collection_id' => $collection->id, + ]); $chat = \App\Models\Chat::factory()->create([ 'chatable_type' => Collection::class, 'chatable_id' => $collection->id, ]); - $functionCallDto = \LlmLaraHub\LlmDriver\Functions\FunctionCallDto::from([ 'function_name' => 'reporting_tool', 'arguments' => json_encode([ @@ -170,7 +168,6 @@ public function test_builds_up_sections() 'chatable_id' => $collection->id, ]); - $functionCallDto = \LlmLaraHub\LlmDriver\Functions\FunctionCallDto::from([ 'function_name' => 'reporting_tool', 'arguments' => json_encode([