From 3f7127ba07ee8c2943be2da81ce614999fe3423b Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 10:17:05 +0200 Subject: [PATCH 1/8] fix(Gemini): implement 'extra_content' in tool response --- src/Responses/Chat/CreateResponseToolCall.php | 7 +++++-- src/Responses/Chat/CreateStreamedResponseToolCall.php | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index 17560b2ef..e1dc86f72 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -10,10 +10,11 @@ private function __construct( public readonly string $id, public readonly string $type, public readonly CreateResponseToolCallFunction $function, + public readonly array $extraContent, ) {} /** - * @param array{id: string, type?: string, function: array{name: string, arguments: string}} $attributes + * @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} $attributes */ public static function from(array $attributes): self { @@ -21,11 +22,12 @@ public static function from(array $attributes): self $attributes['id'], $attributes['type'] ?? 'function', CreateResponseToolCallFunction::from($attributes['function']), + $attributes['extra_content'] ?? [], ); } /** - * @return array{id: string, type: string, function: array{name: string, arguments: string}} + * @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} */ public function toArray(): array { @@ -33,6 +35,7 @@ public function toArray(): array 'id' => $this->id, 'type' => $this->type, 'function' => $this->function->toArray(), + 'extra_content' => $this->extraContent, ]; } } diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index 9173c653b..f805f3dbb 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -11,10 +11,11 @@ private function __construct( public readonly ?string $id, public readonly ?string $type, public readonly CreateStreamedResponseToolCallFunction $function, + public readonly ?array $extraContent, ) {} /** - * @param array{index?: int, id?: string, type?: string, function: array{name?: string, arguments: string}} $attributes + * @param array{index?: int, id?: string, type?: string, function: array{name?: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} $attributes */ public static function from(array $attributes): self { @@ -23,11 +24,12 @@ public static function from(array $attributes): self $attributes['id'] ?? null, $attributes['type'] ?? null, CreateStreamedResponseToolCallFunction::from($attributes['function']), + $attributes['extra_content'] ?? null, ); } /** - * @return array{index?: int, id?: string, type?: string, function?: array{name?: string, arguments: string}} + * @return array{index?: int, id?: string, type?: string, function?: array{name?: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} */ public function toArray(): array { @@ -36,6 +38,7 @@ public function toArray(): array 'id' => $this->id, 'type' => $this->type, 'function' => $this->function->toArray(), + 'extra_content' => $this->extraContent, ], fn (mixed $value): bool => ! is_null($value)); } } From f472242a3f7cf85e1db955afcb09edbf9139f7a7 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 10:21:56 +0200 Subject: [PATCH 2/8] fix(Gemini): fix typings --- src/Responses/Chat/CreateResponseToolCall.php | 4 ++-- src/Responses/Chat/CreateStreamedResponseToolCall.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index e1dc86f72..f141749d7 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -14,7 +14,7 @@ private function __construct( ) {} /** - * @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} $attributes + * @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content: array>|null} $attributes */ public static function from(array $attributes): self { @@ -27,7 +27,7 @@ public static function from(array $attributes): self } /** - * @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} + * @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content: array>|null} */ public function toArray(): array { diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index f805f3dbb..1dcee5a43 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -15,7 +15,7 @@ private function __construct( ) {} /** - * @param array{index?: int, id?: string, type?: string, function: array{name?: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} $attributes + * @param array{index?: int, id?: string, type?: string, function: array{name?: string, arguments: string}, extra_content: array>|null} $attributes */ public static function from(array $attributes): self { @@ -29,7 +29,7 @@ public static function from(array $attributes): self } /** - * @return array{index?: int, id?: string, type?: string, function?: array{name?: string, arguments: string}, extra_content: array{name: string, arguments: string}|null} + * @return array{index?: int, id?: string, type?: string, function?: array{name?: string, arguments: string}, extra_content: array>|null} */ public function toArray(): array { From 2d6f7cebc4496d3bac9e77b15860f0cfd9facd8a Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 11:01:55 +0200 Subject: [PATCH 3/8] fix(Gemini): do not include empty fields in response --- src/Responses/Chat/CreateResponseToolCall.php | 10 +++++----- src/Responses/Chat/CreateStreamedResponseToolCall.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index f141749d7..030f590f6 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -10,7 +10,7 @@ private function __construct( public readonly string $id, public readonly string $type, public readonly CreateResponseToolCallFunction $function, - public readonly array $extraContent, + public readonly ?array $extraContent, ) {} /** @@ -22,20 +22,20 @@ public static function from(array $attributes): self $attributes['id'], $attributes['type'] ?? 'function', CreateResponseToolCallFunction::from($attributes['function']), - $attributes['extra_content'] ?? [], + $attributes['extra_content'] ?? null, ); } /** - * @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content: array>|null} + * @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content?: array>} */ public function toArray(): array { - return [ + return array_filter([ 'id' => $this->id, 'type' => $this->type, 'function' => $this->function->toArray(), 'extra_content' => $this->extraContent, - ]; + ], fn (mixed $value): bool => ! is_null($value)); } } diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index 1dcee5a43..5c764a1c6 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -29,7 +29,7 @@ public static function from(array $attributes): self } /** - * @return array{index?: int, id?: string, type?: string, function?: array{name?: string, arguments: string}, extra_content: array>|null} + * @return array{index?: int, id?: string, type?: string, function?: array{name?: string, arguments: string}, extra_content?: array>} */ public function toArray(): array { From 8eb381f3cde61b12acf2df67ff7ab9adda26311a Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 14:06:06 +0200 Subject: [PATCH 4/8] fix(Gemini): improve typing --- src/Responses/Chat/CreateResponseToolCall.php | 10 ++++++++-- src/Responses/Chat/CreateStreamedResponseToolCall.php | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index 030f590f6..714342fa3 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -6,15 +6,21 @@ final class CreateResponseToolCall { + /** + * @param string $id + * @param string $type + * @param CreateResponseToolCallFunction $function + * @param array>|null $extraContent + */ private function __construct( public readonly string $id, public readonly string $type, public readonly CreateResponseToolCallFunction $function, - public readonly ?array $extraContent, + public readonly ?array $extraContent = null, ) {} /** - * @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content: array>|null} $attributes + * @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content?: array>|null} $attributes */ public static function from(array $attributes): self { diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index 5c764a1c6..35a77607b 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -6,6 +6,13 @@ final class CreateStreamedResponseToolCall { + /** + * @param int|null $index + * @param string|null $id + * @param string|null $type + * @param CreateStreamedResponseToolCallFunction $function + * @param array>|null $extraContent + */ private function __construct( public readonly ?int $index, public readonly ?string $id, From 98845554ed67beaa5c12d378c9dcf26d3ff2fd0a Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 14:24:43 +0200 Subject: [PATCH 5/8] fix(Gemini): update tests --- tests/Fixtures/Chat.php | 44 +++++++++++++++++++ .../Responses/Chat/CreateResponseMessage.php | 28 +++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/tests/Fixtures/Chat.php b/tests/Fixtures/Chat.php index f1cc56b9b..9ac6a8218 100644 --- a/tests/Fixtures/Chat.php +++ b/tests/Fixtures/Chat.php @@ -492,6 +492,50 @@ function chatCompletionWithToolCalls(): array ]; } +/** + * @return array + */ +function chatCompletionWithToolCallsAndExtraContent(): array +{ + return [ + 'id' => 'chatcmpl-123', + 'object' => 'chat.completion', + 'created' => 1699333252, + 'model' => 'gpt-3.5-turbo-0613', + 'choices' => [ + [ + 'index' => 0, + 'message' => [ + 'role' => 'assistant', + 'content' => null, + 'tool_calls' => [ + [ + 'id' => 'call_trlgKnhMpYSC7CFXKw3CceUZ', + 'type' => 'function', + 'function' => [ + 'name' => 'get_current_weather', + 'arguments' => "{\n \"location\": \"Boston, MA\"\n}", + ], + 'extra_content' => [ + 'google' => [ + 'thought_signature' => 'trlgKnhMpYSC7CFXKw3CceUZ' + ] + ], + ], + ], + ], + 'logprobs' => null, + 'finish_reason' => 'tool_calls', + ], + ], + 'usage' => [ + 'prompt_tokens' => 71, + 'completion_tokens' => 17, + 'total_tokens' => 88, + ], + ]; +} + /** * @return array */ diff --git a/tests/Responses/Chat/CreateResponseMessage.php b/tests/Responses/Chat/CreateResponseMessage.php index 39c480f74..ba61451ce 100644 --- a/tests/Responses/Chat/CreateResponseMessage.php +++ b/tests/Responses/Chat/CreateResponseMessage.php @@ -33,7 +33,26 @@ ->content->toBeNull() ->toolCalls->toBeArray() ->toolCalls->toHaveCount(1) - ->toolCalls->each->toBeInstanceOf(CreateResponseToolCall::class); + ->toolCalls->each->toBeInstanceOf(CreateResponseToolCall::class) + ->and($result->toolCalls[0]) + ->extraContent->toBeNull(); +}); + +test('from tool calls response with extra content', function () { + $result = CreateResponseMessage::from(chatCompletionWithToolCallsAndExtraContent()['choices'][0]['message']); + + expect($result) + ->role->toBe('assistant') + ->content->toBeNull() + ->toolCalls->toBeArray() + ->toolCalls->toHaveCount(1) + ->toolCalls->each->toBeInstanceOf(CreateResponseToolCall::class) + ->and($result->toolCalls[0]) + ->extraContent->toBeArray() + ->extraContent->toHaveCount(1) + ->extraContent->toHaveKey('google') + ->extraContent->google->toHaveKey('thought_signature') + ->extraContent->google->thought_signature->toBe('trlgKnhMpYSC7CFXKw3CceUZ'); }); test('from annotations response', function () { @@ -94,6 +113,13 @@ ->toBe(chatCompletionWithToolCalls()['choices'][0]['message']); }); +test('to array from tool calls response with extra content', function () { + $result = CreateResponseMessage::from(chatCompletionWithToolCallsAndExtraContent()['choices'][0]['message']); + + expect($result->toArray()) + ->toBe(chatCompletionWithToolCallsAndExtraContent()['choices'][0]['message']); +}); + test('to array from annotations response', function () { $result = CreateResponseMessage::from(chatCompletionWithAnnotations()['choices'][0]['message']); From 7f9ea56056d9b706d540c9f1bcebbe9aae79efdc Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 15:09:09 +0200 Subject: [PATCH 6/8] fix(Gemini): improving codestyle --- src/Responses/Chat/CreateResponseToolCall.php | 3 --- src/Responses/Chat/CreateStreamedResponseToolCall.php | 4 ---- tests/Fixtures/Chat.php | 2 +- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index 714342fa3..195fb69a2 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -7,9 +7,6 @@ final class CreateResponseToolCall { /** - * @param string $id - * @param string $type - * @param CreateResponseToolCallFunction $function * @param array>|null $extraContent */ private function __construct( diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index 35a77607b..241ff38c7 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -7,10 +7,6 @@ final class CreateStreamedResponseToolCall { /** - * @param int|null $index - * @param string|null $id - * @param string|null $type - * @param CreateStreamedResponseToolCallFunction $function * @param array>|null $extraContent */ private function __construct( diff --git a/tests/Fixtures/Chat.php b/tests/Fixtures/Chat.php index 9ac6a8218..9368fd3e3 100644 --- a/tests/Fixtures/Chat.php +++ b/tests/Fixtures/Chat.php @@ -518,7 +518,7 @@ function chatCompletionWithToolCallsAndExtraContent(): array ], 'extra_content' => [ 'google' => [ - 'thought_signature' => 'trlgKnhMpYSC7CFXKw3CceUZ' + 'thought_signature' => 'trlgKnhMpYSC7CFXKw3CceUZ', ] ], ], From 26b8f92b1849834bfd0c6669b2f357909d269548 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 15:51:23 +0200 Subject: [PATCH 7/8] fix(Gemini): improving codestyle --- src/Responses/Chat/CreateResponseToolCall.php | 2 +- src/Responses/Chat/CreateStreamedResponseToolCall.php | 2 +- tests/Fixtures/Chat.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Responses/Chat/CreateResponseToolCall.php b/src/Responses/Chat/CreateResponseToolCall.php index 195fb69a2..de61a4540 100644 --- a/src/Responses/Chat/CreateResponseToolCall.php +++ b/src/Responses/Chat/CreateResponseToolCall.php @@ -7,7 +7,7 @@ final class CreateResponseToolCall { /** - * @param array>|null $extraContent + * @param array>|null $extraContent */ private function __construct( public readonly string $id, diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index 241ff38c7..1dd6ee3e9 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -7,7 +7,7 @@ final class CreateStreamedResponseToolCall { /** - * @param array>|null $extraContent + * @param array>|null $extraContent */ private function __construct( public readonly ?int $index, diff --git a/tests/Fixtures/Chat.php b/tests/Fixtures/Chat.php index 9368fd3e3..85c9ddf38 100644 --- a/tests/Fixtures/Chat.php +++ b/tests/Fixtures/Chat.php @@ -519,7 +519,7 @@ function chatCompletionWithToolCallsAndExtraContent(): array 'extra_content' => [ 'google' => [ 'thought_signature' => 'trlgKnhMpYSC7CFXKw3CceUZ', - ] + ], ], ], ], From 00c0a18336f73fbc40ce8246e351aea23247cdc0 Mon Sep 17 00:00:00 2001 From: Leonard Fischer Date: Fri, 15 May 2026 16:08:09 +0200 Subject: [PATCH 8/8] fix(Gemini): improvie typing --- src/Responses/Chat/CreateStreamedResponseToolCall.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Responses/Chat/CreateStreamedResponseToolCall.php b/src/Responses/Chat/CreateStreamedResponseToolCall.php index 1dd6ee3e9..6cf6e4270 100644 --- a/src/Responses/Chat/CreateStreamedResponseToolCall.php +++ b/src/Responses/Chat/CreateStreamedResponseToolCall.php @@ -18,7 +18,7 @@ private function __construct( ) {} /** - * @param array{index?: int, id?: string, type?: string, function: array{name?: string, arguments: string}, extra_content: array>|null} $attributes + * @param array{index?: int, id?: string, type?: string, function: array{name?: string, arguments: string}, extra_content?: array>|null} $attributes */ public static function from(array $attributes): self {