From 6c70a13d8d7c2f9a0faab0d311871e1b886778e1 Mon Sep 17 00:00:00 2001 From: Adeniji Adekunle James Date: Fri, 4 Jul 2025 09:19:38 +0100 Subject: [PATCH 01/14] Moves model to 4o-mini as it is cheaper and typically better than 3.5 (#29) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8434328..3d6e4d3 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Finally, you may use the `openai` service to access the OpenAI API: ```php $result = $container->get('openai')->completions()->create([ - 'model' => 'gpt-3.5-turbo-instruct', + 'model' => 'gpt-4o-mini', 'prompt' => 'PHP is', ]); From 8b548efd712b48cdc8e7f88442bf1099e99c1c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen?= Date: Tue, 12 Aug 2025 11:26:55 +0200 Subject: [PATCH 02/14] Bump openai-php/client to 0.15 (#30) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8a72cd7..2cb1e96 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^8.2.0", "nyholm/psr7": "^1.8.2", - "openai-php/client": "^0.13.0", + "openai-php/client": "^0.15.0", "psr/http-client": "^1.0.3", "psr/http-factory": "^1.1.0", "symfony/config": "^5.4|^6.3|^7.1.1", From 48600287744726751d61eda73a07a372de8d5ae9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Aug 2025 11:07:30 +0200 Subject: [PATCH 03/14] chore(deps): bump actions/checkout from 4 to 5 (#31) Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/formats.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/formats.yml b/.github/workflows/formats.yml index 5440721..d858f6a 100644 --- a/.github/workflows/formats.yml +++ b/.github/workflows/formats.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Cache dependencies uses: actions/cache@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d514d65..a434b17 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Cache dependencies uses: actions/cache@v4 From f3322ceb4474378cab33d5d8d1f5e2bcfe54d13f Mon Sep 17 00:00:00 2001 From: Anne van de Venis Date: Thu, 4 Sep 2025 21:02:05 +0200 Subject: [PATCH 04/14] deps: update openai-php/client v0.16 (#32) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2cb1e96..b79a0fb 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^8.2.0", "nyholm/psr7": "^1.8.2", - "openai-php/client": "^0.15.0", + "openai-php/client": "^0.16.0", "psr/http-client": "^1.0.3", "psr/http-factory": "^1.1.0", "symfony/config": "^5.4|^6.3|^7.1.1", From 31ec4c4696e74a9b9b9375ac8d4ad55ae9deb144 Mon Sep 17 00:00:00 2001 From: Anne van de Venis Date: Thu, 2 Oct 2025 15:21:45 +0200 Subject: [PATCH 05/14] deps: update openai-php/client v0.17 (#34) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b79a0fb..7639d3a 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^8.2.0", "nyholm/psr7": "^1.8.2", - "openai-php/client": "^0.16.0", + "openai-php/client": "^0.17.0", "psr/http-client": "^1.0.3", "psr/http-factory": "^1.1.0", "symfony/config": "^5.4|^6.3|^7.1.1", From cc47eb662f07a10e9bd839807036cbc372d4985e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 2 Oct 2025 15:32:54 +0200 Subject: [PATCH 06/14] Refactor as a single-class bundle (#33) --- .github/workflows/tests.yml | 40 +++----- .gitignore | 1 + CHANGELOG.md | 7 ++ README.md | 14 +++ composer.json | 19 ++-- rector.php | 11 ++- src/DependencyInjection/Configuration.php | 36 -------- src/DependencyInjection/OpenAIExtension.php | 39 -------- src/OpenAIBundle.php | 74 ++++++++++++++- src/Resources/config/services.php | 28 ------ .../OpenAIExtensionTest.php | 52 ----------- tests/OpenAIBundleTest.php | 91 +++++++++++++++++++ 12 files changed, 216 insertions(+), 196 deletions(-) delete mode 100644 src/DependencyInjection/Configuration.php delete mode 100644 src/DependencyInjection/OpenAIExtension.php delete mode 100644 src/Resources/config/services.php delete mode 100644 tests/DependencyInjection/OpenAIExtensionTest.php create mode 100644 tests/OpenAIBundleTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a434b17..87668e5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,45 +10,33 @@ jobs: fail-fast: true matrix: php: [8.2, 8.3, 8.4] - symfony: [5.4.*, 6.4.*, 7.0.*] - dependency-version: [prefer-lowest, prefer-stable] - exclude: - - php: 8.4 - symfony: 5.4.* - - php: 8.4 - symfony: 6.4.* - - php: 8.4 - symfony: 7.0.* - - name: Tests P${{ matrix.php }} - SF${{ matrix.symfony }} - ubuntu-latest - ${{ matrix.dependency-version }} + symfony: [^6.4, false] + dependency: [stable] + include: + - { php: 8.4, symfony: ^7.4, dependency: highest } + - { php: 8.4, symfony: ^8.0, dependency: highest } + + env: + SYMFONY_REQUIRE: ${{ matrix.symfony }} + + name: Tests P${{ matrix.php }} - SF${{ matrix.symfony }} - ubuntu-latest - ${{ matrix.dependency }} steps: - name: Checkout uses: actions/checkout@v5 - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.composer/cache/files - key: dependencies-php-${{ matrix.php }}-SF${{ matrix.symfony }}-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }} - - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, mbstring, zip coverage: none - - - name: Require Symfony Version - run: > - composer require - "symfony/config:${{ matrix.symfony }}" - "symfony/dependency-injection:${{ matrix.symfony }}" - "symfony/http-kernel:${{ matrix.symfony }}" - --no-interaction --no-update + tools: flex - name: Install Composer dependencies - run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist + uses: ramsey/composer-install@v2 + with: + dependency-versions: ${{ matrix.dependency }} - name: Integration Tests run: php ./vendor/bin/simple-phpunit diff --git a/.gitignore b/.gitignore index 8e954e3..9b27164 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ /composer.lock /phpunit.xml /vendor/ +/var/ *.swp *.swo diff --git a/CHANGELOG.md b/CHANGELOG.md index 22f06ac..2d7b52c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## v0.17.0 +### Changed +- Refactored into a single `OpenAI\Symfony\OpenAIBundle` class +- Add `project` and `base_uri` configuration options +- Drop support for unsupported Symfony versions. Now requires Symfony 6.4 or 7.3+ +- Add support for Symfony 8.0 + ## v0.12.0 (2025-05-06) ### Changed - Changed underlying `openai/client` package version to 0.12.0 diff --git a/README.md b/README.md index 3d6e4d3..e8fbc1b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,8 @@ OPENAI_API_KEY=sk-... OPENAI_ORGANIZATION=... ``` +For more configuration options, take a look at the [Configuration Reference](#configuration-reference). + Finally, you may use the `openai` service to access the OpenAI API: ```php @@ -57,6 +59,18 @@ echo $result['choices'][0]['text']; // an open-source, widely-used, server-side For usage examples, take a look at the [openai-php/client](https://github.com/openai-php/client) repository. +## Configuration Reference + +The bundle provides the following configuration options, which you can set in your `config/packages/openai.yaml` file: + +```yaml +openai: + api_key: '%env(OPENAI_API_KEY)%' # Your OpenAI API key (required) + organization: '%env(OPENAI_ORGANIZATION)%' # Your OpenAI organization ID (optional) + project: 'proj_...' # The project ID (optional) + base_uri: 'api.openai.com/v1' # The base URI for the OpenAI API (optional) +``` + --- OpenAI PHP for Symfony is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**. diff --git a/composer.json b/composer.json index 7639d3a..e7b26ce 100644 --- a/composer.json +++ b/composer.json @@ -20,16 +20,17 @@ "openai-php/client": "^0.17.0", "psr/http-client": "^1.0.3", "psr/http-factory": "^1.1.0", - "symfony/config": "^5.4|^6.3|^7.1.1", - "symfony/dependency-injection": "^5.4|^6.3|^7.1.5", - "symfony/http-client": "^5.4|^6.3|^7.1.5", - "symfony/http-kernel": "^5.4|^6.3|^7.1.5" + "symfony/config": "^6.4|^7.3|^8.0", + "symfony/dependency-injection": "^6.4|^7.3|^8.0", + "symfony/http-client": "^6.4|^7.3|^8.0", + "symfony/http-kernel": "^6.4|^7.3|^8.0" }, "require-dev": { - "laravel/pint": "^1.18.1", - "phpstan/phpstan": "^1.12.6", - "rector/rector": "^0.14.8", - "symfony/phpunit-bridge": "^5.4|^6.3|^7.1.4" + "laravel/pint": "^1.24.0", + "phpstan/phpstan": "^2.1.22", + "rector/rector": "^2.1.5", + "symfony/phpunit-bridge": "^6.4.25|^7.3|^8.0", + "symfony/framework-bundle": "^6.4|^7.3|^8.0" }, "autoload": { "psr-4": { @@ -53,7 +54,7 @@ "scripts": { "lint": "pint -v", "refactor": "rector --debug", - "test:lint": "pint --test -v", + "test:lint": "pint --test -v ./src ./tests", "test:types": "phpstan analyse --ansi", "test:unit": "simple-phpunit --colors=always", "test": [ diff --git a/rector.php b/rector.php index 2293079..622e4e2 100644 --- a/rector.php +++ b/rector.php @@ -4,16 +4,15 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; +use Rector\Php81\Rector\Array_\FirstClassCallableRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__.'/src', - ]); - - $rectorConfig->skip([ - __DIR__.'/src/Resources/config/', + __DIR__.'/tests', + __DIR__.'/rector.php', ]); $rectorConfig->rules([ @@ -28,4 +27,8 @@ SetList::TYPE_DECLARATION, SetList::PRIVATIZATION, ]); + + $rectorConfig->skip([ + FirstClassCallableRector::class, + ]); }; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php deleted file mode 100644 index b22bb5b..0000000 --- a/src/DependencyInjection/Configuration.php +++ /dev/null @@ -1,36 +0,0 @@ -getRootNode(); - - assert($rootNode instanceof ArrayNodeDefinition); - - $children = $rootNode->children(); - - assert($children instanceof NodeBuilder); - - $children->scalarNode('api_key')->defaultValue('%env(OPENAI_API_KEY)%')->end(); - $children->scalarNode('organization')->defaultValue('%env(default::OPENAI_ORGANIZATION)%')->end(); - - return $treeBuilder; - } -} diff --git a/src/DependencyInjection/OpenAIExtension.php b/src/DependencyInjection/OpenAIExtension.php deleted file mode 100644 index 36dc837..0000000 --- a/src/DependencyInjection/OpenAIExtension.php +++ /dev/null @@ -1,39 +0,0 @@ -> $configs - */ - public function load(array $configs, ContainerBuilder $container): void - { - $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.php'); - - $configuration = $this->getConfiguration($configs, $container); - - assert($configuration instanceof ConfigurationInterface); - - $config = $this->processConfiguration($configuration, $configs); - - $definition = $container->getDefinition(Factory::class); - $definition->addMethodCall('withApiKey', [$config['api_key']]); - if ($config['organization']) { - $definition->addMethodCall('withOrganization', [$config['organization']]); - } - } -} diff --git a/src/OpenAIBundle.php b/src/OpenAIBundle.php index c14715b..9d78a06 100644 --- a/src/OpenAIBundle.php +++ b/src/OpenAIBundle.php @@ -4,6 +4,76 @@ namespace OpenAI\Symfony; -use Symfony\Component\HttpKernel\Bundle\Bundle; +use OpenAI\Client; +use OpenAI\Contracts\ClientContract; +use OpenAI\Factory; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\HttpClient\Psr18Client; +use Symfony\Component\HttpKernel\Bundle\AbstractBundle; -final class OpenAIBundle extends Bundle {} +use function Symfony\Component\DependencyInjection\Loader\Configurator\service; + +final class OpenAIBundle extends AbstractBundle +{ + protected string $extensionAlias = 'openai'; + + public function configure(DefinitionConfigurator $definition): void + { + $root = $definition->rootNode(); + assert($root instanceof ArrayNodeDefinition); + $children = $root->children(); + $children + ->scalarNode('api_key') + ->defaultValue('%env(OPENAI_API_KEY)%') + ->info('OpenAI API Key used to authenticate with the OpenAI API') + ->isRequired(); + $children + ->scalarNode('organization') + ->info('OpenAI API Organization used to authenticate with the OpenAI API') + ->defaultValue('%env(default::OPENAI_ORGANIZATION)%') + ->info(''); + $children + ->scalarNode('project') + ->defaultNull() + ->info('OpenAI API project'); + $children + ->scalarNode('base_uri') + ->defaultNull() + ->info('OpenAI API base URL used to make requests. Defaults to: api.openai.com/v1'); + } + + /** + * @param array{api_key: string, organization: string, project: ?string, base_uri: ?string} $config + */ + public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void + { + $container->services() + ->set('openai.http_client', Psr18Client::class) + ->arg(0, service('http_client')); + + $factory = $container->services() + ->set(Factory::class) + ->factory([\OpenAI::class, 'factory']) + ->call('withHttpClient', [service('openai.http_client')]) + ->call('withHttpHeader', ['OpenAI-Beta', 'assistants=v2']) + ->call('withApiKey', [$config['api_key']]) + ->call('withOrganization', [$config['organization']]); + if ($config['project']) { + $factory->call('withProject', [$config['project']]); + } + if ($config['base_uri']) { + $factory->call('withBaseUri', [$config['base_uri']]); + } + + $container->services() + ->set(Client::class) + ->factory([service(Factory::class), 'make']); + + $container->services() + ->alias(ClientContract::class, Client::class) + ->alias('openai', Client::class); + } +} diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php deleted file mode 100644 index 67fee2f..0000000 --- a/src/Resources/config/services.php +++ /dev/null @@ -1,28 +0,0 @@ -services() - ->set('openai.http_client', Psr18Client::class) - ->arg(0, service('http_client')) - - ->set(Factory::class) - ->factory([OpenAI::class, 'factory']) - ->call('withHttpClient', [service('openai.http_client')]) - ->call('withHttpHeader', ['OpenAI-Beta', 'assistants=v2']) - - ->set(Client::class) - ->factory([service(Factory::class), 'make']) - - ->alias(ClientContract::class, Client::class) - ->alias('openai', Client::class); -}; diff --git a/tests/DependencyInjection/OpenAIExtensionTest.php b/tests/DependencyInjection/OpenAIExtensionTest.php deleted file mode 100644 index 6514b13..0000000 --- a/tests/DependencyInjection/OpenAIExtensionTest.php +++ /dev/null @@ -1,52 +0,0 @@ - 200, - 'response_headers' => [ - 'content-type' => 'application/json', - 'x-request-id' => '0123456789abcdef0123456789abcdef', - ], - ]); - }); - - $container = new ContainerBuilder; - $container->set('http_client', $httpClient); - - $extension = new OpenAIExtension; - $extension->load([ - 'openai' => [ - 'api_key' => 'pk-123456789', - ], - ], $container); - - $openai = $container->get('openai'); - self::assertInstanceOf(Client::class, $openai); - - $response = $openai->files()->delete('file.txt'); - self::assertSame('file.txt', $response->id); - - self::assertSame($openai, $container->get(ClientContract::class), 'Alias for the ClientContract interface'); - } -} diff --git a/tests/OpenAIBundleTest.php b/tests/OpenAIBundleTest.php new file mode 100644 index 0000000..960339f --- /dev/null +++ b/tests/OpenAIBundleTest.php @@ -0,0 +1,91 @@ +extension('framework', [ + 'secret' => 'S0ME_SECRET', + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + ]); + + $container->extension('openai', [ + 'api_key' => 'pk-123456789', + 'organization' => 'org-123456789', + ]); + + $container->services() + ->set('http_client', MockHttpClient::class) + ->public() + + ->set('tested_services', \ArrayObject::class) + ->args([[ + 'openai' => service('openai'), + Client::class => service(Client::class), + ClientContract::class => service(ClientContract::class), + ]]) + ->public(); + } + }; + + // Using a mock to test the service configuration + $httpClient = new MockHttpClient(function (string $method, string $url, array $options = []): MockResponse { + self::assertSame('DELETE', $method); + self::assertSame('https://api.openai.com/v1/files/file.txt', $url); + self::assertContains('Authorization: Bearer pk-123456789', $options['headers']); + + return new MockResponse('{"id":"file.txt","object":"file","deleted":true}', [ + 'http_code' => 200, + 'response_headers' => [ + 'content-type' => 'application/json', + 'x-request-id' => '0123456789abcdef0123456789abcdef', + ], + ]); + }); + + $kernel->boot(); + $container = $kernel->getContainer(); + $container->set('http_client', $httpClient); + + $testedServices = $container->get('tested_services'); + assert($testedServices instanceof \ArrayObject); + $openai = $testedServices['openai']; + self::assertInstanceOf(Client::class, $openai); + self::assertSame($openai, $testedServices[Client::class]); + self::assertSame($openai, $testedServices[ClientContract::class]); + + $response = $openai->files()->delete('file.txt'); + self::assertSame('file.txt', $response->id); + } +} From db61e70d1f0c377aa35c33d8f962860a7b812271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 2 Oct 2025 15:35:05 +0200 Subject: [PATCH 07/14] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7b52c..6862748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## v0.17.0 +## v0.17.0 (2024-10-02) ### Changed - Refactored into a single `OpenAI\Symfony\OpenAIBundle` class - Add `project` and `base_uri` configuration options - Drop support for unsupported Symfony versions. Now requires Symfony 6.4 or 7.3+ - Add support for Symfony 8.0 +- Changed underlying `openai/client` package version to 0.17.0 ## v0.12.0 (2025-05-06) ### Changed From 3ac68865cc8b456f8f113c3ccc6e3a832bc0362f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Oct 2025 14:41:57 +0000 Subject: [PATCH 08/14] chore(deps): bump ramsey/composer-install from 2 to 3 Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 2 to 3. - [Release notes](https://github.com/ramsey/composer-install/releases) - [Commits](https://github.com/ramsey/composer-install/compare/v2...v3) --- updated-dependencies: - dependency-name: ramsey/composer-install dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 87668e5..cb7d8ec 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,7 +34,7 @@ jobs: tools: flex - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: dependency-versions: ${{ matrix.dependency }} From 2e6d30a4370ec7f0bbdaaa35315989509d91607a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 15 Oct 2025 12:34:46 +0200 Subject: [PATCH 09/14] Remove required config --- src/OpenAIBundle.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenAIBundle.php b/src/OpenAIBundle.php index 9d78a06..4974cee 100644 --- a/src/OpenAIBundle.php +++ b/src/OpenAIBundle.php @@ -28,8 +28,7 @@ public function configure(DefinitionConfigurator $definition): void $children ->scalarNode('api_key') ->defaultValue('%env(OPENAI_API_KEY)%') - ->info('OpenAI API Key used to authenticate with the OpenAI API') - ->isRequired(); + ->info('OpenAI API Key used to authenticate with the OpenAI API'); $children ->scalarNode('organization') ->info('OpenAI API Organization used to authenticate with the OpenAI API') From 19a22aa56646d26997cea595d9e810ebfd2a213b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 15 Oct 2025 12:35:26 +0200 Subject: [PATCH 10/14] Use PhpUnit directly --- .github/workflows/tests.yml | 2 +- composer.json | 2 +- tests/OpenAIBundleTest.php | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 87668e5..ad0de0b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,4 +39,4 @@ jobs: dependency-versions: ${{ matrix.dependency }} - name: Integration Tests - run: php ./vendor/bin/simple-phpunit + run: php ./vendor/bin/phpunit diff --git a/composer.json b/composer.json index e7b26ce..3268188 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "laravel/pint": "^1.24.0", "phpstan/phpstan": "^2.1.22", "rector/rector": "^2.1.5", - "symfony/phpunit-bridge": "^6.4.25|^7.3|^8.0", + "phpunit/phpunit": "^11|^12", "symfony/framework-bundle": "^6.4|^7.3|^8.0" }, "autoload": { diff --git a/tests/OpenAIBundleTest.php b/tests/OpenAIBundleTest.php index 960339f..2b7df64 100644 --- a/tests/OpenAIBundleTest.php +++ b/tests/OpenAIBundleTest.php @@ -7,10 +7,12 @@ use OpenAI\Client; use OpenAI\Contracts\ClientContract; use OpenAI\Symfony\OpenAIBundle; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\ErrorHandler\ErrorHandler; use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\Response\MockResponse; use Symfony\Component\HttpKernel\Kernel; @@ -19,6 +21,38 @@ final class OpenAIBundleTest extends TestCase { + public static function setUpBeforeClass(): void + { + ErrorHandler::register(null, false); + } + + #[DoesNotPerformAssertions] + public function test_defaults(): void + { + $kernel = new class('test', true) extends Kernel + { + use MicroKernelTrait; + + public function registerBundles(): iterable + { + yield new FrameworkBundle; + yield new OpenAIBundle; + } + + protected function configureContainer(ContainerConfigurator $container): void + { + $container->extension('framework', [ + 'secret' => 'S0ME_SECRET', + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + ]); + } + }; + + $kernel->boot(); + } + public function test_service(): void { $kernel = new class('test', true) extends Kernel From ac428f022c5ff6cc39c868636903989aa8df2e66 Mon Sep 17 00:00:00 2001 From: Anne van de Venis Date: Sat, 1 Nov 2025 16:53:49 +0100 Subject: [PATCH 11/14] Update openai-php/client version to 0.18 (#38) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3268188..bf728f5 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": "^8.2.0", "nyholm/psr7": "^1.8.2", - "openai-php/client": "^0.17.0", + "openai-php/client": "^0.18.0", "psr/http-client": "^1.0.3", "psr/http-factory": "^1.1.0", "symfony/config": "^6.4|^7.3|^8.0", From 4ef9a3f9b846625f7c51b87936d7d67327657631 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 15:54:04 +0100 Subject: [PATCH 12/14] chore(deps): bump actions/checkout from 5 to 6 (#39) Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/formats.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/formats.yml b/.github/workflows/formats.yml index d858f6a..25e9d58 100644 --- a/.github/workflows/formats.yml +++ b/.github/workflows/formats.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Cache dependencies uses: actions/cache@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ca22eb5..e60a5f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 From c2ed624c822fbc3a9d62fea76de9dd9b6aa53989 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 17:29:23 +0100 Subject: [PATCH 13/14] chore(deps): bump actions/cache from 4 to 5 (#40) Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/cache dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/formats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/formats.yml b/.github/workflows/formats.yml index 25e9d58..d458d1c 100644 --- a/.github/workflows/formats.yml +++ b/.github/workflows/formats.yml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@v6 - name: Cache dependencies - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: ~/.composer/cache/files key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} From 5adc90944f77680765795aa743ab9cff1ac1cf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 15 Dec 2025 18:53:33 +0100 Subject: [PATCH 14/14] Run tests with PHP 8.5 and fix phpstan issue resolved by Symfony 7.4 (#41) --- .github/workflows/tests.yml | 7 ++++--- src/OpenAIBundle.php | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e60a5f7..cb87301 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,12 +9,13 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2, 8.3, 8.4] - symfony: [^6.4, false] + php: [8.2, 8.3, 8.4, 8.5] + symfony: [false] dependency: [stable] include: + - { php: 8.2, symfony: ^6.4 , dependency: stable } - { php: 8.4, symfony: ^7.4, dependency: highest } - - { php: 8.4, symfony: ^8.0, dependency: highest } + - { php: 8.4, symfony: false, dependency: highest } env: SYMFONY_REQUIRE: ${{ matrix.symfony }} diff --git a/src/OpenAIBundle.php b/src/OpenAIBundle.php index 4974cee..484b51a 100644 --- a/src/OpenAIBundle.php +++ b/src/OpenAIBundle.php @@ -7,7 +7,6 @@ use OpenAI\Client; use OpenAI\Contracts\ClientContract; use OpenAI\Factory; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -23,7 +22,6 @@ final class OpenAIBundle extends AbstractBundle public function configure(DefinitionConfigurator $definition): void { $root = $definition->rootNode(); - assert($root instanceof ArrayNodeDefinition); $children = $root->children(); $children ->scalarNode('api_key')