Skip to content

Commit 394c277

Browse files
committed
bug #266 [Platform] Add content when normalizing ollama assistant messages (Rado)
This PR was squashed before being merged into the main branch. Discussion ---------- [Platform] Add content when normalizing ollama assistant messages | Q | A | ------------- | --- | Bug fix? | yes | New feature? |no | Docs? | no | Issues | None | License | MIT The assistant message for ollama chats supports `content` as well as `tool_calls`. Not providing content to assistant messages leads to loss of context especially in cases where no tools have been used. Commits ------- b1a3dcd [Platform] Add content when normalizing ollama assistant messages
2 parents e4ef474 + b1a3dcd commit 394c277

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/platform/src/Bridge/Ollama/Contract/AssistantMessageNormalizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ protected function supportsModel(Model $model): bool
4242
*
4343
* @return array{
4444
* role: Role::Assistant,
45+
* content: string,
4546
* tool_calls: list<array{
4647
* type: 'function',
4748
* function: array{
@@ -55,6 +56,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
5556
{
5657
return [
5758
'role' => Role::Assistant,
59+
'content' => $data->content ?? '',
5860
'tool_calls' => array_values(array_map(function (ToolCall $message): array {
5961
return [
6062
'type' => 'function',

src/platform/tests/Bridge/Ollama/Contract/AssistantMessageNormalizerTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static function normalizeDataProvider(): iterable
7272
new AssistantMessage('Hello'),
7373
[
7474
'role' => Role::Assistant,
75+
'content' => 'Hello',
7576
'tool_calls' => [],
7677
],
7778
];
@@ -80,6 +81,7 @@ public static function normalizeDataProvider(): iterable
8081
new AssistantMessage(toolCalls: [new ToolCall('id1', 'function1', ['param' => 'value'])]),
8182
[
8283
'role' => Role::Assistant,
84+
'content' => '',
8385
'tool_calls' => [
8486
[
8587
'type' => 'function',
@@ -96,6 +98,7 @@ public static function normalizeDataProvider(): iterable
9698
new AssistantMessage(toolCalls: [new ToolCall('id1', 'function1', [])]),
9799
[
98100
'role' => Role::Assistant,
101+
'content' => '',
99102
'tool_calls' => [
100103
[
101104
'type' => 'function',
@@ -115,6 +118,37 @@ public static function normalizeDataProvider(): iterable
115118
]),
116119
[
117120
'role' => Role::Assistant,
121+
'content' => '',
122+
'tool_calls' => [
123+
[
124+
'type' => 'function',
125+
'function' => [
126+
'name' => 'function1',
127+
'arguments' => ['param1' => 'value1'],
128+
],
129+
],
130+
[
131+
'type' => 'function',
132+
'function' => [
133+
'name' => 'function2',
134+
'arguments' => ['param2' => 'value2'],
135+
],
136+
],
137+
],
138+
],
139+
];
140+
141+
yield 'assistant message with tool calls and content' => [
142+
new AssistantMessage(
143+
content: 'Hello',
144+
toolCalls: [
145+
new ToolCall('id1', 'function1', ['param1' => 'value1']),
146+
new ToolCall('id2', 'function2', ['param2' => 'value2']),
147+
]
148+
),
149+
[
150+
'role' => Role::Assistant,
151+
'content' => 'Hello',
118152
'tool_calls' => [
119153
[
120154
'type' => 'function',

0 commit comments

Comments
 (0)