diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..15af632 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ + + +### What: + +- [ ] Bug Fix +- [ ] New Feature + +### Description: + + + +### Related: + + diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..ca79ca5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/formats.yml b/.github/workflows/formats.yml index dd0c824..d858f6a 100644 --- a/.github/workflows/formats.yml +++ b/.github/workflows/formats.yml @@ -11,17 +11,17 @@ jobs: matrix: os: [ubuntu-latest] php: [8.2] - dependency-version: [prefer-lowest, prefer-stable] + dependency-version: [prefer-stable] name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.composer/cache/files key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bdc3757..a434b17 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,23 +4,30 @@ on: ['push', 'pull_request'] jobs: ci: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest + strategy: fail-fast: true matrix: - os: [ubuntu-latest] - php: [8.1, 8.2] - symfony: [5.4.*, 6.2.*] + php: [8.2, 8.3, 8.4] + symfony: [5.4.*, 6.4.*, 7.0.*] dependency-version: [prefer-lowest, prefer-stable] - - name: Tests P${{ matrix.php }} - SF${{ matrix.symfony }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} + 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 }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v5 - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.composer/cache/files key: dependencies-php-${{ matrix.php }}-SF${{ matrix.symfony }}-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }} @@ -39,6 +46,7 @@ jobs: "symfony/dependency-injection:${{ matrix.symfony }}" "symfony/http-kernel:${{ matrix.symfony }}" --no-interaction --no-update + - name: Install Composer dependencies run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist diff --git a/CHANGELOG.md b/CHANGELOG.md index c22efa5..22f06ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ 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.12.0 (2025-05-06) +### Changed +- Changed underlying `openai/client` package version to 0.12.0 +- Add an alias for the `ClientContract` interface + +## v0.10.0 (2024-06-19) +### Changed +- Specify header `OpenAI-Beta: assistants=v2` +- Changed underlying `openai/client` package version to 0.10.0 + ## v0.7.10 (2023-11-14) ### Changed - Changed underlying `openai/client` package version to 0.7.10 diff --git a/README.md b/README.md index 8171dd2..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' => 'text-davinci-003', + 'model' => 'gpt-4o-mini', 'prompt' => 'PHP is', ]); diff --git a/composer.json b/composer.json index 67c5dca..2cb1e96 100644 --- a/composer.json +++ b/composer.json @@ -8,24 +8,28 @@ { "name": "Jérôme Tamarelle", "email": "jerome@tamarelle.net" + }, + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" } ], "require": { - "php": "^8.1.0", - "nyholm/psr7": "^1.8.0", - "openai-php/client": "^v0.7.10", - "psr/http-client": "^1.0.2", - "psr/http-factory": "^1.0.2", - "symfony/config": "^5.4.21|^6.2.7", - "symfony/dependency-injection": "^5.4.21|^6.2.10", - "symfony/http-client": "^5.4.21|^6.2.10", - "symfony/http-kernel": "^5.4.21|^6.2.10" + "php": "^8.2.0", + "nyholm/psr7": "^1.8.2", + "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", + "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" }, "require-dev": { - "laravel/pint": "^1.10.0", - "phpstan/phpstan": "^1.10.14", + "laravel/pint": "^1.18.1", + "phpstan/phpstan": "^1.12.6", "rector/rector": "^0.14.8", - "symfony/phpunit-bridge": "^6.2.10" + "symfony/phpunit-bridge": "^5.4|^6.3|^7.1.4" }, "autoload": { "psr-4": { diff --git a/src/OpenAIBundle.php b/src/OpenAIBundle.php index 4a58def..c14715b 100644 --- a/src/OpenAIBundle.php +++ b/src/OpenAIBundle.php @@ -6,6 +6,4 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -final class OpenAIBundle extends Bundle -{ -} +final class OpenAIBundle extends Bundle {} diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index a4780b6..67fee2f 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -6,6 +6,7 @@ use OpenAI; use OpenAI\Client; +use OpenAI\Contracts\ClientContract; use OpenAI\Factory; use Symfony\Component\HttpClient\Psr18Client; @@ -17,9 +18,11 @@ ->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 index 54f225c..6514b13 100644 --- a/tests/DependencyInjection/OpenAIExtensionTest.php +++ b/tests/DependencyInjection/OpenAIExtensionTest.php @@ -5,6 +5,7 @@ namespace OpenAI\Symfony\Tests\DependencyInjection; use OpenAI\Client; +use OpenAI\Contracts\ClientContract; use OpenAI\Symfony\DependencyInjection\OpenAIExtension; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -13,7 +14,7 @@ final class OpenAIExtensionTest extends TestCase { - public function testService(): void + public function test_service(): void { // Using a mock to test the service configuration $httpClient = new MockHttpClient(function (string $method, string $url, array $options = []) { @@ -30,10 +31,10 @@ public function testService(): void ]); }); - $container = new ContainerBuilder(); + $container = new ContainerBuilder; $container->set('http_client', $httpClient); - $extension = new OpenAIExtension(); + $extension = new OpenAIExtension; $extension->load([ 'openai' => [ 'api_key' => 'pk-123456789', @@ -45,5 +46,7 @@ public function testService(): void $response = $openai->files()->delete('file.txt'); self::assertSame('file.txt', $response->id); + + self::assertSame($openai, $container->get(ClientContract::class), 'Alias for the ClientContract interface'); } }