Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 71714f5

Browse files
authored
fix: Gemini system prompt (#381)
I started to get 400 Bad Request from Gemini API, not sure if it was due to changing a model or what. Changing `system_instruction.parts` into a list like in the [docs](https://ai.google.dev/gemini-api/docs/text-generation#system-instructions) fixed it. Tested at least with `gemini-1.5-pro` and `gemini-2.5-pro` and `gemini-2.0-flash`, works fine.
1 parent cb6fc83 commit 71714f5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Platform/Bridge/Google/Contract/MessageBagNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function supportsModel(Model $model): bool
3737
* role: 'model'|'user',
3838
* parts: array<int, mixed>
3939
* }>,
40-
* system_instruction?: array{parts: array{text: string}}
40+
* system_instruction?: array{parts: array{text: string}[]}
4141
* }
4242
*/
4343
public function normalize(mixed $data, ?string $format = null, array $context = []): array
@@ -46,7 +46,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4646

4747
if (null !== $systemMessage = $data->getSystemMessage()) {
4848
$array['system_instruction'] = [
49-
'parts' => ['text' => $systemMessage->content],
49+
'parts' => [['text' => $systemMessage->content]],
5050
];
5151
}
5252

tests/Platform/Bridge/Google/Contract/MessageBagNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static function provideMessageBagData(): iterable
142142
['role' => 'user', 'parts' => [['text' => 'Hello there']]],
143143
],
144144
'system_instruction' => [
145-
'parts' => ['text' => 'You are a cat. Your name is Neko.'],
145+
'parts' => [['text' => 'You are a cat. Your name is Neko.']],
146146
],
147147
],
148148
];

0 commit comments

Comments
 (0)