From 62a09ae36a19a42f2592ad38cd0e3d6add05a84d Mon Sep 17 00:00:00 2001 From: Kyle Nash Date: Fri, 7 Jun 2024 15:01:54 +0100 Subject: [PATCH] fix: Update image url content type to use url instead of file id --- src/Resources/ThreadsMessages.php | 8 ++++---- .../Threads/Messages/ThreadMessageListResponse.php | 6 +++--- .../Threads/Messages/ThreadMessageResponse.php | 6 +++--- .../Messages/ThreadMessageResponseContentImageUrl.php | 10 +++++----- .../ThreadMessageResponseContentImageUrlObject.php | 6 +++--- tests/Fixtures/ThreadMessage.php | 2 +- .../Messages/ThreadMessageResponseContentImageUrl.php | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Resources/ThreadsMessages.php b/src/Resources/ThreadsMessages.php index da1b1adb..44142433 100644 --- a/src/Resources/ThreadsMessages.php +++ b/src/Resources/ThreadsMessages.php @@ -26,7 +26,7 @@ public function create(string $threadId, array $parameters): ThreadMessageRespon { $payload = Payload::create("threads/$threadId/messages", $parameters); - /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> $response */ + /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> $response */ $response = $this->transporter->requestObject($payload); return ThreadMessageResponse::from($response->data(), $response->meta()); @@ -41,7 +41,7 @@ public function retrieve(string $threadId, string $messageId): ThreadMessageResp { $payload = Payload::retrieve("threads/$threadId/messages", $messageId); - /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> $response */ + /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> $response */ $response = $this->transporter->requestObject($payload); return ThreadMessageResponse::from($response->data(), $response->meta()); @@ -58,7 +58,7 @@ public function modify(string $threadId, string $messageId, array $parameters): { $payload = Payload::modify("threads/$threadId/messages", $messageId, $parameters); - /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> $response */ + /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> $response */ $response = $this->transporter->requestObject($payload); return ThreadMessageResponse::from($response->data(), $response->meta()); @@ -90,7 +90,7 @@ public function list(string $threadId, array $parameters = []): ThreadMessageLis { $payload = Payload::list("threads/$threadId/messages", $parameters); - /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */ + /** @var Response}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */ $response = $this->transporter->requestObject($payload); return ThreadMessageListResponse::from($response->data(), $response->meta()); diff --git a/src/Responses/Threads/Messages/ThreadMessageListResponse.php b/src/Responses/Threads/Messages/ThreadMessageListResponse.php index 5cb3fe55..4e2f0bd6 100644 --- a/src/Responses/Threads/Messages/ThreadMessageListResponse.php +++ b/src/Responses/Threads/Messages/ThreadMessageListResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract}}|array{type: string, image_file: array{file_id: string}}|array{type: 'image_url', image_url: array{file_id: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool}> + * @implements ResponseContract}}|array{type: string, image_file: array{file_id: string}}|array{type: 'image_url', image_url: array{url: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool}> */ final class ThreadMessageListResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible}}|array{type: string, image_file: array{file_id: string}}|array{type: 'image_url', image_url: array{file_id: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool}> + * @use ArrayAccessible}}|array{type: string, image_file: array{file_id: string}}|array{type: 'image_url', image_url: array{url: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool}> */ use ArrayAccessible; @@ -40,7 +40,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{object: string, data: array}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes + * @param array{object: string, data: array}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/src/Responses/Threads/Messages/ThreadMessageResponse.php b/src/Responses/Threads/Messages/ThreadMessageResponse.php index a828adaa..d7186a61 100644 --- a/src/Responses/Threads/Messages/ThreadMessageResponse.php +++ b/src/Responses/Threads/Messages/ThreadMessageResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract}}|array{type: string, image_file: array{file_id: string, detail?: string}}|array{type: 'image_url', image_url: array{file_id: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> + * @implements ResponseContract}}|array{type: string, image_file: array{file_id: string, detail?: string}}|array{type: 'image_url', image_url: array{url: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> */ final class ThreadMessageResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible}}|array{type: string, image_file: array{file_id: string, detail?: string}}|array{type: 'image_url', image_url: array{file_id: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> + * @use ArrayAccessible}}|array{type: string, image_file: array{file_id: string, detail?: string}}|array{type: 'image_url', image_url: array{url: string, detail?: string}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array}> */ use ArrayAccessible; @@ -47,7 +47,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{id: string, object: string, created_at: int, thread_id: string, role: string, content: array}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array} $attributes + * @param array{id: string, object: string, created_at: int, thread_id: string, role: string, content: array}}>, assistant_id: ?string, run_id: ?string, attachments: array}>, metadata: array} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php b/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php index 5eca0dde..a4fc624d 100644 --- a/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php +++ b/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php @@ -9,7 +9,7 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract + * @implements ResponseContract */ final class ThreadMessageResponseContentImageUrl implements ResponseContract { @@ -21,7 +21,7 @@ final class ThreadMessageResponseContentImageUrl implements ResponseContract use Fakeable; private function __construct( - public string $fileId, + public string $url, public ?string $detail, ) { } @@ -29,12 +29,12 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{file_id: string, detail?: string} $attributes + * @param array{url: string, detail?: string} $attributes */ public static function from(array $attributes): self { return new self( - $attributes['file_id'], + $attributes['url'], $attributes['detail'] ?? null, ); } @@ -45,7 +45,7 @@ public static function from(array $attributes): self public function toArray(): array { return array_filter([ - 'file_id' => $this->fileId, + 'url' => $this->url, 'detail' => $this->detail, ], fn (?string $value): bool => $value !== null); } diff --git a/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrlObject.php b/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrlObject.php index acb58b86..ac65eb54 100644 --- a/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrlObject.php +++ b/src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrlObject.php @@ -9,12 +9,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract + * @implements ResponseContract */ final class ThreadMessageResponseContentImageUrlObject implements ResponseContract { /** - * @use ArrayAccessible + * @use ArrayAccessible */ use ArrayAccessible; @@ -32,7 +32,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{type: 'image_url', image_url: array{file_id: string, detail?: string}} $attributes + * @param array{type: 'image_url', image_url: array{url: string, detail?: string}} $attributes */ public static function from(array $attributes): self { diff --git a/tests/Fixtures/ThreadMessage.php b/tests/Fixtures/ThreadMessage.php index d0f47567..2f11609b 100644 --- a/tests/Fixtures/ThreadMessage.php +++ b/tests/Fixtures/ThreadMessage.php @@ -48,7 +48,7 @@ function threadMessageResource(): array [ 'type' => 'image_url', 'image_url' => [ - 'file_id' => 'file-VKxjnFCaSHc4ZELRGKwTMFtI', + 'url' => 'https://example.com/image.png', 'detail' => 'high', ], ], diff --git a/tests/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php b/tests/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php index 87beb9d2..3c997b36 100644 --- a/tests/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php +++ b/tests/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php @@ -6,15 +6,15 @@ $result = ThreadMessageResponseContentImageUrl::from(threadMessageResource()['content'][2]['image_url']); expect($result) - ->fileId->toBe('file-VKxjnFCaSHc4ZELRGKwTMFtI') + ->url->toBe('https://example.com/image.png') ->detail->toBe('high'); }); test('as array accessible', function () { $result = ThreadMessageResponseContentImageUrl::from(threadMessageResource()['content'][2]['image_url']); - expect($result['file_id']) - ->toBe('file-VKxjnFCaSHc4ZELRGKwTMFtI') + expect($result['url']) + ->toBe('https://example.com/image.png') ->and($result['detail']) ->toBe('high'); });