diff --git a/src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php b/src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php index 9fe6c50c..1a84964d 100644 --- a/src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php +++ b/src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php @@ -9,7 +9,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @phpstan-type ContainerFileType array{file_id: string, type: 'container_file_citation', text?: string, start_index?: int, end_index?: int} + * @phpstan-type ContainerFileType array{file_id: string, filename: string, type: 'container_file_citation', container_id: string, text?: string, start_index?: int, end_index?: int} * * @implements ResponseContract */ @@ -27,7 +27,9 @@ final class OutputMessageContentOutputTextAnnotationsContainerFile implements Re */ private function __construct( public readonly string $fileId, + public readonly string $filename, public readonly string $type, + public readonly string $containerId, public readonly ?string $text, public readonly ?int $startIndex, public readonly ?int $endIndex, @@ -40,7 +42,9 @@ public static function from(array $attributes): self { return new self( fileId: $attributes['file_id'], + filename: $attributes['filename'], type: $attributes['type'], + containerId: $attributes['container_id'], text: $attributes['text'] ?? null, startIndex: $attributes['start_index'] ?? null, endIndex: $attributes['end_index'] ?? null, @@ -54,7 +58,9 @@ public function toArray(): array { $result = [ 'file_id' => $this->fileId, + 'filename' => $this->filename, 'type' => $this->type, + 'container_id' => $this->containerId, ]; if ($this->text !== null) { diff --git a/tests/Fixtures/Responses.php b/tests/Fixtures/Responses.php index ec2b0aae..39cc0ef9 100644 --- a/tests/Fixtures/Responses.php +++ b/tests/Fixtures/Responses.php @@ -591,6 +591,14 @@ function outputAnnotationMessage(): array 'index' => 294, 'type' => 'file_citation', ], + [ + 'file_id' => 'cfile_15vdn2c43dec8191afde1f1fc40avec6', + 'filename' => 'image.png', + 'type' => 'container_file_citation', + 'container_id' => 'cntr_61vcf2b258d88128b3fc109db6fv61e406ebfd5bc0cbcbce', + 'start_index' => 133, + 'end_index' => 166, + ], ], 'text' => 'As of today, March 9, 2025, one notable positive news story...', 'type' => 'output_text', diff --git a/tests/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php b/tests/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php new file mode 100644 index 00000000..1a78bfac --- /dev/null +++ b/tests/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsContainerFile.php @@ -0,0 +1,38 @@ +toBeInstanceOf(OutputMessageContentOutputTextAnnotationsContainerFile::class) + ->fileId->toBe('cfile_15vdn2c43dec8191afde1f1fc40avec6') + ->filename->toBe('image.png') + ->startIndex->toBe(133) + ->endIndex->toBe(166) + ->type->toBe('container_file_citation') + ->containerId->toBe('cntr_61vcf2b258d88128b3fc109db6fv61e406ebfd5bc0cbcbce'); +}); + +test('as array accessible', function () { + $annotation = outputAnnotationMessage()['content'][0]['annotations'][5]; + $response = OutputMessageContentOutputTextAnnotationsContainerFile::from($annotation); + + expect($response['file_id'])->toBe('cfile_15vdn2c43dec8191afde1f1fc40avec6') + ->and($response['filename'])->toBe('image.png') + ->and($response['start_index'])->toBe(133) + ->and($response['end_index'])->toBe(166) + ->and($response['type'])->toBe('container_file_citation') + ->and($response['container_id'])->toBe('cntr_61vcf2b258d88128b3fc109db6fv61e406ebfd5bc0cbcbce'); +}); + +test('to array', function () { + $annotation = outputAnnotationMessage()['content'][0]['annotations'][5]; + $response = OutputMessageContentOutputTextAnnotationsContainerFile::from($annotation); + + expect($response->toArray()) + ->toBeArray() + ->toBe($annotation); +});