From 37ecfc1326ba880488f7dd0010c30940383ad9a9 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 18 Jun 2024 15:56:44 +0000 Subject: [PATCH] Apply fixes from StyleCI --- .../migrations/2024_04_17_162758_activate_pgvector.php | 3 +-- .../2024_04_18_162859_create_embeddings_table.php | 3 +-- src/AdaServiceProvider.php | 4 ++-- src/Engine/OpenAI.php | 4 ++-- src/Models/Embedding.php | 10 +++++----- src/Tools/Prompts/OpenAIPrompt.php | 4 ++-- tests/OpenAIEngineTest.php | 10 +++------- 7 files changed, 16 insertions(+), 22 deletions(-) diff --git a/database/migrations/2024_04_17_162758_activate_pgvector.php b/database/migrations/2024_04_17_162758_activate_pgvector.php index fd48c58..e1fe7b2 100644 --- a/database/migrations/2024_04_17_162758_activate_pgvector.php +++ b/database/migrations/2024_04_17_162758_activate_pgvector.php @@ -2,8 +2,7 @@ use Illuminate\Database\Migrations\Migration; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. */ diff --git a/database/migrations/2024_04_18_162859_create_embeddings_table.php b/database/migrations/2024_04_18_162859_create_embeddings_table.php index 5bb9662..a61dd15 100644 --- a/database/migrations/2024_04_18_162859_create_embeddings_table.php +++ b/database/migrations/2024_04_18_162859_create_embeddings_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class() extends Migration { /** * Run the migrations. */ diff --git a/src/AdaServiceProvider.php b/src/AdaServiceProvider.php index bff342d..4ac8ee9 100644 --- a/src/AdaServiceProvider.php +++ b/src/AdaServiceProvider.php @@ -43,7 +43,7 @@ public function register() ], 'ada-views'); $this->app->singleton('ada', function () { - return new Ada; + return new Ada(); }); $this->validateIndexClass(); @@ -62,7 +62,7 @@ protected function validateIndexClass() $indexClass = config('ada.index_class', \Ada\Index\DefaultIndex::class); $reflection = new \ReflectionClass($indexClass); - if (! $reflection->isSubclassOf(Index::class)) { + if (!$reflection->isSubclassOf(Index::class)) { throw new Exception("Index class has to implement \Ada\Index\Index."); } } diff --git a/src/Engine/OpenAI.php b/src/Engine/OpenAI.php index ef3a1cf..7d1c3d4 100644 --- a/src/Engine/OpenAI.php +++ b/src/Engine/OpenAI.php @@ -40,8 +40,8 @@ public function generate(Prompt $prompt, string $model = 'gpt-3.5-turbo', int $t { try { $result = $this->client->chat()->create([ - 'model' => $model, - 'messages' => $prompt->toArray(), + 'model' => $model, + 'messages' => $prompt->toArray(), 'temperature' => $temperature, ...$options, ]); diff --git a/src/Models/Embedding.php b/src/Models/Embedding.php index fd2b85b..92d0b28 100644 --- a/src/Models/Embedding.php +++ b/src/Models/Embedding.php @@ -28,9 +28,9 @@ public function embeddable() } /** - * @param string $query The query to lookup. - * @param Prompt|null $contextPrompt The prompt to use for the context, in case a custom template is necessary. - * @param Closure|null $additionalConstraints Limit the lookup by providing a query. + * @param string $query The query to lookup. + * @param Prompt|null $contextPrompt The prompt to use for the context, in case a custom template is necessary. + * @param Closure|null $additionalConstraints Limit the lookup by providing a query. * * @throws \Illuminate\Contracts\Container\BindingResolutionException */ @@ -65,8 +65,8 @@ public static function lookup(string $query, ?Prompt $contextPrompt = null, ?Clo } /** - * @param Vector $vector The vector to compare to - * @param Closure|null $additionalConstraints Limit the search further by providing a query. + * @param Vector $vector The vector to compare to + * @param Closure|null $additionalConstraints Limit the search further by providing a query. */ public static function getNearestNeighbor(Vector $vector, ?Closure $additionalConstraints = null): ?Embedding { diff --git a/src/Tools/Prompts/OpenAIPrompt.php b/src/Tools/Prompts/OpenAIPrompt.php index a397892..908b975 100644 --- a/src/Tools/Prompts/OpenAIPrompt.php +++ b/src/Tools/Prompts/OpenAIPrompt.php @@ -8,11 +8,11 @@ public function toArray(): array { return [ [ - 'role' => 'system', + 'role' => 'system', 'content' => $this->template, ], [ - 'role' => 'user', + 'role' => 'user', 'content' => $this->query, ], ]; diff --git a/tests/OpenAIEngineTest.php b/tests/OpenAIEngineTest.php index 7a66b20..b7cbdaf 100644 --- a/tests/OpenAIEngineTest.php +++ b/tests/OpenAIEngineTest.php @@ -27,11 +27,10 @@ ->and($response->getContent())->toBe(json_encode([-0.025455512, 0.004357308, -0.023832073])) ->and($response->tokenUsage)->toBe([ 'prompt_tokens' => 41, - 'total_tokens' => 41, + 'total_tokens' => 41, ]); }); - it('creates an GeneratedResponse from a Open AI JSON chat response', function () { $response = json_decode(file_get_contents('tests/fixtures/openai_200_query.json'), true); @@ -46,14 +45,13 @@ ->and($response->model)->toBe('gpt-3.5-turbo-0125') ->and($response->getContent())->toStartWith("The habitat of the PHP Elephant is referred to as 'Silicon Forests'.") ->and($response->tokenUsage)->toBe([ - 'prompt_tokens' => 13, + 'prompt_tokens' => 13, 'completion_tokens' => 9, - 'total_tokens' => 22, + 'total_tokens' => 22, ]); }); it('creates an ErrorResponse from a failed Open AI request', function () { - $exceptionContent = json_decode(file_get_contents('tests/fixtures/openai_failed.json'), true); $exception = new \OpenAI\Exceptions\ErrorException($exceptionContent, 500); @@ -63,6 +61,4 @@ ->and($response->engine)->toBe(\Ada\Engine\OpenAI::class) ->and($response->success)->toBeFalse() ->and($response->getContent())->toStartWith('Error: Incorrect API key provided: abc.'); - - });