Skip to content

Commit

Permalink
making progress on the reporting tool
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jul 9, 2024
1 parent 12d6611 commit 82104f5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 29 deletions.
17 changes: 7 additions & 10 deletions Modules/LlmDriver/app/Functions/ReportingTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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,
]);
}

Expand Down
3 changes: 2 additions & 1 deletion Modules/LlmDriver/app/LlmDriverClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion Modules/LlmDriver/app/LlmServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function boot(): void
return new ReportingTool();
});


}

/**
Expand Down
2 changes: 0 additions & 2 deletions Modules/LlmDriver/app/Orchestrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +43,6 @@ public function handle(
*/
$messagesArray = $message->getLatestMessages();


$filter = $message->meta_data?->filter;

if ($filter) {
Expand Down
1 change: 0 additions & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions tests/Feature/Models/SectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/OrchestrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions tests/Feature/ReportingToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit 82104f5

Please sign in to comment.