From 924a3f9a06f003c1d7c70aa22fb1d0355687758f Mon Sep 17 00:00:00 2001 From: Pavel Buchnev Date: Sun, 1 Sep 2024 17:54:21 +0400 Subject: [PATCH] Fixes Spiral bootloader. Adds missed dependency --- src/Integration/Spiral/OpenAIClientBootloader.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Integration/Spiral/OpenAIClientBootloader.php b/src/Integration/Spiral/OpenAIClientBootloader.php index cf338da..a060684 100644 --- a/src/Integration/Spiral/OpenAIClientBootloader.php +++ b/src/Integration/Spiral/OpenAIClientBootloader.php @@ -4,12 +4,15 @@ namespace LLM\Agents\OpenAI\Client\Integration\Spiral; +use GuzzleHttp\Client as HttpClient; use LLM\Agents\LLM\LLMInterface; use LLM\Agents\OpenAI\Client\LLM; use LLM\Agents\OpenAI\Client\Parsers\ChatResponseParser; use LLM\Agents\OpenAI\Client\StreamResponseParser; +use OpenAI\Contracts\ClientContract; use OpenAI\Responses\Chat\CreateStreamedResponse; use Spiral\Boot\Bootloader\Bootloader; +use Spiral\Boot\EnvironmentInterface; final class OpenAIClientBootloader extends Bootloader { @@ -18,6 +21,18 @@ public function defineSingletons(): array return [ LLMInterface::class => LLM::class, + ClientContract::class => static fn( + EnvironmentInterface $env, + ): ClientContract => \OpenAI::factory() + ->withApiKey($env->get('OPENAI_KEY')) + ->withHttpHeader('OpenAI-Beta', 'assistants=v1') + ->withHttpClient( + new HttpClient([ + 'timeout' => (int) $env->get('OPENAI_HTTP_CLIENT_TIMEOUT', 2 * 60), + ]), + ) + ->make(), + StreamResponseParser::class => static function ( ChatResponseParser $chatResponseParser, ): StreamResponseParser {