diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php index 6861384e..589d9423 100644 --- a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php @@ -37,7 +37,7 @@ public static function from(array $attributes): self return new self( $attributes['name'], $attributes['arguments'], - $attributes['output'], + $attributes['output'] ?? null, ); } diff --git a/tests/Fixtures/ThreadRunSteps.php b/tests/Fixtures/ThreadRunSteps.php index 454b313e..73c28206 100644 --- a/tests/Fixtures/ThreadRunSteps.php +++ b/tests/Fixtures/ThreadRunSteps.php @@ -89,6 +89,42 @@ function threadRunStepWithCodeInterpreterOutputResource(): array ]; } +/** + * @return array + */ +function threadRunStepWithFunctionCallPendingOutputResource(): 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' => 'tool_calls', + 'status' => 'in_progress', + 'cancelled_at' => null, + 'completed_at' => 1699564119, + 'expires_at' => null, + 'failed_at' => null, + 'last_error' => null, + 'step_details' => [ + 'type' => 'tool_calls', + 'tool_calls' => [ + [ + 'id' => 'call_Fbg14X7kZF2WDzlPhpQ167De', + 'type' => 'function', + 'function' => [ + 'name' => 'add', + 'arguments' => '{ "a": 5, "b": 7 }', + ], + ], + ], + ], + 'metadata' => ['name' => 'the step name'], + ]; +} + /** * @return array */ diff --git a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php index af680d5c..644cdf09 100644 --- a/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php +++ b/tests/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php @@ -10,6 +10,14 @@ ->output->toBe('12'); }); +test('from function call with output not submitted', function () { + $result = ThreadRunStepResponseFunction::from(threadRunStepWithFunctionCallPendingOutputResource()['step_details']['tool_calls'][0]['function']); + expect($result) + ->name->toBe('add') + ->arguments->toBe('{ "a": 5, "b": 7 }') + ->output->toBeEmpty(); +}); + test('as array accessible', function () { $result = ThreadRunStepResponseFunction::from(threadRunStepWithCodeInterpreterOutputResource()['step_details']['tool_calls'][1]['function']);