Skip to content

Commit

Permalink
Merge pull request #1 from 5am-code/analysis-e0QjGa
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
mechelon authored Jun 18, 2024
2 parents 055ab6a + 37ecfc1 commit 0e1fa49
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions database/migrations/2024_04_17_162758_activate_pgvector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/AdaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function register()
], 'ada-views');

$this->app->singleton('ada', function () {
return new Ada;
return new Ada();
});

$this->validateIndexClass();
Expand All @@ -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.");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
10 changes: 5 additions & 5 deletions src/Models/Embedding.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/Prompts/OpenAIPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public function toArray(): array
{
return [
[
'role' => 'system',
'role' => 'system',
'content' => $this->template,
],
[
'role' => 'user',
'role' => 'user',
'content' => $this->query,
],
];
Expand Down
10 changes: 3 additions & 7 deletions tests/OpenAIEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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.');


});

0 comments on commit 0e1fa49

Please sign in to comment.