From 16e023ea4c70b65d38754365da184c0e2c19a3b7 Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Thu, 1 Aug 2024 22:24:46 -0400 Subject: [PATCH] omg this will simplify a lot of things but it sure is making a lot of changes --- Modules/LlmDriver/app/Functions/CreateDocument.php | 9 +-------- Modules/LlmDriver/app/OllamaClient.php | 1 - .../LlmDriver/app/Responses/ClaudeCompletionResponse.php | 2 +- Modules/LlmDriver/app/Responses/CompletionResponse.php | 2 +- .../LlmDriver/app/Responses/OllamaCompletionResponse.php | 2 +- app/Jobs/ProcessTextFilesJob.php | 6 +++--- app/Models/Document.php | 9 ++++----- app/Models/Message.php | 1 - tests/Feature/Http/Controllers/ChatControllerTest.php | 3 --- tests/Feature/Models/DocumentTest.php | 6 ++++-- tests/Feature/SearchAndSummarizeChatRepoTest.php | 2 +- 11 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Modules/LlmDriver/app/Functions/CreateDocument.php b/Modules/LlmDriver/app/Functions/CreateDocument.php index 600b40d9..7eb3a129 100644 --- a/Modules/LlmDriver/app/Functions/CreateDocument.php +++ b/Modules/LlmDriver/app/Functions/CreateDocument.php @@ -2,17 +2,10 @@ namespace LlmLaraHub\LlmDriver\Functions; -use App\Domains\Documents\StatusEnum; -use App\Domains\Documents\TypesEnum; -use App\Domains\Sources\WebSearch\Response\SearchResponseDto; -use App\Domains\Sources\WebSearch\WebSearchFacade; -use App\Models\Document; -use Facades\App\Domains\Tokenizer\Templatizer; use App\Helpers\ChatHelperTrait; +use App\Models\Document; use App\Models\Message; -use Facades\App\Domains\Sources\WebSearch\GetPage; use Illuminate\Support\Facades\Log; -use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\LlmDriver\Responses\FunctionResponse; use LlmLaraHub\LlmDriver\ToolsHelper; diff --git a/Modules/LlmDriver/app/OllamaClient.php b/Modules/LlmDriver/app/OllamaClient.php index f78ecc28..6194b491 100644 --- a/Modules/LlmDriver/app/OllamaClient.php +++ b/Modules/LlmDriver/app/OllamaClient.php @@ -186,7 +186,6 @@ public function completion(string $prompt): CompletionResponse 'stream' => false, ]); - return OllamaCompletionResponse::from($response->json()); } diff --git a/Modules/LlmDriver/app/Responses/ClaudeCompletionResponse.php b/Modules/LlmDriver/app/Responses/ClaudeCompletionResponse.php index e2622473..304748ad 100644 --- a/Modules/LlmDriver/app/Responses/ClaudeCompletionResponse.php +++ b/Modules/LlmDriver/app/Responses/ClaudeCompletionResponse.php @@ -12,7 +12,7 @@ public function __construct( #[WithCastable(ClaudeContentCaster::class)] public mixed $content, public string|Optional $stop_reason, - public string|null $tool_used = "", + public ?string $tool_used = '', /** @var array */ #[WithCastable(ClaudeToolCaster::class)] #[MapInputName('content')] diff --git a/Modules/LlmDriver/app/Responses/CompletionResponse.php b/Modules/LlmDriver/app/Responses/CompletionResponse.php index ed91de13..b30082df 100644 --- a/Modules/LlmDriver/app/Responses/CompletionResponse.php +++ b/Modules/LlmDriver/app/Responses/CompletionResponse.php @@ -9,7 +9,7 @@ class CompletionResponse extends \Spatie\LaravelData\Data public function __construct( public mixed $content, public string|Optional $stop_reason, - public string|null $tool_used = "", + public ?string $tool_used = '', /** @var array */ public array $tool_calls = [], public ?int $input_tokens = null, diff --git a/Modules/LlmDriver/app/Responses/OllamaCompletionResponse.php b/Modules/LlmDriver/app/Responses/OllamaCompletionResponse.php index 4d1dd669..abc1f769 100644 --- a/Modules/LlmDriver/app/Responses/OllamaCompletionResponse.php +++ b/Modules/LlmDriver/app/Responses/OllamaCompletionResponse.php @@ -12,7 +12,7 @@ public function __construct( public mixed $content, #[MapInputName('done_reason')] public string|Optional $stop_reason, - public string|null $tool_used = "", + public ?string $tool_used = '', /** @var array */ #[MapInputName('message.tool_calls')] public array $tool_calls = [], diff --git a/app/Jobs/ProcessTextFilesJob.php b/app/Jobs/ProcessTextFilesJob.php index 854ebe04..0ae9be19 100644 --- a/app/Jobs/ProcessTextFilesJob.php +++ b/app/Jobs/ProcessTextFilesJob.php @@ -92,10 +92,10 @@ public function handle(): void Bus::batch([ [ new TagDocumentJob($document), - new DocumentProcessingCompleteJob($document) - ] + new DocumentProcessingCompleteJob($document), + ], ]) - ->name("Finalizing Documents") + ->name('Finalizing Documents') ->allowFailures() ->dispatch(); }) diff --git a/app/Models/Document.php b/app/Models/Document.php index c2236dee..d6f5ee9f 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -19,7 +19,6 @@ use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Log; use LlmLaraHub\LlmDriver\HasDrivers; -use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\TagFunction\Contracts\TaggableContract; use LlmLaraHub\TagFunction\Helpers\Taggable; use LlmLaraHub\TagFunction\Jobs\TagDocumentJob; @@ -164,7 +163,7 @@ public static function make( string $content, Collection $collection, ?string $filePath = null - ) : Document { + ): Document { return Document::create([ 'file_path' => $filePath, 'collection_id' => $collection->id, @@ -213,10 +212,10 @@ public function vectorizeDocument(): void [ new SummarizeDocumentJob($document), new TagDocumentJob($document), - new DocumentProcessingCompleteJob($document) - ] + new DocumentProcessingCompleteJob($document), + ], ]) - ->name("Finalizing Documents") + ->name('Finalizing Documents') ->allowFailures() ->dispatch(); }) diff --git a/app/Models/Message.php b/app/Models/Message.php index facd057a..1a5fd176 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -9,7 +9,6 @@ use App\Events\MessageCreatedEvent; use App\Jobs\OrchestrateJob; use App\Jobs\SimpleRetrieveRelatedOrchestrateJob; -use App\Jobs\SimpleSearchAndSummarizeOrchestrateJob; use Facades\App\Domains\Tokenizer\Templatizer; use Illuminate\Bus\Batch; use Illuminate\Database\Eloquent\Factories\HasFactory; diff --git a/tests/Feature/Http/Controllers/ChatControllerTest.php b/tests/Feature/Http/Controllers/ChatControllerTest.php index f4c520f5..2bf78915 100644 --- a/tests/Feature/Http/Controllers/ChatControllerTest.php +++ b/tests/Feature/Http/Controllers/ChatControllerTest.php @@ -11,7 +11,6 @@ use App\Models\User; use Facades\App\Domains\Agents\VerifyResponseAgent; use Facades\LlmLaraHub\LlmDriver\Orchestrate; -use Illuminate\Support\Facades\Bus; use LlmLaraHub\LlmDriver\LlmDriverFacade; use LlmLaraHub\LlmDriver\Responses\CompletionResponse; use Tests\TestCase; @@ -178,8 +177,6 @@ public function test_kick_off_chat_makes_system() } - - public function test_standard_checker() { Orchestrate::shouldReceive('handle')->once()->andReturn('Yo'); diff --git a/tests/Feature/Models/DocumentTest.php b/tests/Feature/Models/DocumentTest.php index 09e581f4..b5c2d088 100644 --- a/tests/Feature/Models/DocumentTest.php +++ b/tests/Feature/Models/DocumentTest.php @@ -37,7 +37,8 @@ public function test_parent() $model->parent->id); } - public function test_document_make() { + public function test_document_make() + { $collection = \App\Models\Collection::factory()->create(); $document = Document::make('Foo bar', $collection); @@ -48,7 +49,8 @@ public function test_document_make() { $this->assertNotNull($document->collection->documents()->first()->id); } - public function test_document_vectorize() { + public function test_document_vectorize() + { Bus::fake(); $collection = \App\Models\Collection::factory()->create(); $document = Document::make('Foo bar', diff --git a/tests/Feature/SearchAndSummarizeChatRepoTest.php b/tests/Feature/SearchAndSummarizeChatRepoTest.php index 6ab08f65..fb7bbc8d 100644 --- a/tests/Feature/SearchAndSummarizeChatRepoTest.php +++ b/tests/Feature/SearchAndSummarizeChatRepoTest.php @@ -4,8 +4,8 @@ use App\Domains\Agents\VerifyPromptOutputDto; use App\Domains\Chat\MetaDataDto; -use App\Domains\Messages\RoleEnum; use App\Domains\Messages\RetrieveRelatedChatRepo; +use App\Domains\Messages\RoleEnum; use App\Models\Chat; use App\Models\Collection; use App\Models\Document;