Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContainerFileType>
*/
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/Responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use OpenAI\Responses\Responses\Output\OutputMessageContentOutputTextAnnotationsContainerFile;

test('from', function () {
$annotation = outputAnnotationMessage()['content'][0]['annotations'][5];
$response = OutputMessageContentOutputTextAnnotationsContainerFile::from($annotation);

expect($response)
->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);
});