Skip to content

Commit

Permalink
Merge branch 'feature/laravel-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Sep 1, 2024
2 parents fbc3e44 + 924a3f9 commit 3ff8f6d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Integration/Spiral/OpenAIClientBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 {
Expand Down

0 comments on commit 3ff8f6d

Please sign in to comment.