Skip to content

Commit 88be4b3

Browse files
valtzuchr-hertel
authored andcommitted
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 7a0fb4f commit 88be4b3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected function supportsModel(Model $model): bool
4444
* role: 'model'|'user',
4545
* parts: array<int, mixed>
4646
* }>,
47-
* system_instruction?: array{parts: array{text: string}}
47+
* system_instruction?: array{parts: array{text: string}[]}
4848
* }
4949
*/
5050
public function normalize(mixed $data, ?string $format = null, array $context = []): array
@@ -53,7 +53,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
5353

5454
if (null !== $systemMessage = $data->getSystemMessage()) {
5555
$array['system_instruction'] = [
56-
'parts' => ['text' => $systemMessage->content],
56+
'parts' => [['text' => $systemMessage->content]],
5757
];
5858
}
5959

src/platform/tests/Bridge/Google/Contract/MessageBagNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static function provideMessageBagData(): iterable
149149
['role' => 'user', 'parts' => [['text' => 'Hello there']]],
150150
],
151151
'system_instruction' => [
152-
'parts' => ['text' => 'You are a cat. Your name is Neko.'],
152+
'parts' => [['text' => 'You are a cat. Your name is Neko.']],
153153
],
154154
],
155155
];

0 commit comments

Comments
 (0)