Skip to content

Commit

Permalink
oops style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 19, 2024
1 parent bd1e901 commit 442b12e
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 38 deletions.
2 changes: 0 additions & 2 deletions Modules/LlmDriver/app/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ public function getFunctions(): array
{
$functions = LlmDriverFacade::getFunctions();



return collect($functions)->map(function ($function) {
$function = $function->toArray();
$properties = [];
Expand Down
31 changes: 9 additions & 22 deletions Modules/LlmDriver/app/Functions/SearchAndSummarize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
namespace LlmLaraHub\LlmDriver\Functions;

use App\Domains\Messages\RoleEnum;
use LlmLaraHub\LlmDriver\HasDrivers;
use LlmLaraHub\LlmDriver\Responses\FunctionResponse;
use App\Models\Chat;
use App\Models\DocumentChunk;
use Illuminate\Contracts\Container\BindingResolutionException;
use Exception;
use Illuminate\Support\Facades\Log;
use Laravel\Pennant\Feature;
use LlmLaraHub\LlmDriver\HasDrivers;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use LlmLaraHub\LlmDriver\Requests\MessageInDto;
use LlmLaraHub\LlmDriver\Responses\CompletionResponse;
use LlmLaraHub\LlmDriver\Responses\EmbeddingsResponseDto;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Container\ContainerExceptionInterface;
use Spatie\LaravelData\Exceptions\MaxTransformationDepthReached;
use Spatie\LaravelData\Exceptions\CannotCreateData;
use Spatie\LaravelData\Exceptions\CannotSetComputedValue;
use LlmLaraHub\LlmDriver\Responses\FunctionResponse;

class SearchAndSummarize extends FunctionContract
{
Expand All @@ -28,11 +20,7 @@ class SearchAndSummarize extends FunctionContract
protected string $description = 'Used to embed users prompt, search database and return summarized results.';

/**
*
* @param MessageInDto[] $messageArray
* @param HasDrivers $model
* @param FunctionCallDto $functionCallDto
* @return FunctionResponse
* @param MessageInDto[] $messageArray
*/
public function handle(
array $messageArray,
Expand All @@ -43,12 +31,11 @@ public function handle(
* @TODO
*
* @see https://github.com/orgs/LlmLaraHub/projects/1/views/1?pane=issue&itemId=59671259
*
* @TODO
*
* @TODO
* Should I break up the string using the LLM to make the search better?
*
*/
$input = collect($messageArray)->first(function($item) {
$input = collect($messageArray)->first(function ($item) {
return $item->role === 'user';
});

Expand All @@ -61,10 +48,10 @@ public function handle(

$embeddingSize = get_embedding_size($model->getEmbeddingDriver());


/**
* @TODO
* @TODO
* Track the document page for referehce
*
* @see https://github.com/orgs/LlmLaraHub/projects/1?pane=issue&itemId=60394288
*/
$results = DocumentChunk::query()
Expand Down Expand Up @@ -121,7 +108,7 @@ public function handle(
return FunctionResponse::from(
[
'content' => $content,
'save_to_message' => false
'save_to_message' => false,
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/LlmDriver/app/HasDrivers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getId(): int;

public function getType(): string;

public function getChatable() : HasDrivers;
public function getChatable(): HasDrivers;

public function getChat() : Chat;
public function getChat(): Chat;
}
2 changes: 1 addition & 1 deletion Modules/LlmDriver/app/Orchestrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(array $messagesArray, Chat $chat): ?string
/** @var FunctionResponse $response */
$response = $functionClass->handle($messagesArray, $chat, $functionDto);

if($response->save_to_message) {
if ($response->save_to_message) {
$chat->addInput(
message: $response->content,
role: RoleEnum::Assistant,
Expand Down
3 changes: 2 additions & 1 deletion app/Domains/Messages/SearchAndSummarizeChatRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public function search(Chat $chat, string $input): string
$embeddingSize = get_embedding_size($chat->chatable->getEmbeddingDriver());

/**
* @TODO
* @TODO
* Track the document page for referehce
*
* @see https://github.com/orgs/LlmLaraHub/projects/1?pane=issue&itemId=60394288
*/
$results = DocumentChunk::query()
Expand Down
9 changes: 5 additions & 4 deletions app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class Collection extends Model implements HasDrivers, TaggableContract
'embedding_driver' => DriversEnum::class,
];

public function getChatable(): HasDrivers {
return $this;
public function getChatable(): HasDrivers
{
return $this;
}

public function team(): BelongsTo
Expand All @@ -50,8 +51,8 @@ public function team(): BelongsTo
public function getChat(): Chat
{
/**
* @TODO
* I need to come back to this
* @TODO
* I need to come back to this
*/
return $this->chats()->first();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function getType(): string
public function getChat(): Chat
{
/**
* @TODO
* I need to come back to this
* @TODO
* I need to come back to this
*/
return $this->collection->chats()->first();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/DocumentChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function getChatable(): HasDrivers
public function getChat(): Chat
{
/**
* @TODO
* I need to come back to this
* @TODO
* I need to come back to this
*/
return $this->document->collection->chats()->first();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/SearchAndSummarizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use LlmLaraHub\LlmDriver\Functions\SearchAndSummarize;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use LlmLaraHub\LlmDriver\Requests\MessageInDto;
use LlmLaraHub\LlmDriver\Responses\CompletionResponse;
use Tests\TestCase;

class SearchAndSummarizeTest extends TestCase
Expand All @@ -32,7 +31,8 @@ public function test_can_generate_function_as_array(): void
$this->assertInstanceOf(PropertyDto::class, $parameters->properties[0]);
}

public function test_gets_user_input() {
public function test_gets_user_input()
{
$messageArray = [];

$messageArray[] = MessageInDto::from([
Expand Down

0 comments on commit 442b12e

Please sign in to comment.