From 275f1d66cf71e6615e5bef4dbcca398062b2aad9 Mon Sep 17 00:00:00 2001 From: gehrisandro Date: Fri, 10 Nov 2023 23:40:07 +0100 Subject: [PATCH] WIP: add tests --- src/Resources/ThreadsRunsSteps.php | 4 +- .../Runs/Steps/ThreadRunStepListResponse.php | 6 +- .../Runs/Steps/ThreadRunStepResponse.php | 27 +++++---- .../ThreadRunStepListResponseFixture.php | 36 +++++++++++ .../Steps/ThreadRunStepResponseFixture.php | 28 +++++++++ tests/Fixtures/ThreadRunSteps.php | 60 +++++++++++++++++++ .../Runs/Steps/ThreadRunStepListResponse.php | 50 ++++++++++++++++ .../Runs/Steps/ThreadRunStepResponse.php | 57 ++++++++++++++++++ .../ThreadRunStepResponseCodeInterpreter.php | 26 ++++++++ ...StepResponseCodeInterpreterOutputImage.php | 25 ++++++++ ...esponseCodeInterpreterOutputImageImage.php | 23 +++++++ ...nStepResponseCodeInterpreterOutputLogs.php | 24 ++++++++ .../ThreadRunStepResponseCodeToolCall.php | 26 ++++++++ .../Steps/ThreadRunStepResponseFunction.php | 25 ++++++++ .../ThreadRunStepResponseFunctionToolCall.php | 26 ++++++++ .../ThreadRunStepResponseMessageCreation.php | 23 +++++++ ...StepResponseMessageCreationStepDetails.php | 25 ++++++++ ...ThreadRunStepResponseRetrievalToolCall.php | 25 ++++++++ ...eadRunStepResponseToolCallsStepDetails.php | 26 ++++++++ 19 files changed, 526 insertions(+), 16 deletions(-) create mode 100644 src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepListResponseFixture.php create mode 100644 src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepResponseFixture.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php create mode 100644 tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php diff --git a/src/Resources/ThreadsRunsSteps.php b/src/Resources/ThreadsRunsSteps.php index ddf7762b..a914956f 100644 --- a/src/Resources/ThreadsRunsSteps.php +++ b/src/Resources/ThreadsRunsSteps.php @@ -23,7 +23,7 @@ public function retrieve(string $threadId, string $runId, string $stepId): Threa { $payload = Payload::retrieve('threads/'.$threadId.'/runs/'.$runId.'/steps', $stepId); - /** @var Response}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}> $response */ + /** @var Response}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}> $response */ $response = $this->transporter->requestObject($payload); return ThreadRunStepResponse::from($response->data(), $response->meta()); @@ -40,7 +40,7 @@ public function list(string $threadId, string $runId, array $parameters = []): T { $payload = Payload::list('threads/'.$threadId.'/runs/'.$runId.'/steps', $parameters); - /** @var Response}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */ + /** @var Response}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */ $response = $this->transporter->requestObject($payload); return ThreadRunStepListResponse::from($response->data(), $response->meta()); diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php index dc5e3110..3b3ee293 100644 --- a/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}>, first_id: ?string, last_id: ?string, has_more: bool}> + * @implements ResponseContract}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}>, first_id: ?string, last_id: ?string, has_more: bool}> */ final class ThreadRunStepListResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}>, first_id: ?string, last_id: ?string, has_more: bool}> + * @use ArrayAccessible}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}>, first_id: ?string, last_id: ?string, has_more: bool}> */ use ArrayAccessible; @@ -40,7 +40,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{object: string, data: array}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes + * @param array{object: string, data: array}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php index a7e5f602..a7cb54db 100644 --- a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}> + * @implements ResponseContract}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}> */ final class ThreadRunStepResponse implements ResponseContract { /** - * @use ArrayAccessible}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array}> + * @use ArrayAccessible}}|array{id: string, type: string, retrieval: array}|array{id: string, type: string, function: array{name: string, arguments: string, output: ?string}}>}|array{type: string, message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array}> */ use ArrayAccessible; @@ -50,7 +50,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{id: string, object: string, created_at: int, thread_id: string, assistant_id: string, run_id: string, type: string, status: string, step_details: array{type: 'tool_calls', tool_calls: array}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata: ?array} $attributes + * @param array{id: string, object: string, created_at: int, thread_id: string, assistant_id: string, run_id: string, type: string, status: string, step_details: array{type: 'tool_calls', tool_calls: array}}|array{id: string, type: 'retrieval', retrieval: array}|array{id: string, type: 'function', function: array{name: string, arguments: string, output: ?string}}>}|array{type: 'message_creation', message_creation: array{message_id: string}}, last_error: ?array{code: string, message: string}, expires_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, metadata?: array} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { @@ -84,22 +84,27 @@ public static function from(array $attributes, MetaInformation $meta): self */ public function toArray(): array { - return [ + $data = [ 'id' => $this->id, 'object' => $this->object, 'created_at' => $this->createdAt, - 'thread_id' => $this->threadId, - 'assistant_id' => $this->assistantId, 'run_id' => $this->runId, + 'assistant_id' => $this->assistantId, + 'thread_id' => $this->threadId, 'type' => $this->type, 'status' => $this->status, - 'step_details' => $this->stepDetails->toArray(), - 'last_error' => $this->lastError?->toArray(), - 'expires_at' => $this->expiresAt, 'cancelled_at' => $this->cancelledAt, - 'failed_at' => $this->failedAt, 'completed_at' => $this->completedAt, - 'metadata' => $this->metadata, + 'expires_at' => $this->expiresAt, + 'failed_at' => $this->failedAt, + 'last_error' => $this->lastError?->toArray(), + 'step_details' => $this->stepDetails->toArray(), ]; + + if ($this->metadata !== []) { + $data['metadata'] = $this->metadata; + } + + return $data; } } diff --git a/src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepListResponseFixture.php b/src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepListResponseFixture.php new file mode 100644 index 00000000..0e71a4b8 --- /dev/null +++ b/src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepListResponseFixture.php @@ -0,0 +1,36 @@ + 'list', + 'data' => [ + [ + 'id' => 'step_1spQXgbAabXFm1YXrwiGIMUz', + 'object' => 'thread.run.step', + 'created_at' => 1_699_564_106, + 'run_id' => 'run_fYijubpOJsKDnvtACWBS8C8r', + 'assistant_id' => 'asst_EopvUEMh90bxkNRYEYM81Orc', + 'thread_id' => 'thread_3WdOgtVuhD8aUIEx774Whkvo', + 'type' => 'message_creation', + 'status' => 'completed', + 'cancelled_at' => null, + 'completed_at' => 1_699_564_119, + 'expires_at' => null, + 'failed_at' => null, + 'last_error' => null, + 'step_details' => [ + 'type' => 'message_creation', + 'message_creation' => [ + 'message_id' => 'msg_i404PxKbB92d0JAmdOIcX7vA', + ], + ], + ], + ], + 'first_id' => 'step_1spQXgbAabXFm1YXrwiGIMUz', + 'last_id' => 'step_1spQXgbAabXFm1YXrwiGIMUz', + 'has_more' => false, + ]; +} diff --git a/src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepResponseFixture.php b/src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepResponseFixture.php new file mode 100644 index 00000000..1e4105ac --- /dev/null +++ b/src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepResponseFixture.php @@ -0,0 +1,28 @@ + 'step_1spQXgbAabXFm1YXrwiGIMUz', + 'object' => 'thread.run.step', + 'created_at' => 1_699_564_106, + 'run_id' => 'run_fYijubpOJsKDnvtACWBS8C8r', + 'assistant_id' => 'asst_EopvUEMh90bxkNRYEYM81Orc', + 'thread_id' => 'thread_3WdOgtVuhD8aUIEx774Whkvo', + 'type' => 'message_creation', + 'status' => 'completed', + 'cancelled_at' => null, + 'completed_at' => 1_699_564_119, + 'expires_at' => null, + 'failed_at' => null, + 'last_error' => null, + 'step_details' => [ + 'type' => 'message_creation', + 'message_creation' => [ + 'message_id' => 'msg_i404PxKbB92d0JAmdOIcX7vA', + ], + ], + ]; +} diff --git a/tests/Fixtures/ThreadRunSteps.php b/tests/Fixtures/ThreadRunSteps.php index c07d5bbf..ef811c6c 100644 --- a/tests/Fixtures/ThreadRunSteps.php +++ b/tests/Fixtures/ThreadRunSteps.php @@ -28,6 +28,66 @@ function threadRunStepResource(): array ]; } +/** + * @return array + */ +function threadRunStepWithCodeInterpreterOutputResource(): array +{ + return [ + 'id' => 'step_1spQXgbAabXFm1YXrwiGIMUz', + 'object' => 'thread.run.step', + 'created_at' => 1699564106, + 'run_id' => 'run_fYijubpOJsKDnvtACWBS8C8r', + 'assistant_id' => 'asst_EopvUEMh90bxkNRYEYM81Orc', + 'thread_id' => 'thread_3WdOgtVuhD8aUIEx774Whkvo', + 'type' => 'message_creation', + 'status' => 'completed', + 'cancelled_at' => null, + 'completed_at' => 1699564119, + 'expires_at' => null, + 'failed_at' => null, + 'last_error' => null, + 'step_details' => [ + 'type' => 'tool_calls', + 'tool_calls' => [ + [ + 'id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj', + 'type' => 'code_interpreter', + 'code_interpreter' => [ + 'input' => 'The input string.', + 'outputs' => [ + [ + 'type' => 'image', + 'image' => [ + 'file_id' => 'file-6EsV79Y261TEmi0PY5iHbZdS', + ], + ], + [ + 'type' => 'logs', + 'logs' => 'The log output content.', + ], + ], + ], + ], + [ + 'id' => 'call_Fbg14X7kZF2WDzlPhpQ167De', + 'type' => 'function', + 'function' => [ + 'name' => 'add', + 'arguments' => '{ "a": 5, "b": 7 }', + 'output' => '12', + ], + ], + [ + 'id' => 'call_mNs14X7kZF2WDzlPhpQ163Co', + 'type' => 'retrieval', + 'retrieval' => [], + ], + ], + ], + ]; +} + /** * @return array */ diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php new file mode 100644 index 00000000..d78b0dcb --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php @@ -0,0 +1,50 @@ +toBeInstanceOf(ThreadRunStepListResponse::class) + ->object->toBe('list') + ->data->toBeArray()->toHaveCount(2) + ->data->each->toBeInstanceOf(ThreadRunStepResponse::class) + ->meta()->toBeInstanceOf(MetaInformation::class); +}); + +test('as array accessible', function () { + $response = ThreadRunStepListResponse::from(threadRunStepListResource(), meta()); + + expect($response['object'])->toBe('list'); +}); + +test('to array', function () { + $response = ThreadRunStepListResponse::from(threadRunStepListResource(), meta()); + + expect($response->toArray()) + ->toBeArray() + ->toBe(threadRunStepListResource()); +}); + +test('fake', function () { + $response = ThreadRunStepListResponse::fake(); + + expect($response['data'][0]) + ->id->toBe('step_1spQXgbAabXFm1YXrwiGIMUz'); +}); + +test('fake with override', function () { + $response = ThreadRunStepListResponse::fake([ + 'data' => [ + [ + 'id' => 'step_1234', + ], + ], + ]); + + expect($response['data'][0]) + ->id->toBe('step_1234'); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php new file mode 100644 index 00000000..64b9a9e1 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php @@ -0,0 +1,57 @@ +id->toBe('step_1spQXgbAabXFm1YXrwiGIMUz') + ->object->toBe('thread.run.step') + ->createdAt->toBe(1699564106) + ->runId->toBe('run_fYijubpOJsKDnvtACWBS8C8r') + ->assistantId->toBe('asst_EopvUEMh90bxkNRYEYM81Orc') + ->threadId->toBe('thread_3WdOgtVuhD8aUIEx774Whkvo') + ->type->toBe('message_creation') + ->status->toBe('completed') + ->cancelledAt->toBeNull() + ->completedAt->toBe(1699564119) + ->expiresAt->toBeNull() + ->failedAt->toBeNull() + ->last_error->toBeNull() + ->stepDetails->toBeInstanceOf(ThreadRunStepResponseMessageCreationStepDetails::class) + ->metadata->toBe([]) + ->meta()->toBeInstanceOf(MetaInformation::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponse::from(threadRunStepResource(), meta()); + + expect($result['id']) + ->toBe('step_1spQXgbAabXFm1YXrwiGIMUz'); +}); + +test('to array', function () { + $result = ThreadRunStepResponse::from(threadRunStepResource(), meta()); + + expect($result->toArray()) + ->toBe(threadRunStepResource()); +}); + +test('fake', function () { + $response = ThreadRunStepResponse::fake(); + + expect($response) + ->id->toBe('step_1spQXgbAabXFm1YXrwiGIMUz'); +}); + +test('fake with override', function () { + $response = ThreadRunStepResponse::fake([ + 'id' => 'step_1234', + ]); + + expect($response) + ->id->toBe('step_1234'); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php new file mode 100644 index 00000000..7d489dd5 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php @@ -0,0 +1,26 @@ +input->toBe('The input string.') + ->outputs->toBeArray() + ->outputs->{0}->toBeInstanceOf(ThreadRunStepResponseCodeInterpreterOutputImage::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseCodeInterpreter::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']); + + expect($result['input']) + ->toBe('The input string.'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseCodeInterpreter::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php new file mode 100644 index 00000000..a8cf2e42 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php @@ -0,0 +1,25 @@ +type->toBe('image') + ->image->toBeInstanceOf(ThreadRunStepResponseCodeInterpreterOutputImageImage::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseCodeInterpreterOutputImage::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]); + + expect($result['type']) + ->toBe('image'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseCodeInterpreterOutputImage::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php new file mode 100644 index 00000000..71e7183a --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php @@ -0,0 +1,23 @@ +fileId->toBe('file-6EsV79Y261TEmi0PY5iHbZdS'); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseCodeInterpreterOutputImageImage::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]['image']); + + expect($result['file_id']) + ->toBe('file-6EsV79Y261TEmi0PY5iHbZdS'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseCodeInterpreterOutputImageImage::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]['image']); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][0]['image']); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php new file mode 100644 index 00000000..626aa513 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php @@ -0,0 +1,24 @@ +type->toBe('logs') + ->logs->toBe('The log output content.'); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseCodeInterpreterOutputLogs::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][1]); + + expect($result['type']) + ->toBe('logs'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseCodeInterpreterOutputLogs::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][1]); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]['code_interpreter']['outputs'][1]); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php new file mode 100644 index 00000000..54d5377f --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php @@ -0,0 +1,26 @@ +id->toBe('call_KSg14X7kZF2WDzlPhpQ168Mj') + ->type->toBe('code_interpreter') + ->codeInterpreter->toBeInstanceOf(ThreadRunStepResponseCodeInterpreter::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseCodeToolCall::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]); + + expect($result['id']) + ->toBe('call_KSg14X7kZF2WDzlPhpQ168Mj'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseCodeToolCall::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][0]); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php new file mode 100644 index 00000000..af680d5c --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php @@ -0,0 +1,25 @@ +name->toBe('add') + ->arguments->toBe('{ "a": 5, "b": 7 }') + ->output->toBe('12'); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseFunction::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]['function']); + + expect($result['name']) + ->toBe('add'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseFunction::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]['function']); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]['function']); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php new file mode 100644 index 00000000..fd5caa56 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php @@ -0,0 +1,26 @@ +id->toBe('call_Fbg14X7kZF2WDzlPhpQ167De') + ->type->toBe('function') + ->function->toBeInstanceOf(ThreadRunStepResponseFunction::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseFunctionToolCall::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]); + + expect($result['id']) + ->toBe('call_Fbg14X7kZF2WDzlPhpQ167De'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseFunctionToolCall::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php new file mode 100644 index 00000000..31f1f0a1 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php @@ -0,0 +1,23 @@ +messageId->toBe('msg_i404PxKbB92d0JAmdOIcX7vA'); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseMessageCreation::from(threadRunStepResource()['step_details']['message_creation']); + + expect($result['message_id']) + ->toBe('msg_i404PxKbB92d0JAmdOIcX7vA'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseMessageCreation::from(threadRunStepResource()['step_details']['message_creation']); + + expect($result->toArray()) + ->toBe(threadRunStepResource()['step_details']['message_creation']); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php new file mode 100644 index 00000000..55f15569 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php @@ -0,0 +1,25 @@ +type->toBe('message_creation') + ->messageCreation->toBeInstanceOf(ThreadRunStepResponseMessageCreation::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseMessageCreationStepDetails::from(threadRunStepResource()['step_details']); + + expect($result['type']) + ->toBe('message_creation'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseMessageCreationStepDetails::from(threadRunStepResource()['step_details']); + + expect($result->toArray()) + ->toBe(threadRunStepResource()['step_details']); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php new file mode 100644 index 00000000..de4e964e --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php @@ -0,0 +1,25 @@ +id->toBe('call_mNs14X7kZF2WDzlPhpQ163Co') + ->type->toBe('retrieval') + ->retrieval->toBe([]); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseRetrievalToolCall::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][2]); + + expect($result['id']) + ->toBe('call_mNs14X7kZF2WDzlPhpQ163Co'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseRetrievalToolCall::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][2]); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][2]); +}); diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php new file mode 100644 index 00000000..e165f936 --- /dev/null +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php @@ -0,0 +1,26 @@ +type->toBe('tool_calls') + ->toolCalls->toBeArray() + ->toolCalls->{0}->toBeInstanceOf(ThreadRunStepResponseCodeToolCall::class); +}); + +test('as array accessible', function () { + $result = ThreadRunStepResponseToolCallsStepDetails::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']); + + expect($result['type']) + ->toBe('tool_calls'); +}); + +test('to array', function () { + $result = ThreadRunStepResponseToolCallsStepDetails::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']); + + expect($result->toArray()) + ->toBe(threadRunStepWithCodeInterpreterOutputResource()['step_details']); +});