Skip to content

Commit cb0c57c

Browse files
committed
fix: support null on 'output_text'
1 parent e05e470 commit cb0c57c

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/Responses/Responses/CreateResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static function from(array $attributes, MetaInformation $meta): self
157157
maxOutputTokens: $attributes['max_output_tokens'],
158158
model: $attributes['model'],
159159
output: $output,
160-
outputText: implode(' ', $texts),
160+
outputText: empty($texts) ? null : implode(' ', $texts),
161161
parallelToolCalls: $attributes['parallel_tool_calls'],
162162
previousResponseId: $attributes['previous_response_id'],
163163
reasoning: isset($attributes['reasoning'])

tests/Fixtures/Responses.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,25 @@ function outputMessage(): array
290290
];
291291
}
292292

293+
/**
294+
* @return array<string, mixed>
295+
*/
296+
function outputMessageOnlyRefusal(): array
297+
{
298+
return [
299+
'content' => [
300+
[
301+
'refusal' => 'The assistant refused to answer.',
302+
'type' => 'refusal',
303+
],
304+
],
305+
'id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c',
306+
'role' => 'assistant',
307+
'status' => 'completed',
308+
'type' => 'message',
309+
];
310+
}
311+
293312
/**
294313
* @return array<string, mixed>
295314
*/

tests/Responses/Responses/CreateResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@
5656
->toBe($expected);
5757
});
5858

59+
test('to array with no messages', function () {
60+
$payload = createResponseResource();
61+
$payload['output'] = [
62+
outputMessageOnlyRefusal(),
63+
];
64+
65+
$response = CreateResponse::from($payload, meta());
66+
67+
expect($response->toArray())
68+
->toBeArray()
69+
->outputText->toBeNull();
70+
});
71+
5972
test('fake', function () {
6073
$response = CreateResponse::fake();
6174

0 commit comments

Comments
 (0)