Skip to content

Commit d4108e3

Browse files
qwertyquestNate Brown
andauthored
Fix(OpenAI): Add filename property to OutputMessageContentOutputTextAnnotationsFileCitation (#696)
* Add `filename` property to OutputMessageContentOutputTextAnnotationsFileCitation * add test for `OutputMessageContentOutputTextAnnotationsFileCitation` --------- Co-authored-by: Nate Brown <[email protected]>
1 parent e79ab01 commit d4108e3

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsFileCitation.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
use OpenAI\Testing\Responses\Concerns\Fakeable;
1010

1111
/**
12-
* @phpstan-type FileCitationType array{file_id: string, index: int, type: 'file_citation'}
12+
* @phpstan-type FileCitationType array{file_id: string, filename: string, index: int, type: 'file_citation'}
1313
*
1414
* @implements ResponseContract<FileCitationType>
1515
*/
1616
final class OutputMessageContentOutputTextAnnotationsFileCitation implements ResponseContract
1717
{
1818
/**
19-
* @use ArrayAccessible<array{file_id: string, index: int, type: 'file_citation'}>
19+
* @use ArrayAccessible<array{file_id: string, filename: string, index: int, type: 'file_citation'}>
2020
*/
2121
use ArrayAccessible;
2222

@@ -27,17 +27,19 @@ final class OutputMessageContentOutputTextAnnotationsFileCitation implements Res
2727
*/
2828
private function __construct(
2929
public readonly string $fileId,
30+
public readonly string $filename,
3031
public readonly int $index,
3132
public readonly string $type,
3233
) {}
3334

3435
/**
35-
* @param array{file_id: string, index: int, type: 'file_citation'} $attributes
36+
* @param array{file_id: string, filename: string, index: int, type: 'file_citation'} $attributes
3637
*/
3738
public static function from(array $attributes): self
3839
{
3940
return new self(
4041
fileId: $attributes['file_id'],
42+
filename: $attributes['filename'],
4143
index: $attributes['index'],
4244
type: $attributes['type'],
4345
);
@@ -50,6 +52,7 @@ public function toArray(): array
5052
{
5153
return [
5254
'file_id' => $this->fileId,
55+
'filename' => $this->filename,
5356
'index' => $this->index,
5457
'type' => $this->type,
5558
];

tests/Fixtures/Responses.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,18 @@ function outputAnnotationMessage(): array
579579
'type' => 'url_citation',
580580
'url' => 'https://.../?utm_source=chatgpt.com',
581581
],
582+
[
583+
'file_id' => 'file-8aTRXYAhp5PbDF5R5P9Rky',
584+
'filename' => 'document.pdf',
585+
'index' => 138,
586+
'type' => 'file_citation',
587+
],
588+
[
589+
'file_id' => 'file-9cPRXMKyn1BmDT1K9J8Xxa',
590+
'filename' => 'example-file.md',
591+
'index' => 294,
592+
'type' => 'file_citation',
593+
],
582594
],
583595
'text' => 'As of today, March 9, 2025, one notable positive news story...',
584596
'type' => 'output_text',
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use OpenAI\Responses\Responses\Output\OutputMessageContentOutputTextAnnotationsFileCitation;
4+
5+
test('from', function () {
6+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][3];
7+
$response = OutputMessageContentOutputTextAnnotationsFileCitation::from($annotation);
8+
9+
expect($response)
10+
->toBeInstanceOf(OutputMessageContentOutputTextAnnotationsFileCitation::class)
11+
->fileId->toBe('file-8aTRXYAhp5PbDF5R5P9Rky')
12+
->filename->toBe('document.pdf')
13+
->index->toBe(138)
14+
->type->toBe('file_citation');
15+
});
16+
17+
test('from with second file citation', function () {
18+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][4];
19+
$response = OutputMessageContentOutputTextAnnotationsFileCitation::from($annotation);
20+
21+
expect($response)
22+
->toBeInstanceOf(OutputMessageContentOutputTextAnnotationsFileCitation::class)
23+
->fileId->toBe('file-9cPRXMKyn1BmDT1K9J8Xxa')
24+
->filename->toBe('example-file.md')
25+
->index->toBe(294)
26+
->type->toBe('file_citation');
27+
});
28+
29+
test('as array accessible', function () {
30+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][3];
31+
$response = OutputMessageContentOutputTextAnnotationsFileCitation::from($annotation);
32+
33+
expect($response['file_id'])->toBe('file-8aTRXYAhp5PbDF5R5P9Rky')
34+
->and($response['filename'])->toBe('document.pdf')
35+
->and($response['index'])->toBe(138)
36+
->and($response['type'])->toBe('file_citation');
37+
});
38+
39+
test('to array', function () {
40+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][3];
41+
$response = OutputMessageContentOutputTextAnnotationsFileCitation::from($annotation);
42+
43+
expect($response->toArray())
44+
->toBeArray()
45+
->toBe($annotation);
46+
});

0 commit comments

Comments
 (0)