Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
halilcosdu authored and github-actions[bot] committed Sep 14, 2024
1 parent aee92ca commit c8c55be
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/AiServiceDrivers/AiServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class AiServiceManager extends Manager
{
public function createOpenaiDriver(): OpenAiDriver
{
$apiKey = config('slower.open_ai.api_key');
$apiKey = config('slower.open_ai.api_key');
$organization = config('slower.open_ai.organization');
$timeout = config('slower.open_ai.request_timeout', 30);
if ( !is_string($apiKey) || ($organization !== null && !is_string($organization)) ) {
$timeout = config('slower.open_ai.request_timeout', 30);
if (! is_string($apiKey) || ($organization !== null && ! is_string($organization))) {
throw new InvalidArgumentException(
'The OpenAI API Key is missing. Please publish the [slower.php] configuration file and set the [api_key].'
);
Expand All @@ -23,8 +23,9 @@ public function createOpenaiDriver(): OpenAiDriver
->withApiKey($apiKey)
->withOrganization($organization)
->withHttpHeader('OpenAI-Beta', 'assistants=v2')
->withHttpClient(new Client([ 'timeout' => $timeout ]))
->withHttpClient(new Client(['timeout' => $timeout]))
->make();

return new OpenAiDriver($openAI);
}

Expand Down
5 changes: 2 additions & 3 deletions src/AiServiceDrivers/OpenAiDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

class OpenAiDriver implements AiServiceDriver
{
public function __construct(protected Client $client)
{
}
public function __construct(protected Client $client) {}

public function analyze(string $userMessage): ?string
{
Expand All @@ -20,6 +18,7 @@ public function analyze(string $userMessage): ?string
['role' => 'user', 'content' => $userMessage],
],
]);

return $result->choices[0]->message->content ?? null;
}
}
7 changes: 2 additions & 5 deletions src/Services/RecommendationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

class RecommendationService
{
public function __construct(protected AiServiceDriver $aiService)
{

}
public function __construct(protected AiServiceDriver $aiService) {}

public function getRecommendation($record): ?string
{
Expand All @@ -29,7 +26,7 @@ public function getRecommendation($record): ?string

return tap(
$this->aiService->analyze($userMessage),
static fn($result) => $record->update([
static fn ($result) => $record->update([
'is_analyzed' => true,
'recommendation' => $result,
])
Expand Down
3 changes: 0 additions & 3 deletions src/SlowerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
use HalilCosdu\Slower\AiServiceDrivers\Contracts\AiServiceDriver;
use HalilCosdu\Slower\Commands\AnalyzeQuery;
use HalilCosdu\Slower\Commands\SlowLogCleaner;
use HalilCosdu\Slower\Services\RecommendationService;
use Illuminate\Database\Connection;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use InvalidArgumentException;
use OpenAI as OpenAIFactory;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

Expand Down
1 change: 0 additions & 1 deletion tests/SlowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class TestModel extends Illuminate\Database\Eloquent\Model {}
});
});


describe('ai-service', function () {
it('returns an instance of the configured driver', function () {
expect(
Expand Down

0 comments on commit c8c55be

Please sign in to comment.