From 58cd7c403e5ca50e6c5102d65702ca156e58798a Mon Sep 17 00:00:00 2001 From: Davey Shafik Date: Thu, 28 Nov 2024 06:00:31 -0800 Subject: [PATCH] feature: Use PSR-18 compatible wrapper for Laravel HTTP client --- composer.json | 3 ++- src/ServiceProvider.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4caa56a..f52b7c9 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "php": "^8.1.0", "guzzlehttp/guzzle": "^7.9.2", "laravel/framework": "^9.46.0|^10.34.2|^11.29.0", - "openai-php/client": "^0.10.2" + "openai-php/client": "^0.10.2", + "swisnl/laravel-psr-http-client-bridge": "^0.2.0" }, "require-dev": { "laravel/pint": "^1.18.1", diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index a6e6808..b41e050 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -5,6 +5,7 @@ namespace OpenAI\Laravel; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Support\Facades\Http; use Illuminate\Support\ServiceProvider as BaseServiceProvider; use OpenAI; use OpenAI\Client; @@ -34,7 +35,8 @@ public function register(): void ->withApiKey($apiKey) ->withOrganization($organization) ->withHttpHeader('OpenAI-Beta', 'assistants=v2') - ->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)])) + ->withHttpClient(new \Swis\Laravel\Bridge\PsrHttpClient\Client( + fn () => Http::timeout((int) config('openai.request_timeout', 30)))) ->make(); });