From 2c411ce3bbb6bc9110364f1199d8ccfb1ebf3567 Mon Sep 17 00:00:00 2001
From: gehrisandro
Date: Wed, 21 Jun 2023 18:51:33 +0200
Subject: [PATCH 01/12] error handling: catch errors in stream responses -
fixes #147
---
src/Responses/StreamResponse.php | 6 +++++
tests/Arch.php | 1 +
tests/Fixtures/Chat.php | 8 +++++++
.../Streams/ChatCompletionCreateError.txt | 1 +
tests/Resources/Chat.php | 24 +++++++++++++++++++
5 files changed, 40 insertions(+)
create mode 100644 tests/Fixtures/Streams/ChatCompletionCreateError.txt
diff --git a/src/Responses/StreamResponse.php b/src/Responses/StreamResponse.php
index f73b5626..c4e24342 100644
--- a/src/Responses/StreamResponse.php
+++ b/src/Responses/StreamResponse.php
@@ -4,6 +4,7 @@
use Generator;
use IteratorAggregate;
+use OpenAI\Exceptions\ErrorException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
@@ -44,8 +45,13 @@ public function getIterator(): Generator
break;
}
+ /** @var array{error?: array{message: string, type: string, code: string}} $response */
$response = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
+ if (isset($response['error'])) {
+ throw new ErrorException($response['error']);
+ }
+
yield $this->responseClass::from($response);
}
}
diff --git a/tests/Arch.php b/tests/Arch.php
index 3dac108d..1f89e1e9 100644
--- a/tests/Arch.php
+++ b/tests/Arch.php
@@ -30,6 +30,7 @@
test('responses')->expect('OpenAI\Responses')->toOnlyUse([
'OpenAI\Enums',
+ 'OpenAI\Exceptions\ErrorException',
'OpenAI\Contracts',
'OpenAI\Testing\Responses\Concerns',
'Psr\Http\Message\ResponseInterface',
diff --git a/tests/Fixtures/Chat.php b/tests/Fixtures/Chat.php
index 70661f01..536dbf25 100644
--- a/tests/Fixtures/Chat.php
+++ b/tests/Fixtures/Chat.php
@@ -128,3 +128,11 @@ function chatCompletionStream()
{
return fopen(__DIR__.'/Streams/ChatCompletionCreate.txt', 'r');
}
+
+/**
+ * @return resource
+ */
+function chatCompletionStreamError()
+{
+ return fopen(__DIR__.'/Streams/ChatCompletionCreateError.txt', 'r');
+}
diff --git a/tests/Fixtures/Streams/ChatCompletionCreateError.txt b/tests/Fixtures/Streams/ChatCompletionCreateError.txt
new file mode 100644
index 00000000..e4f2dff6
--- /dev/null
+++ b/tests/Fixtures/Streams/ChatCompletionCreateError.txt
@@ -0,0 +1 @@
+data: {"error":{"message":"The server had an error while processing your request. Sorry about that!","type":"server_error","param":null,"code":null}}
diff --git a/tests/Resources/Chat.php b/tests/Resources/Chat.php
index a350db00..c4d5c0bf 100644
--- a/tests/Resources/Chat.php
+++ b/tests/Resources/Chat.php
@@ -90,3 +90,27 @@
->logprobs->toBe(null)
->finishReason->toBeNull();
});
+
+test('handles error messages in stream', function () {
+ $response = new Response(
+ body: new Stream(chatCompletionStreamError())
+ );
+
+ $client = mockStreamClient('POST', 'chat/completions', [
+ 'model' => 'gpt-3.5-turbo',
+ 'messages' => ['role' => 'user', 'content' => 'Hello!'],
+ ], $response);
+
+ $result = $client->chat()->createStreamed([
+ 'model' => 'gpt-3.5-turbo',
+ 'messages' => ['role' => 'user', 'content' => 'Hello!'],
+ ]);
+
+ expect(fn () => $result->getIterator()->current())
+ ->toThrow(function (OpenAI\Exceptions\ErrorException $e) {
+ expect($e->getMessage())->toBe('The server had an error while processing your request. Sorry about that!')
+ ->and($e->getErrorMessage())->toBe('The server had an error while processing your request. Sorry about that!')
+ ->and($e->getErrorCode())->toBeNull()
+ ->and($e->getErrorType())->toBe('server_error');
+ });
+});
From a56748d0b13831c6c602b4c1328dc99813fb414a Mon Sep 17 00:00:00 2001
From: gehrisandro
Date: Fri, 23 Jun 2023 09:42:08 +0200
Subject: [PATCH 02/12] error handling: error message is sometimes an array -
fixes #146
---
src/Exceptions/ErrorException.php | 10 +++++++--
src/Responses/StreamResponse.php | 2 +-
src/Transporters/HttpTransporter.php | 2 +-
tests/Transporters/HttpTransporter.php | 28 ++++++++++++++++++++++++++
4 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/src/Exceptions/ErrorException.php b/src/Exceptions/ErrorException.php
index 8f54c943..33627b17 100644
--- a/src/Exceptions/ErrorException.php
+++ b/src/Exceptions/ErrorException.php
@@ -11,11 +11,17 @@ final class ErrorException extends Exception
/**
* Creates a new Exception instance.
*
- * @param array{message: string, type: ?string, code: ?string} $contents
+ * @param array{message: string|array, type: ?string, code: ?string} $contents
*/
public function __construct(private readonly array $contents)
{
- parent::__construct($contents['message']);
+ $message = $contents['message'];
+
+ if (is_array($message)) {
+ $message = implode("\n", $message);
+ }
+
+ parent::__construct($message);
}
/**
diff --git a/src/Responses/StreamResponse.php b/src/Responses/StreamResponse.php
index c4e24342..84775f9c 100644
--- a/src/Responses/StreamResponse.php
+++ b/src/Responses/StreamResponse.php
@@ -45,7 +45,7 @@ public function getIterator(): Generator
break;
}
- /** @var array{error?: array{message: string, type: string, code: string}} $response */
+ /** @var array{error?: array{message: string|array, type: string, code: string}} $response */
$response = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
if (isset($response['error'])) {
diff --git a/src/Transporters/HttpTransporter.php b/src/Transporters/HttpTransporter.php
index e90e0f35..385a2ba3 100644
--- a/src/Transporters/HttpTransporter.php
+++ b/src/Transporters/HttpTransporter.php
@@ -123,7 +123,7 @@ private function throwIfJsonError(ResponseInterface $response, string|ResponseIn
}
try {
- /** @var array{error?: array{message: string, type: string, code: string}} $response */
+ /** @var array{error?: array{message: string|array, type: string, code: string}} $response */
$response = json_decode($contents, true, 512, JSON_THROW_ON_ERROR);
if (isset($response['error'])) {
diff --git a/tests/Transporters/HttpTransporter.php b/tests/Transporters/HttpTransporter.php
index 7d7a75a2..16cb6186 100644
--- a/tests/Transporters/HttpTransporter.php
+++ b/tests/Transporters/HttpTransporter.php
@@ -187,6 +187,34 @@
});
});
+test('error message may be an array', function () {
+ $payload = Payload::create('completions', ['model' => 'gpt-4']);
+
+ $response = new Response(404, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
+ 'error' => [
+ 'message' => [
+ 'Invalid schema for function \'get_current_weather\': In context=(\'properties\', \'location\'), array schema missing items',
+ ],
+ 'type' => 'invalid_request_error',
+ 'param' => null,
+ 'code' => null,
+ ],
+ ]));
+
+ $this->client
+ ->shouldReceive('sendRequest')
+ ->once()
+ ->andReturn($response);
+
+ expect(fn () => $this->http->requestObject($payload))
+ ->toThrow(function (ErrorException $e) {
+ expect($e->getMessage())->toBe('Invalid schema for function \'get_current_weather\': In context=(\'properties\', \'location\'), array schema missing items')
+ ->and($e->getErrorMessage())->toBe('Invalid schema for function \'get_current_weather\': In context=(\'properties\', \'location\'), array schema missing items')
+ ->and($e->getErrorCode())->toBeNull()
+ ->and($e->getErrorType())->toBe('invalid_request_error');
+ });
+});
+
test('request object client errors', function () {
$payload = Payload::list('models');
From c4ae556a6b8ec9a06b2acd3e2fa9d89b6f298b0e Mon Sep 17 00:00:00 2001
From: gehrisandro
Date: Fri, 23 Jun 2023 09:51:23 +0200
Subject: [PATCH 03/12] error handling: error message is sometimes empty -
fixes https://github.com/openai-php/laravel/issues/47
---
src/Exceptions/ErrorException.php | 2 +-
tests/Transporters/HttpTransporter.php | 52 ++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/src/Exceptions/ErrorException.php b/src/Exceptions/ErrorException.php
index 33627b17..165892d0 100644
--- a/src/Exceptions/ErrorException.php
+++ b/src/Exceptions/ErrorException.php
@@ -15,7 +15,7 @@ final class ErrorException extends Exception
*/
public function __construct(private readonly array $contents)
{
- $message = $contents['message'];
+ $message = ($contents['message'] ?: $this->contents['code']) ?: 'Unknown error';
if (is_array($message)) {
$message = implode("\n", $message);
diff --git a/tests/Transporters/HttpTransporter.php b/tests/Transporters/HttpTransporter.php
index 16cb6186..fa4c1742 100644
--- a/tests/Transporters/HttpTransporter.php
+++ b/tests/Transporters/HttpTransporter.php
@@ -215,6 +215,58 @@
});
});
+test('error message may be empty', function () {
+ $payload = Payload::create('completions', ['model' => 'gpt-4']);
+
+ $response = new Response(404, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
+ 'error' => [
+ 'message' => '',
+ 'type' => 'invalid_request_error',
+ 'param' => null,
+ 'code' => 'invalid_api_key',
+ ],
+ ]));
+
+ $this->client
+ ->shouldReceive('sendRequest')
+ ->once()
+ ->andReturn($response);
+
+ expect(fn () => $this->http->requestObject($payload))
+ ->toThrow(function (ErrorException $e) {
+ expect($e->getMessage())->toBe('invalid_api_key')
+ ->and($e->getErrorMessage())->toBe('invalid_api_key')
+ ->and($e->getErrorCode())->toBe('invalid_api_key')
+ ->and($e->getErrorType())->toBe('invalid_request_error');
+ });
+});
+
+test('error message and code may be empty', function () {
+ $payload = Payload::create('completions', ['model' => 'gpt-4']);
+
+ $response = new Response(404, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
+ 'error' => [
+ 'message' => '',
+ 'type' => 'invalid_request_error',
+ 'param' => null,
+ 'code' => null,
+ ],
+ ]));
+
+ $this->client
+ ->shouldReceive('sendRequest')
+ ->once()
+ ->andReturn($response);
+
+ expect(fn () => $this->http->requestObject($payload))
+ ->toThrow(function (ErrorException $e) {
+ expect($e->getMessage())->toBe('Unknown error')
+ ->and($e->getErrorMessage())->toBe('Unknown error')
+ ->and($e->getErrorCode())->toBeNull()
+ ->and($e->getErrorType())->toBe('invalid_request_error');
+ });
+});
+
test('request object client errors', function () {
$payload = Payload::list('models');
From aca5cfcfdc7effa1418f4b6997c3510826786b25 Mon Sep 17 00:00:00 2001
From: gehrisandro
Date: Fri, 23 Jun 2023 22:13:33 +0200
Subject: [PATCH 04/12] release: v0.6.2
---
CHANGELOG.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d28454e6..bd418bb6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,14 @@ 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.6.2 (2023-06-23)
+### Changed
+- Error handling: use error code as exception message if error message is empty ([#150](https://github.com/openai-php/client/pull/150))
+
+### Fixed
+- Error handling: Catch error in stream responses ([#150](https://github.com/openai-php/client/pull/150))
+- Error handling: Handle errors where message is an array ([#150](https://github.com/openai-php/client/pull/150))
+
## v0.6.1 (2023-06-15)
### Fixed
- Chat/CreateResponse faking with function_call ([#145](https://github.com/openai-php/client/issues/145))
From d8ebc24fe2a719310c501b614ec44494d8d2e6d5 Mon Sep 17 00:00:00 2001
From: Nuno Maduro
Date: Sat, 1 Jul 2023 11:37:55 +0100
Subject: [PATCH 05/12] chore: bump dependencies
---
composer.json | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/composer.json b/composer.json
index e8fc5927..7cefa8fe 100644
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,7 @@
],
"require": {
"php": "^8.1.0",
- "php-http/discovery": "^1.18.1",
+ "php-http/discovery": "^1.19.0",
"php-http/multipart-stream-builder": "^1.3.0",
"psr/http-client": "^1.0.2",
"psr/http-client-implementation": "^1.0.1",
@@ -24,15 +24,15 @@
"require-dev": {
"guzzlehttp/guzzle": "^7.7.0",
"guzzlehttp/psr7": "^2.5.0",
- "laravel/pint": "^1.10.2",
- "nunomaduro/collision": "^7.5.2",
+ "laravel/pint": "^1.10.3",
+ "nunomaduro/collision": "^7.7.0",
"pestphp/pest": "dev-develop as 2.6.2",
- "pestphp/pest-plugin-arch": "^2.2.0",
+ "pestphp/pest-plugin-arch": "^2.2.1",
"pestphp/pest-plugin-mock": "^2.0.0",
"pestphp/pest-plugin-type-coverage": "^2.0.0",
- "phpstan/phpstan": "^1.10.15",
+ "phpstan/phpstan": "^1.10.22",
"rector/rector": "^0.16.0",
- "symfony/var-dumper": "^6.3.0"
+ "symfony/var-dumper": "^6.3.1"
},
"autoload": {
"psr-4": {
From f002b0f5adaae499189bce55c246b48f43a18891 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Haydar=20=C5=9EAH=C4=B0N?=
Date: Mon, 3 Jul 2023 22:24:43 +0300
Subject: [PATCH 06/12] Update api reference links
---
CHANGELOG.md | 2 +-
README.md | 2 +-
src/Client.php | 16 ++++++++--------
src/Contracts/ClientContract.php | 16 ++++++++--------
.../Resources/CompletionsContract.php | 4 ++--
src/Contracts/Resources/EditsContract.php | 2 +-
src/Contracts/Resources/EmbeddingsContract.php | 2 +-
src/Contracts/Resources/FilesContract.php | 10 +++++-----
src/Contracts/Resources/FineTunesContract.php | 12 ++++++------
src/Contracts/Resources/ImagesContract.php | 6 +++---
src/Contracts/Resources/ModelsContract.php | 6 +++---
.../Resources/ModerationsContract.php | 2 +-
src/Resources/Completions.php | 4 ++--
src/Resources/Edits.php | 2 +-
src/Resources/Embeddings.php | 2 +-
src/Resources/Files.php | 10 +++++-----
src/Resources/FineTunes.php | 12 ++++++------
src/Resources/Images.php | 6 +++---
src/Resources/Models.php | 6 +++---
src/Resources/Moderations.php | 2 +-
tests/Transporters/HttpTransporter.php | 18 +++++++++---------
21 files changed, 71 insertions(+), 71 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd418bb6..96876072 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -100,7 +100,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## v0.2.0 (2022-11-07)
### Added
-- Add `images()` resource to interact with [DALL-E](https://beta.openai.com/docs/api-reference/images)
+- Add `images()` resource to interact with [DALL-E](https://platform.openai.com/docs/api-reference/images)
### Fixed
- Parse completions create response with logprobs correctly
diff --git a/README.md b/README.md
index fd9296c5..72b2f257 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
------
-**OpenAI PHP** is a community-maintained PHP API client that allows you to interact with the [Open AI API](https://beta.openai.com/docs/api-reference/introduction). If you or your business relies on this package, it's important to support the developers who have contributed their time and effort to create and maintain this valuable tool:
+**OpenAI PHP** is a community-maintained PHP API client that allows you to interact with the [Open AI API](https://platform.openai.com/docs/api-reference/introduction). If you or your business relies on this package, it's important to support the developers who have contributed their time and effort to create and maintain this valuable tool:
- Nuno Maduro: **[github.com/sponsors/nunomaduro](https://github.com/sponsors/nunomaduro)**
- Sandro Gehri: **[github.com/sponsors/gehrisandro](https://github.com/sponsors/gehrisandro)**
diff --git a/src/Client.php b/src/Client.php
index 6695f789..c13be5e4 100644
--- a/src/Client.php
+++ b/src/Client.php
@@ -31,7 +31,7 @@ public function __construct(private readonly TransporterContract $transporter)
* Given a prompt, the model will return one or more predicted completions, and can also return the probabilities
* of alternative tokens at each position.
*
- * @see https://beta.openai.com/docs/api-reference/completions
+ * @see https://platorm.openai.com/docs/api-reference/completions
*/
public function completions(): Completions
{
@@ -51,7 +51,7 @@ public function chat(): Chat
/**
* Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
*
- * @see https://beta.openai.com/docs/api-reference/embeddings
+ * @see https://platorm.openai.com/docs/api-reference/embeddings
*/
public function embeddings(): Embeddings
{
@@ -71,7 +71,7 @@ public function audio(): Audio
/**
* Given a prompt and an instruction, the model will return an edited version of the prompt.
*
- * @see https://beta.openai.com/docs/api-reference/edits
+ * @see https://platorm.openai.com/docs/api-reference/edits
*/
public function edits(): Edits
{
@@ -81,7 +81,7 @@ public function edits(): Edits
/**
* Files are used to upload documents that can be used with features like Fine-tuning.
*
- * @see https://beta.openai.com/docs/api-reference/files
+ * @see https://platorm.openai.com/docs/api-reference/files
*/
public function files(): Files
{
@@ -91,7 +91,7 @@ public function files(): Files
/**
* List and describe the various models available in the API.
*
- * @see https://beta.openai.com/docs/api-reference/models
+ * @see https://platorm.openai.com/docs/api-reference/models
*/
public function models(): Models
{
@@ -101,7 +101,7 @@ public function models(): Models
/**
* Manage fine-tuning jobs to tailor a model to your specific training data.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes
*/
public function fineTunes(): FineTunes
{
@@ -111,7 +111,7 @@ public function fineTunes(): FineTunes
/**
* Given a input text, outputs if the model classifies it as violating OpenAI's content policy.
*
- * @see https://beta.openai.com/docs/api-reference/moderations
+ * @see https://platorm.openai.com/docs/api-reference/moderations
*/
public function moderations(): Moderations
{
@@ -121,7 +121,7 @@ public function moderations(): Moderations
/**
* Given a prompt and/or an input image, the model will generate a new image.
*
- * @see https://beta.openai.com/docs/api-reference/images
+ * @see https://platorm.openai.com/docs/api-reference/images
*/
public function images(): Images
{
diff --git a/src/Contracts/ClientContract.php b/src/Contracts/ClientContract.php
index 78ec8c88..06d3fd75 100644
--- a/src/Contracts/ClientContract.php
+++ b/src/Contracts/ClientContract.php
@@ -19,7 +19,7 @@ interface ClientContract
* Given a prompt, the model will return one or more predicted completions, and can also return the probabilities
* of alternative tokens at each position.
*
- * @see https://beta.openai.com/docs/api-reference/completions
+ * @see https://platorm.openai.com/docs/api-reference/completions
*/
public function completions(): CompletionsContract;
@@ -33,7 +33,7 @@ public function chat(): ChatContract;
/**
* Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
*
- * @see https://beta.openai.com/docs/api-reference/embeddings
+ * @see https://platorm.openai.com/docs/api-reference/embeddings
*/
public function embeddings(): EmbeddingsContract;
@@ -47,42 +47,42 @@ public function audio(): AudioContract;
/**
* Given a prompt and an instruction, the model will return an edited version of the prompt.
*
- * @see https://beta.openai.com/docs/api-reference/edits
+ * @see https://platorm.openai.com/docs/api-reference/edits
*/
public function edits(): EditsContract;
/**
* Files are used to upload documents that can be used with features like Fine-tuning.
*
- * @see https://beta.openai.com/docs/api-reference/files
+ * @see https://platorm.openai.com/docs/api-reference/files
*/
public function files(): FilesContract;
/**
* List and describe the various models available in the API.
*
- * @see https://beta.openai.com/docs/api-reference/models
+ * @see https://platorm.openai.com/docs/api-reference/models
*/
public function models(): ModelsContract;
/**
* Manage fine-tuning jobs to tailor a model to your specific training data.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes
*/
public function fineTunes(): FineTunesContract;
/**
* Given a input text, outputs if the model classifies it as violating OpenAI's content policy.
*
- * @see https://beta.openai.com/docs/api-reference/moderations
+ * @see https://platorm.openai.com/docs/api-reference/moderations
*/
public function moderations(): ModerationsContract;
/**
* Given a prompt and/or an input image, the model will generate a new image.
*
- * @see https://beta.openai.com/docs/api-reference/images
+ * @see https://platorm.openai.com/docs/api-reference/images
*/
public function images(): ImagesContract;
}
diff --git a/src/Contracts/Resources/CompletionsContract.php b/src/Contracts/Resources/CompletionsContract.php
index d991a2d7..d8dc1d57 100644
--- a/src/Contracts/Resources/CompletionsContract.php
+++ b/src/Contracts/Resources/CompletionsContract.php
@@ -11,7 +11,7 @@ interface CompletionsContract
/**
* Creates a completion for the provided prompt and parameters
*
- * @see https://beta.openai.com/docs/api-reference/completions/create-completion
+ * @see https://platorm.openai.com/docs/api-reference/completions/create-completion
*
* @param array $parameters
*/
@@ -20,7 +20,7 @@ public function create(array $parameters): CreateResponse;
/**
* Creates a streamed completion for the provided prompt and parameters
*
- * @see https://beta.openai.com/docs/api-reference/completions/create-completion
+ * @see https://platorm.openai.com/docs/api-reference/completions/create-completion
*
* @param array $parameters
* @return StreamResponse
diff --git a/src/Contracts/Resources/EditsContract.php b/src/Contracts/Resources/EditsContract.php
index 266fec61..6f37941e 100644
--- a/src/Contracts/Resources/EditsContract.php
+++ b/src/Contracts/Resources/EditsContract.php
@@ -9,7 +9,7 @@ interface EditsContract
/**
* Creates a new edit for the provided input, instruction, and parameters.
*
- * @see https://beta.openai.com/docs/api-reference/edits/create
+ * @see https://platorm.openai.com/docs/api-reference/edits/create
*
* @param array $parameters
*/
diff --git a/src/Contracts/Resources/EmbeddingsContract.php b/src/Contracts/Resources/EmbeddingsContract.php
index 4768bc90..cb769ece 100644
--- a/src/Contracts/Resources/EmbeddingsContract.php
+++ b/src/Contracts/Resources/EmbeddingsContract.php
@@ -9,7 +9,7 @@ interface EmbeddingsContract
/**
* Creates an embedding vector representing the input text.
*
- * @see https://beta.openai.com/docs/api-reference/embeddings/create
+ * @see https://platorm.openai.com/docs/api-reference/embeddings/create
*
* @param array $parameters
*/
diff --git a/src/Contracts/Resources/FilesContract.php b/src/Contracts/Resources/FilesContract.php
index 11b3cb30..0e92f5fa 100644
--- a/src/Contracts/Resources/FilesContract.php
+++ b/src/Contracts/Resources/FilesContract.php
@@ -12,28 +12,28 @@ interface FilesContract
/**
* Returns a list of files that belong to the user's organization.
*
- * @see https://beta.openai.com/docs/api-reference/files/list
+ * @see https://platorm.openai.com/docs/api-reference/files/list
*/
public function list(): ListResponse;
/**
* Returns information about a specific file.
*
- * @see https://beta.openai.com/docs/api-reference/files/retrieve
+ * @see https://platorm.openai.com/docs/api-reference/files/retrieve
*/
public function retrieve(string $file): RetrieveResponse;
/**
* Returns the contents of the specified file.
*
- * @see https://beta.openai.com/docs/api-reference/files/retrieve-content
+ * @see https://platorm.openai.com/docs/api-reference/files/retrieve-content
*/
public function download(string $file): string;
/**
* Upload a file that contains document(s) to be used across various endpoints/features.
*
- * @see https://beta.openai.com/docs/api-reference/files/upload
+ * @see https://platorm.openai.com/docs/api-reference/files/upload
*
* @param array $parameters
*/
@@ -42,7 +42,7 @@ public function upload(array $parameters): CreateResponse;
/**
* Delete a file.
*
- * @see https://beta.openai.com/docs/api-reference/files/delete
+ * @see https://platorm.openai.com/docs/api-reference/files/delete
*/
public function delete(string $file): DeleteResponse;
}
diff --git a/src/Contracts/Resources/FineTunesContract.php b/src/Contracts/Resources/FineTunesContract.php
index bad321f9..9fd43571 100644
--- a/src/Contracts/Resources/FineTunesContract.php
+++ b/src/Contracts/Resources/FineTunesContract.php
@@ -15,7 +15,7 @@ interface FineTunesContract
*
* Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/create
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/create
*
* @param array $parameters
*/
@@ -24,35 +24,35 @@ public function create(array $parameters): RetrieveResponse;
/**
* List your organization's fine-tuning jobs.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/list
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/list
*/
public function list(): ListResponse;
/**
* Gets info about the fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/list
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/list
*/
public function retrieve(string $fineTuneId): RetrieveResponse;
/**
* Immediately cancel a fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/cancel
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/cancel
*/
public function cancel(string $fineTuneId): RetrieveResponse;
/**
* Get fine-grained status updates for a fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/events
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/events
*/
public function listEvents(string $fineTuneId): ListEventsResponse;
/**
* Get streamed fine-grained status updates for a fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/events
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/events
*
* @return StreamResponse
*/
diff --git a/src/Contracts/Resources/ImagesContract.php b/src/Contracts/Resources/ImagesContract.php
index f89e3282..3f4b8c3c 100644
--- a/src/Contracts/Resources/ImagesContract.php
+++ b/src/Contracts/Resources/ImagesContract.php
@@ -11,7 +11,7 @@ interface ImagesContract
/**
* Creates an image given a prompt.
*
- * @see https://beta.openai.com/docs/api-reference/images/create
+ * @see https://platorm.openai.com/docs/api-reference/images/create
*
* @param array $parameters
*/
@@ -20,7 +20,7 @@ public function create(array $parameters): CreateResponse;
/**
* Creates an edited or extended image given an original image and a prompt.
*
- * @see https://beta.openai.com/docs/api-reference/images/create-edit
+ * @see https://platorm.openai.com/docs/api-reference/images/create-edit
*
* @param array $parameters
*/
@@ -29,7 +29,7 @@ public function edit(array $parameters): EditResponse;
/**
* Creates a variation of a given image.
*
- * @see https://beta.openai.com/docs/api-reference/images/create-variation
+ * @see https://platorm.openai.com/docs/api-reference/images/create-variation
*
* @param array $parameters
*/
diff --git a/src/Contracts/Resources/ModelsContract.php b/src/Contracts/Resources/ModelsContract.php
index 1592fe38..77c3a734 100644
--- a/src/Contracts/Resources/ModelsContract.php
+++ b/src/Contracts/Resources/ModelsContract.php
@@ -11,21 +11,21 @@ interface ModelsContract
/**
* Lists the currently available models, and provides basic information about each one such as the owner and availability.
*
- * @see https://beta.openai.com/docs/api-reference/models/list
+ * @see https://platorm.openai.com/docs/api-reference/models/list
*/
public function list(): ListResponse;
/**
* Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
*
- * @see https://beta.openai.com/docs/api-reference/models/retrieve
+ * @see https://platorm.openai.com/docs/api-reference/models/retrieve
*/
public function retrieve(string $model): RetrieveResponse;
/**
* Delete a fine-tuned model. You must have the Owner role in your organization.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/delete-model
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/delete-model
*/
public function delete(string $model): DeleteResponse;
}
diff --git a/src/Contracts/Resources/ModerationsContract.php b/src/Contracts/Resources/ModerationsContract.php
index 4d7f79c9..8a8fe52c 100644
--- a/src/Contracts/Resources/ModerationsContract.php
+++ b/src/Contracts/Resources/ModerationsContract.php
@@ -9,7 +9,7 @@ interface ModerationsContract
/**
* Classifies if text violates OpenAI's Content Policy.
*
- * @see https://beta.openai.com/docs/api-reference/moderations/create
+ * @see https://platorm.openai.com/docs/api-reference/moderations/create
*
* @param array $parameters
*/
diff --git a/src/Resources/Completions.php b/src/Resources/Completions.php
index 51502d48..02f6d765 100644
--- a/src/Resources/Completions.php
+++ b/src/Resources/Completions.php
@@ -18,7 +18,7 @@ final class Completions implements CompletionsContract
/**
* Creates a completion for the provided prompt and parameters
*
- * @see https://beta.openai.com/docs/api-reference/completions/create-completion
+ * @see https://platorm.openai.com/docs/api-reference/completions/create-completion
*
* @param array $parameters
*/
@@ -37,7 +37,7 @@ public function create(array $parameters): CreateResponse
/**
* Creates a streamed completion for the provided prompt and parameters
*
- * @see https://beta.openai.com/docs/api-reference/completions/create-completion
+ * @see https://platorm.openai.com/docs/api-reference/completions/create-completion
*
* @param array $parameters
* @return StreamResponse
diff --git a/src/Resources/Edits.php b/src/Resources/Edits.php
index 77b65e9f..deaa9d3d 100644
--- a/src/Resources/Edits.php
+++ b/src/Resources/Edits.php
@@ -15,7 +15,7 @@ final class Edits implements EditsContract
/**
* Creates a new edit for the provided input, instruction, and parameters.
*
- * @see https://beta.openai.com/docs/api-reference/edits/create
+ * @see https://platorm.openai.com/docs/api-reference/edits/create
*
* @param array $parameters
*/
diff --git a/src/Resources/Embeddings.php b/src/Resources/Embeddings.php
index 4a37443f..6e2cf021 100644
--- a/src/Resources/Embeddings.php
+++ b/src/Resources/Embeddings.php
@@ -15,7 +15,7 @@ final class Embeddings implements EmbeddingsContract
/**
* Creates an embedding vector representing the input text.
*
- * @see https://beta.openai.com/docs/api-reference/embeddings/create
+ * @see https://platorm.openai.com/docs/api-reference/embeddings/create
*
* @param array $parameters
*/
diff --git a/src/Resources/Files.php b/src/Resources/Files.php
index 8147dc18..73ad9e68 100644
--- a/src/Resources/Files.php
+++ b/src/Resources/Files.php
@@ -18,7 +18,7 @@ final class Files implements FilesContract
/**
* Returns a list of files that belong to the user's organization.
*
- * @see https://beta.openai.com/docs/api-reference/files/list
+ * @see https://platorm.openai.com/docs/api-reference/files/list
*/
public function list(): ListResponse
{
@@ -33,7 +33,7 @@ public function list(): ListResponse
/**
* Returns information about a specific file.
*
- * @see https://beta.openai.com/docs/api-reference/files/retrieve
+ * @see https://platorm.openai.com/docs/api-reference/files/retrieve
*/
public function retrieve(string $file): RetrieveResponse
{
@@ -48,7 +48,7 @@ public function retrieve(string $file): RetrieveResponse
/**
* Returns the contents of the specified file.
*
- * @see https://beta.openai.com/docs/api-reference/files/retrieve-content
+ * @see https://platorm.openai.com/docs/api-reference/files/retrieve-content
*/
public function download(string $file): string
{
@@ -60,7 +60,7 @@ public function download(string $file): string
/**
* Upload a file that contains document(s) to be used across various endpoints/features.
*
- * @see https://beta.openai.com/docs/api-reference/files/upload
+ * @see https://platorm.openai.com/docs/api-reference/files/upload
*
* @param array $parameters
*/
@@ -77,7 +77,7 @@ public function upload(array $parameters): CreateResponse
/**
* Delete a file.
*
- * @see https://beta.openai.com/docs/api-reference/files/delete
+ * @see https://platorm.openai.com/docs/api-reference/files/delete
*/
public function delete(string $file): DeleteResponse
{
diff --git a/src/Resources/FineTunes.php b/src/Resources/FineTunes.php
index 91bfb748..44993611 100644
--- a/src/Resources/FineTunes.php
+++ b/src/Resources/FineTunes.php
@@ -21,7 +21,7 @@ final class FineTunes implements FineTunesContract
*
* Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/create
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/create
*
* @param array $parameters
*/
@@ -38,7 +38,7 @@ public function create(array $parameters): RetrieveResponse
/**
* List your organization's fine-tuning jobs.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/list
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/list
*/
public function list(): ListResponse
{
@@ -53,7 +53,7 @@ public function list(): ListResponse
/**
* Gets info about the fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/list
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/list
*/
public function retrieve(string $fineTuneId): RetrieveResponse
{
@@ -68,7 +68,7 @@ public function retrieve(string $fineTuneId): RetrieveResponse
/**
* Immediately cancel a fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/cancel
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/cancel
*/
public function cancel(string $fineTuneId): RetrieveResponse
{
@@ -83,7 +83,7 @@ public function cancel(string $fineTuneId): RetrieveResponse
/**
* Get fine-grained status updates for a fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/events
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/events
*/
public function listEvents(string $fineTuneId): ListEventsResponse
{
@@ -98,7 +98,7 @@ public function listEvents(string $fineTuneId): ListEventsResponse
/**
* Get streamed fine-grained status updates for a fine-tune job.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/events
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/events
*
* @return StreamResponse
*/
diff --git a/src/Resources/Images.php b/src/Resources/Images.php
index c3f1d6a3..ee96cde9 100644
--- a/src/Resources/Images.php
+++ b/src/Resources/Images.php
@@ -17,7 +17,7 @@ final class Images implements ImagesContract
/**
* Creates an image given a prompt.
*
- * @see https://beta.openai.com/docs/api-reference/images/create
+ * @see https://platorm.openai.com/docs/api-reference/images/create
*
* @param array $parameters
*/
@@ -34,7 +34,7 @@ public function create(array $parameters): CreateResponse
/**
* Creates an edited or extended image given an original image and a prompt.
*
- * @see https://beta.openai.com/docs/api-reference/images/create-edit
+ * @see https://platorm.openai.com/docs/api-reference/images/create-edit
*
* @param array $parameters
*/
@@ -51,7 +51,7 @@ public function edit(array $parameters): EditResponse
/**
* Creates a variation of a given image.
*
- * @see https://beta.openai.com/docs/api-reference/images/create-variation
+ * @see https://platorm.openai.com/docs/api-reference/images/create-variation
*
* @param array $parameters
*/
diff --git a/src/Resources/Models.php b/src/Resources/Models.php
index 93194a0e..790515aa 100644
--- a/src/Resources/Models.php
+++ b/src/Resources/Models.php
@@ -17,7 +17,7 @@ final class Models implements ModelsContract
/**
* Lists the currently available models, and provides basic information about each one such as the owner and availability.
*
- * @see https://beta.openai.com/docs/api-reference/models/list
+ * @see https://platorm.openai.com/docs/api-reference/models/list
*/
public function list(): ListResponse
{
@@ -32,7 +32,7 @@ public function list(): ListResponse
/**
* Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
*
- * @see https://beta.openai.com/docs/api-reference/models/retrieve
+ * @see https://platorm.openai.com/docs/api-reference/models/retrieve
*/
public function retrieve(string $model): RetrieveResponse
{
@@ -47,7 +47,7 @@ public function retrieve(string $model): RetrieveResponse
/**
* Delete a fine-tuned model. You must have the Owner role in your organization.
*
- * @see https://beta.openai.com/docs/api-reference/fine-tunes/delete-model
+ * @see https://platorm.openai.com/docs/api-reference/fine-tunes/delete-model
*/
public function delete(string $model): DeleteResponse
{
diff --git a/src/Resources/Moderations.php b/src/Resources/Moderations.php
index 477a3ab5..8abbd483 100644
--- a/src/Resources/Moderations.php
+++ b/src/Resources/Moderations.php
@@ -15,7 +15,7 @@ final class Moderations implements ModerationsContract
/**
* Classifies if text violates OpenAI's Content Policy.
*
- * @see https://beta.openai.com/docs/api-reference/moderations/create
+ * @see https://platorm.openai.com/docs/api-reference/moderations/create
*
* @param array $parameters
*/
diff --git a/tests/Transporters/HttpTransporter.php b/tests/Transporters/HttpTransporter.php
index fa4c1742..0ad767ee 100644
--- a/tests/Transporters/HttpTransporter.php
+++ b/tests/Transporters/HttpTransporter.php
@@ -88,7 +88,7 @@
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
'error' => [
- 'message' => 'Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.',
+ 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.',
'type' => 'invalid_request_error',
'param' => null,
'code' => 'invalid_api_key',
@@ -102,8 +102,8 @@
expect(fn () => $this->http->requestObject($payload))
->toThrow(function (ErrorException $e) {
- expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.')
- ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.')
+ expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
+ ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
->and($e->getErrorCode())->toBe('invalid_api_key')
->and($e->getErrorType())->toBe('invalid_request_error');
});
@@ -376,7 +376,7 @@
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
'error' => [
- 'message' => 'Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.',
+ 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.',
'type' => 'invalid_request_error',
'param' => null,
'code' => 'invalid_api_key',
@@ -390,8 +390,8 @@
expect(fn () => $this->http->requestContent($payload))
->toThrow(function (ErrorException $e) {
- expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.')
- ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.')
+ expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
+ ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
->and($e->getErrorCode())->toBe('invalid_api_key')
->and($e->getErrorType())->toBe('invalid_request_error');
});
@@ -428,7 +428,7 @@
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
'error' => [
- 'message' => 'Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.',
+ 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.',
'type' => 'invalid_request_error',
'param' => null,
'code' => 'invalid_api_key',
@@ -442,8 +442,8 @@
expect(fn () => $this->http->requestStream($payload))
->toThrow(function (ErrorException $e) {
- expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.')
- ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://beta.openai.com.')
+ expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
+ ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
->and($e->getErrorCode())->toBe('invalid_api_key')
->and($e->getErrorType())->toBe('invalid_request_error');
});
From e994c2b257b28a912ca9bd5c1e743a0f9e3a5a78 Mon Sep 17 00:00:00 2001
From: Thorsten <77540900+thoasty-dev@users.noreply.github.com>
Date: Fri, 7 Jul 2023 14:44:05 +0200
Subject: [PATCH 07/12] Update TranscriptionResponseSegment.php
---
src/Responses/Audio/TranscriptionResponseSegment.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Responses/Audio/TranscriptionResponseSegment.php b/src/Responses/Audio/TranscriptionResponseSegment.php
index de31603a..0b15acc4 100644
--- a/src/Responses/Audio/TranscriptionResponseSegment.php
+++ b/src/Responses/Audio/TranscriptionResponseSegment.php
@@ -38,7 +38,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
- * @param array{id: int, seek: int, start: float, end: float, text: string, tokens: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool} $attributes
+ * @param array{id: int, seek: int, start: float, end: float, text: string, tokens: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient?: bool} $attributes
*/
public static function from(array $attributes): self
{
@@ -53,7 +53,7 @@ public static function from(array $attributes): self
$attributes['avg_logprob'],
$attributes['compression_ratio'],
$attributes['no_speech_prob'],
- $attributes['transient'],
+ $attributes['transient'] ?? false,
);
}
From b703dba3bee84c68f14d454f6e30170774d11734 Mon Sep 17 00:00:00 2001
From: Nuno Maduro
Date: Fri, 7 Jul 2023 13:49:58 +0100
Subject: [PATCH 08/12] release: v0.6.3
---
CHANGELOG.md | 4 ++++
composer.json | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 96876072..5e893d9a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ 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.6.3 (2023-07-07)
+### Fixed
+- Breaking change on OpenAI API regarding "transient" field in Audio ([#160](https://github.com/openai-php/client/pull/160))
+
## v0.6.2 (2023-06-23)
### Changed
- Error handling: use error code as exception message if error message is empty ([#150](https://github.com/openai-php/client/pull/150))
diff --git a/composer.json b/composer.json
index 7cefa8fe..2556348b 100644
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,7 @@
"pestphp/pest-plugin-arch": "^2.2.1",
"pestphp/pest-plugin-mock": "^2.0.0",
"pestphp/pest-plugin-type-coverage": "^2.0.0",
- "phpstan/phpstan": "^1.10.22",
+ "phpstan/phpstan": "^1.10.25",
"rector/rector": "^0.16.0",
"symfony/var-dumper": "^6.3.1"
},
From 9165c52649e366aacb3fcf2e609ae34295689288 Mon Sep 17 00:00:00 2001
From: Robert Brodie
Date: Fri, 7 Jul 2023 13:02:44 -0400
Subject: [PATCH 09/12] Update incorrect URL references, fixes
openai-php/client#161
---
tests/Transporters/HttpTransporter.php | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/tests/Transporters/HttpTransporter.php b/tests/Transporters/HttpTransporter.php
index 0ad767ee..d0bbac4d 100644
--- a/tests/Transporters/HttpTransporter.php
+++ b/tests/Transporters/HttpTransporter.php
@@ -88,7 +88,7 @@
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
'error' => [
- 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.',
+ 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.',
'type' => 'invalid_request_error',
'param' => null,
'code' => 'invalid_api_key',
@@ -102,8 +102,8 @@
expect(fn () => $this->http->requestObject($payload))
->toThrow(function (ErrorException $e) {
- expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
- ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
+ expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.')
+ ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.')
->and($e->getErrorCode())->toBe('invalid_api_key')
->and($e->getErrorType())->toBe('invalid_request_error');
});
@@ -376,7 +376,7 @@
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
'error' => [
- 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.',
+ 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.',
'type' => 'invalid_request_error',
'param' => null,
'code' => 'invalid_api_key',
@@ -390,8 +390,8 @@
expect(fn () => $this->http->requestContent($payload))
->toThrow(function (ErrorException $e) {
- expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
- ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
+ expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.')
+ ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.')
->and($e->getErrorCode())->toBe('invalid_api_key')
->and($e->getErrorType())->toBe('invalid_request_error');
});
@@ -428,7 +428,7 @@
$response = new Response(401, ['Content-Type' => 'application/json; charset=utf-8'], json_encode([
'error' => [
- 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.',
+ 'message' => 'Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.',
'type' => 'invalid_request_error',
'param' => null,
'code' => 'invalid_api_key',
@@ -442,8 +442,8 @@
expect(fn () => $this->http->requestStream($payload))
->toThrow(function (ErrorException $e) {
- expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
- ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platormopenai.com.')
+ expect($e->getMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.')
+ ->and($e->getErrorMessage())->toBe('Incorrect API key provided: foo. You can find your API key at https://platform.openai.com.')
->and($e->getErrorCode())->toBe('invalid_api_key')
->and($e->getErrorType())->toBe('invalid_request_error');
});
From ee207273fd71120d1259e81d52a00c63ea3d3343 Mon Sep 17 00:00:00 2001
From: Sander Muller
Date: Tue, 18 Jul 2023 17:35:59 +0200
Subject: [PATCH 10/12] Update TranslationResponseSegment.php
---
src/Responses/Audio/TranslationResponseSegment.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Responses/Audio/TranslationResponseSegment.php b/src/Responses/Audio/TranslationResponseSegment.php
index af53cd93..eb22a8b1 100644
--- a/src/Responses/Audio/TranslationResponseSegment.php
+++ b/src/Responses/Audio/TranslationResponseSegment.php
@@ -38,7 +38,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
- * @param array{id: int, seek: int, start: float, end: float, text: string, tokens: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool} $attributes
+ * @param array{id: int, seek: int, start: float, end: float, text: string, tokens: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient?: bool} $attributes
*/
public static function from(array $attributes): self
{
@@ -53,7 +53,7 @@ public static function from(array $attributes): self
$attributes['avg_logprob'],
$attributes['compression_ratio'],
$attributes['no_speech_prob'],
- $attributes['transient'],
+ $attributes['transient'] ?? false,
);
}
From 7c9994f79c44c3b56862d207e154f992a2306404 Mon Sep 17 00:00:00 2001
From: Connor Tumbleson
Date: Wed, 2 Aug 2023 02:43:15 -0400
Subject: [PATCH 11/12] Fix Lint failures. (#179)
* style: prefer ? for null
* style: null type can be removed if default is null
* style: prefer pint spacing, with removed rector null param
---
src/Responses/Chat/CreateStreamedResponseDelta.php | 2 +-
src/Testing/ClientFake.php | 2 +-
src/Testing/Resources/Concerns/Testable.php | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/Responses/Chat/CreateStreamedResponseDelta.php b/src/Responses/Chat/CreateStreamedResponseDelta.php
index 7b58a43f..5d4511f9 100644
--- a/src/Responses/Chat/CreateStreamedResponseDelta.php
+++ b/src/Responses/Chat/CreateStreamedResponseDelta.php
@@ -33,7 +33,7 @@ public function toArray(): array
$data = array_filter([
'role' => $this->role,
'content' => $this->content,
- ], fn (string|null $value): bool => ! is_null($value));
+ ], fn (?string $value): bool => ! is_null($value));
if ($this->functionCall instanceof CreateStreamedResponseFunctionCall) {
$data['content'] = null;
diff --git a/src/Testing/ClientFake.php b/src/Testing/ClientFake.php
index e58d75e2..e1106913 100644
--- a/src/Testing/ClientFake.php
+++ b/src/Testing/ClientFake.php
@@ -41,7 +41,7 @@ public function addResponses(array $responses): void
$this->responses = [...$this->responses, ...$responses];
}
- public function assertSent(string $resource, callable|int|null $callback = null): void
+ public function assertSent(string $resource, callable|int $callback = null): void
{
if (is_int($callback)) {
$this->assertSentTimes($resource, $callback);
diff --git a/src/Testing/Resources/Concerns/Testable.php b/src/Testing/Resources/Concerns/Testable.php
index 44aeb38f..aa4a989d 100644
--- a/src/Testing/Resources/Concerns/Testable.php
+++ b/src/Testing/Resources/Concerns/Testable.php
@@ -16,19 +16,19 @@ public function __construct(protected ClientFake $fake)
abstract protected function resource(): string;
/**
- * @param array|string|null $parameters
+ * @param array|string $parameters
*/
- protected function record(string $method, array|string|null $parameters = null): ResponseContract|StreamResponse|string
+ protected function record(string $method, array|string $parameters = null): ResponseContract|StreamResponse|string
{
return $this->fake->record(new TestRequest($this->resource(), $method, $parameters));
}
- public function assertSent(callable|int|null $callback = null): void
+ public function assertSent(callable|int $callback = null): void
{
$this->fake->assertSent($this->resource(), $callback);
}
- public function assertNotSent(callable|int|null $callback = null): void
+ public function assertNotSent(callable|int $callback = null): void
{
$this->fake->assertNotSent($this->resource(), $callback);
}
From 0d64fdba00f95b5c3f77ad85c93f353f49dd8d35 Mon Sep 17 00:00:00 2001
From: Connor Tumbleson
Date: Thu, 3 Aug 2023 02:18:35 -0400
Subject: [PATCH 12/12] Add missing moderation enums. (#178)
* fix: add missing moderation category enums
* test: adjust tests for assertions on moderation categories
---
src/Enums/Moderations/Category.php | 4 ++++
.../Fixtures/Moderations/CreateResponseFixture.php | 8 ++++++++
tests/Fixtures/Moderation.php | 8 ++++++++
tests/Resources/Moderations.php | 7 ++++++-
tests/Responses/Moderations/CreateResponseResult.php | 2 +-
5 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/Enums/Moderations/Category.php b/src/Enums/Moderations/Category.php
index 3637ec2a..34bdbaf6 100644
--- a/src/Enums/Moderations/Category.php
+++ b/src/Enums/Moderations/Category.php
@@ -8,7 +8,11 @@ enum Category: string
{
case Hate = 'hate';
case HateThreatening = 'hate/threatening';
+ case Harassment = 'harassment';
+ case HarassmentThreatening = 'harassment/threatening';
case SelfHarm = 'self-harm';
+ case SelfHarmIntent = 'self-harm/intent';
+ case SelfHarmInstructions = 'self-harm/instructions';
case Sexual = 'sexual';
case SexualMinors = 'sexual/minors';
case Violence = 'violence';
diff --git a/src/Testing/Responses/Fixtures/Moderations/CreateResponseFixture.php b/src/Testing/Responses/Fixtures/Moderations/CreateResponseFixture.php
index c39c313d..0c03c74c 100644
--- a/src/Testing/Responses/Fixtures/Moderations/CreateResponseFixture.php
+++ b/src/Testing/Responses/Fixtures/Moderations/CreateResponseFixture.php
@@ -12,7 +12,11 @@ final class CreateResponseFixture
'categories' => [
'hate' => false,
'hate/threatening' => true,
+ 'harassment' => false,
+ 'harassment/threatening' => false,
'self-harm' => false,
+ 'self-harm/intent' => false,
+ 'self-harm/instructions' => false,
'sexual' => false,
'sexual/minors' => false,
'violence' => true,
@@ -21,7 +25,11 @@ final class CreateResponseFixture
'category_scores' => [
'hate' => 0.22714105248451233,
'hate/threatening' => 0.4132447838783264,
+ 'harassment' => 0.1602763684674149,
+ 'harassment/threatening' => 0.1602763684674149,
'self-harm' => 0.005232391878962517,
+ 'self-harm/intent' => 0.005134391873962517,
+ 'self-harm/instructions' => 0.005132591874962517,
'sexual' => 0.01407341007143259,
'sexual/minors' => 0.0038522258400917053,
'violence' => 0.9223177433013916,
diff --git a/tests/Fixtures/Moderation.php b/tests/Fixtures/Moderation.php
index 6bcb88f2..322cbf25 100644
--- a/tests/Fixtures/Moderation.php
+++ b/tests/Fixtures/Moderation.php
@@ -13,7 +13,11 @@ function moderationResource(): array
'categories' => [
'hate' => false,
'hate/threatening' => true,
+ 'harassment' => false,
+ 'harassment/threatening' => false,
'self-harm' => false,
+ 'self-harm/intent' => false,
+ 'self-harm/instructions' => false,
'sexual' => false,
'sexual/minors' => false,
'violence' => true,
@@ -22,7 +26,11 @@ function moderationResource(): array
'category_scores' => [
'hate' => 0.22714105248451233,
'hate/threatening' => 0.4132447838783264,
+ 'harassment' => 0.1602763684674149,
+ 'harassment/threatening' => 0.1602763684674149,
'self-harm' => 0.005232391878962517,
+ 'self-harm/intent' => 0.005134391873962517,
+ 'self-harm/instructions' => 0.005132591874962517,
'sexual' => 0.01407341007143259,
'sexual/minors' => 0.0038522258400917053,
'violence' => 0.9223177433013916,
diff --git a/tests/Resources/Moderations.php b/tests/Resources/Moderations.php
index 0a30f508..99248acb 100644
--- a/tests/Resources/Moderations.php
+++ b/tests/Resources/Moderations.php
@@ -25,11 +25,16 @@
expect($result->results[0])
->flagged->toBeTrue()
- ->categories->toHaveCount(7)
+ ->categories->toHaveCount(11)
->each->toBeInstanceOf(CreateResponseCategory::class);
expect($result->results[0]->categories[Category::Hate->value])
->category->toBe(Category::Hate)
->violated->toBe(false)
->score->toBe(0.22714105248451233);
+
+ expect($result->results[0]->categories[Category::Violence->value])
+ ->category->toBe(Category::Violence)
+ ->violated->toBe(true)
+ ->score->toBe(0.9223177433013916);
});
diff --git a/tests/Responses/Moderations/CreateResponseResult.php b/tests/Responses/Moderations/CreateResponseResult.php
index 99c57903..5196a984 100644
--- a/tests/Responses/Moderations/CreateResponseResult.php
+++ b/tests/Responses/Moderations/CreateResponseResult.php
@@ -8,7 +8,7 @@
expect($result)
->flagged->toBeTrue()
- ->categories->toHaveCount(7)
+ ->categories->toHaveCount(11)
->each->toBeInstanceOf(CreateResponseCategory::class);
});