Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Release version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
om4csaba committed Dec 21, 2022
1 parent 61a00e0 commit 8329e62
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 113 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -86,13 +86,11 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup node
if: matrix.test-type == 'integration'
uses: actions/setup-node@v2
with:
node-version: '16'
uses: actions/setup-node@v3

- name: Install and run @stoplight/prism
if: matrix.test-type == 'integration'
Expand Down Expand Up @@ -141,12 +139,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '16'
uses: actions/setup-node@v3

- name: Install and run @stoplight/prism
run: |
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.3.0 - 2022-12-21

### Added
- Use parameters defined outside endpoint methods.

### Changed
- Encourage the use of `php-http/mock-client` for testing and mocking API responses.
- Remove the `Tests\MockHttpClient` class, and use the `php-http/mock-client` package instead.
- Make Handler and Model class names more readable.

### Fixed
- Use correct model type for nested models.

## 1.2.0 - 2022-11-07

### Added
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ composer test:integration

We do not recommend running integration tests against the live OpenAI API endpoints. This is because the tests will send example data to all endpoints, which can result in new data being created, or existing data being deleted.

### Writing Your Own Tests

If you are writing your own tests, you will likely need to mock the responses from the **OpenAI API**.

One way of doing this is to install the `php-http/mock-client` package into your project, and then use the `\Http\Mock\Client` class (instead of a real PSR-18 client) when instantiating the **Tectalic OpenAI REST API Client**.

This allows you to mock the responses from the **OpenAI API**, rather than performing real requests.

Please see the [Mock Client documentation](https://docs.php-http.org/en/latest/clients/mock-client.html#mock-client) for details.

## Support

If you have any questions or feedback, please use the [discussion board](https://github.com/tectalichq/public-openai-client-php/discussions).
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"require-dev": {
"league/openapi-psr7-validator": "^0.17.0",
"mikey179/vfsstream": "^1.6.10",
"php-http/mock-client": "^1.5",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^8.5.14 || ^9.5",
"squizlabs/php_codesniffer": "^3.6",
Expand All @@ -54,7 +55,10 @@
"@test:unit",
"@test:integration"
],
"test:coverage": "XDEBUG_MODE=coverage phpunit --verbose --coverage-html=coverage",
"test:coverage": [
"Composer\\Config::disableProcessTimeout",
"XDEBUG_MODE=coverage phpunit --verbose --coverage-html=coverage"
],
"test:integration": "phpunit --verbose --testsuite=integration",
"test:phpcs": "phpcs -q -s",
"test:phpstan": "phpstan analyse --memory-limit=1G",
Expand All @@ -67,5 +71,8 @@
"test:phpstan": "Static test via phpstan.",
"test:phpcs": "Style test via phpcs.",
"test:unit": "Unit test via phpunit."
},
"suggest": {
"php-http/mock-client": "Simplify testing by using a mock HTTP client"
}
}
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"libraryVersion": "1.2.0",
"libraryVersion": "1.3.0",
"apiVersion": "1.1.0",
"buildVersion": "1.1.5"
"buildVersion": "1.2.0"
}
3 changes: 2 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tectalic\OpenAi;

