1tomany / llm-sdk-bundle
Symfony bundle that provides bindings for the 1tomany/llm-sdk package
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/1tomany/llm-sdk-bundle
Requires
- php: >=8.4
- 1tomany/llm-sdk: ^0.2.0
- symfony/config: ^7.2|^8.0
- symfony/dependency-injection: ^7.2|^8.0
- symfony/http-kernel: ^7.2|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.93
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.5
README
This package wraps the 1tomany/llm-sdk library into an easy to use Symfony bundle.
Installation
Install the bundle using Composer:
composer require 1tomany/llm-sdk-bundle
Configuration
Below is the complete configuration for this bundle. To customize it for your Symfony application, create a file named llm_sdk.yaml in config/packages/ and make the necessary changes.
llm_sdk: claude: api_key: '%env(CLAUDE_API_KEY)%' http_client: 'http_client' serializer: 'serializer' gemini: api_key: '%env(GEMINI_API_KEY)%' http_client: 'http_client' serializer: 'serializer' openai: api_key: '%env(OPENAI_API_KEY)%' http_client: 'http_client' serializer: 'serializer' when@dev: llm_sdk: mock: enabled: true
By default, the http_client and serializer properties in the claude, gemini and openai blocks use the @http_client and @serializer services defined in a standard Symfony application. You're free to use your own scoped HTTP client or serializer services.
If you wish to disable a vendor, simply delete the configuration block from the file. For example, if your application only uses Gemini, you would delete the claude and openai blocks, leaving you with:
llm_sdk: gemini: api_key: '%env(GEMINI_API_KEY)%'
You'll also have to define the API keys in your .env file or by using the Symfony Secrets component.
Usage
Any action interface can be injected into a service. Because you can have multiple clients loaded in at once, the model passed into the request dictates what client to use. This makes it very easy to allow your users to select amongst any client supported by the core 1tomany/llm-sdk library.
<?php namespace App\File\Action\Handler; use OneToMany\LlmSdk\Contract\Action\File\UploadFileActionInterface; use OneToMany\LlmSdk\Contract\Action\Query\ExecuteQueryActionInterface; use function mime_content_type; final readonly class QueryFileHandler { public function __construct( private UploadFileActionInterface $uploadFileAction, private ExecuteQueryActionInterface $executeQueryAction, ) { } public function __invoke(string $path, string $prompt): void { $model = 'gemini-2.5-flash'; /** * @var non-empty-lowercase-string $format */ $format = mime_content_type($path); // Upload the file to cache it with the model $uploadRequest = new UploadRequest($model) ->atPath($path) ->withFormat($format); $response = $this->uploadFileAction->act(...[ 'request' => $uploadRequest, ]); // $response instanceof OneToMany\LlmSdk\Response\File\UploadResponse $fileUri = $response->getUri(); // Compile and execute a query using the file $compileRequest = new CompileRequest($model) ->withText($prompt) ->withFileUri($fileUri, $format); $response = $this->executeQueryAction->act(...[ 'request' => $compileRequest, ]); // $response instanceof OneToMany\LlmSdk\Response\Query\ExecuteResponse printf("Model output: %s\n", $response->getOutput()); } }
Credits
License
The MIT License