Skip to content

Commit 6a7c4bc

Browse files
authored
fix(OpenAI): Missing properties on container file annotation (#703)
* Add missing filename property to OutputMessageContentOutputTextAnnotationsContainerFile * Add container id to OutputMessageContentOutputTextAnnotationsContainerFile and add test coverage
1 parent 6404b5f commit 6a7c4bc

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use OpenAI\Testing\Responses\Concerns\Fakeable;
1010

1111
/**
12-
* @phpstan-type ContainerFileType array{file_id: string, type: 'container_file_citation', text?: string, start_index?: int, end_index?: int}
12+
* @phpstan-type ContainerFileType array{file_id: string, filename: string, type: 'container_file_citation', container_id: string, text?: string, start_index?: int, end_index?: int}
1313
*
1414
* @implements ResponseContract<ContainerFileType>
1515
*/
@@ -27,7 +27,9 @@ final class OutputMessageContentOutputTextAnnotationsContainerFile implements Re
2727
*/
2828
private function __construct(
2929
public readonly string $fileId,
30+
public readonly string $filename,
3031
public readonly string $type,
32+
public readonly string $containerId,
3133
public readonly ?string $text,
3234
public readonly ?int $startIndex,
3335
public readonly ?int $endIndex,
@@ -40,7 +42,9 @@ public static function from(array $attributes): self
4042
{
4143
return new self(
4244
fileId: $attributes['file_id'],
45+
filename: $attributes['filename'],
4346
type: $attributes['type'],
47+
containerId: $attributes['container_id'],
4448
text: $attributes['text'] ?? null,
4549
startIndex: $attributes['start_index'] ?? null,
4650
endIndex: $attributes['end_index'] ?? null,
@@ -54,7 +58,9 @@ public function toArray(): array
5458
{
5559
$result = [
5660
'file_id' => $this->fileId,
61+
'filename' => $this->filename,
5762
'type' => $this->type,
63+
'container_id' => $this->containerId,
5864
];
5965

6066
if ($this->text !== null) {

tests/Fixtures/Responses.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,14 @@ function outputAnnotationMessage(): array
591591
'index' => 294,
592592
'type' => 'file_citation',
593593
],
594+
[
595+
'file_id' => 'cfile_15vdn2c43dec8191afde1f1fc40avec6',
596+
'filename' => 'image.png',
597+
'type' => 'container_file_citation',
598+
'container_id' => 'cntr_61vcf2b258d88128b3fc109db6fv61e406ebfd5bc0cbcbce',
599+
'start_index' => 133,
600+
'end_index' => 166,
601+
],
594602
],
595603
'text' => 'As of today, March 9, 2025, one notable positive news story...',
596604
'type' => 'output_text',
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
use OpenAI\Responses\Responses\Output\OutputMessageContentOutputTextAnnotationsContainerFile;
4+
5+
test('from', function () {
6+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][5];
7+
$response = OutputMessageContentOutputTextAnnotationsContainerFile::from($annotation);
8+
9+
expect($response)
10+
->toBeInstanceOf(OutputMessageContentOutputTextAnnotationsContainerFile::class)
11+
->fileId->toBe('cfile_15vdn2c43dec8191afde1f1fc40avec6')
12+
->filename->toBe('image.png')
13+
->startIndex->toBe(133)
14+
->endIndex->toBe(166)
15+
->type->toBe('container_file_citation')
16+
->containerId->toBe('cntr_61vcf2b258d88128b3fc109db6fv61e406ebfd5bc0cbcbce');
17+
});
18+
19+
test('as array accessible', function () {
20+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][5];
21+
$response = OutputMessageContentOutputTextAnnotationsContainerFile::from($annotation);
22+
23+
expect($response['file_id'])->toBe('cfile_15vdn2c43dec8191afde1f1fc40avec6')
24+
->and($response['filename'])->toBe('image.png')
25+
->and($response['start_index'])->toBe(133)
26+
->and($response['end_index'])->toBe(166)
27+
->and($response['type'])->toBe('container_file_citation')
28+
->and($response['container_id'])->toBe('cntr_61vcf2b258d88128b3fc109db6fv61e406ebfd5bc0cbcbce');
29+
});
30+
31+
test('to array', function () {
32+
$annotation = outputAnnotationMessage()['content'][0]['annotations'][5];
33+
$response = OutputMessageContentOutputTextAnnotationsContainerFile::from($annotation);
34+
35+
expect($response->toArray())
36+
->toBeArray()
37+
->toBe($annotation);
38+
});

0 commit comments

Comments
 (0)