use Http\Message\Authentication;
use Http\Message\MultipartStream\MultipartStreamBuilder;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Client\ClientExceptionInterface;
Expand Down Expand Up @@ -369,7 +370,7 @@ private function mergeRequestParts(

$request = $request->withHeader(
'User-Agent',
'Tectalic OpenAI REST API Client/1.2.0'
'Tectalic OpenAI REST API Client/1.3.0'
);

// Merge Headers.
Expand Down
1 change: 1 addition & 0 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tectalic\OpenAi;

use Http\Message\Authentication;
use LogicException;
use Psr\Http\Client\ClientInterface;

Expand Down
47 changes: 0 additions & 47 deletions tests/MockHttpClient.php

This file was deleted.

24 changes: 24 additions & 0 deletions tests/NullAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Copyright (c) 2022 Tectalic (https://tectalic.com)
*
* For copyright and license information, please view the LICENSE file that was distributed with this source code.
*
* Please see the README.md file for usage instructions.
*/

declare(strict_types=1);

namespace Tests;

use Http\Message\Authentication;
use Psr\Http\Message\RequestInterface;

final class NullAuth implements Authentication
{
public function authenticate(RequestInterface $request): RequestInterface
{
return $request;
}
}
32 changes: 18 additions & 14 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@

namespace Tests\Unit;

use Http\Mock\Client;
use LogicException;
use Nyholm\Psr7\Request;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use ReflectionClass;
use ReflectionObject;
use Tectalic\OpenAi\Authentication;
use Tectalic\OpenAi\Client;
use Tectalic\OpenAi\Client as OpenAiClient;
use Tectalic\OpenAi\ClientException;
use Tectalic\OpenAi\Manager;
use Tectalic\OpenAi\Models\AbstractModel;
use Tectalic\OpenAi\Models\AbstractModelCollection;
use Tectalic\OpenAi\Models\UnstructuredModel;
use Tests\MockHttpClient;
use Tests\NullAuth;

final class ClientTest extends TestCase
{
public function setUp(): void
{
Manager::build(
new MockHttpClient(),
new Authentication('token')
new Client(),
new NullAuth()
);
}

Expand All @@ -48,9 +48,9 @@ public function tearDown(): void

public function testGlobal(): void
{
$client = new Client(
new MockHttpClient(),
new Authentication('token'),
$client = new OpenAiClient(
new Client(),
new NullAuth(),
Manager::BASE_URI
);
$this->assertEquals($client, Manager::access());
Expand All @@ -64,8 +64,8 @@ public function testDoubleBuild(): void
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Client already built.');
Manager::build(
new MockHttpClient(),
new Authentication('token')
new Client(),
new NullAuth()
);
}

Expand Down Expand Up @@ -385,15 +385,19 @@ public function invalidResponse(): array

/**
* @dataProvider invalidResponse
* @param class-string<\Throwable> $exception
* @param class-string<\Exception> $exception
*/
public function testInvalidResponse(string $method, string $exception, string $message): void
{
$this->expectException(ClientException::class);
$this->expectExceptionMessage($message);
$client = new Client(
new MockHttpClient(new $exception()),
new Authentication('token'),

$mockClient = new Client();
$mockClient->addException(new $exception());

$client = new OpenAiClient(
$mockClient,
new NullAuth(),
Manager::BASE_URI
);
$client->sendRequest($client->$method('/'));
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Handlers/CompletionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tests\Unit\Handlers;

use Http\Mock\Client;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Expand All @@ -22,18 +23,17 @@
use Tectalic\OpenAi\Manager;
use Tectalic\OpenAi\Models\Completions\CreateRequest;
use Tests\AssertValidateTrait;
use Tests\MockHttpClient;

final class CompletionsTest extends TestCase
{
use AssertValidateTrait;

/** @var MockHttpClient */
/** @var Client */
private $mockClient;

protected function setUp(): void
{
$this->mockClient = new MockHttpClient();
$this->mockClient = new Client();
Manager::build(
$this->mockClient,
new Authentication('token')
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Handlers/EditsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tests\Unit\Handlers;

use Http\Mock\Client;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Expand All @@ -22,18 +23,17 @@
use Tectalic\OpenAi\Manager;
use Tectalic\OpenAi\Models\Edits\CreateRequest;
use Tests\AssertValidateTrait;
use Tests\MockHttpClient;

final class EditsTest extends TestCase
{
use AssertValidateTrait;

/** @var MockHttpClient */
/** @var Client */
private $mockClient;

protected function setUp(): void
{
$this->mockClient = new MockHttpClient();
$this->mockClient = new Client();
Manager::build(
$this->mockClient,
new Authentication('token')
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Handlers/EmbeddingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tests\Unit\Handlers;

use Http\Mock\Client;
use Nyholm\Psr7\Response;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Expand All @@ -22,18 +23,17 @@
use Tectalic\OpenAi\Manager;
use Tectalic\OpenAi\Models\Embeddings\CreateRequest;
use Tests\AssertValidateTrait;
use Tests\MockHttpClient;

final class EmbeddingsTest extends TestCase
{
use AssertValidateTrait;

/** @var MockHttpClient */
/** @var Client */
private $mockClient;

protected function setUp(): void
{
$this->mockClient = new MockHttpClient();
$this->mockClient = new Client();
Manager::build(
$this->mockClient,
new Authentication('token')
Expand Down

0 comments on commit 8329e62

Please sign in to comment.