File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ protected function mapAssistantMessage(AssistantMessage $message): void
9595 'type ' => 'function ' ,
9696 'function ' => [
9797 'name ' => $ toolCall ->name ,
98- 'arguments ' => json_encode ($ toolCall ->arguments ()),
98+ 'arguments ' => json_encode ($ toolCall ->arguments () ?: ( object ) [] ),
9999 ],
100100 ], $ message ->toolCalls );
101101
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ protected function mapAssistantMessage(AssistantMessage $message): void
9595 'type ' => 'function ' ,
9696 'function ' => [
9797 'name ' => $ toolCall ->name ,
98- 'arguments ' => json_encode ($ toolCall ->arguments ()),
98+ 'arguments ' => json_encode ($ toolCall ->arguments () ?: ( object ) [] ),
9999 ],
100100 ], $ message ->toolCalls );
101101
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ protected function mapAssistantMessage(AssistantMessage $message): void
9696 'type ' => 'function ' ,
9797 'function ' => [
9898 'name ' => $ toolCall ->name ,
99- 'arguments ' => json_encode ($ toolCall ->arguments ()),
99+ 'arguments ' => json_encode ($ toolCall ->arguments () ?: ( object ) [] ),
100100 ],
101101 ], $ message ->toolCalls );
102102
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ protected function mapAssistantMessage(AssistantMessage $message): void
155155 'call_id ' => $ toolCall ->resultId ,
156156 'type ' => 'function_call ' ,
157157 'name ' => $ toolCall ->name ,
158- 'arguments ' => json_encode ($ toolCall ->arguments ()),
158+ 'arguments ' => json_encode ($ toolCall ->arguments () ?: ( object ) [] ),
159159 ], $ message ->toolCalls )
160160 );
161161 }
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ protected function mapAssistantMessage(AssistantMessage $message): void
159159 'type ' => 'function ' ,
160160 'function ' => [
161161 'name ' => $ toolCall ->name ,
162- 'arguments ' => json_encode ($ toolCall ->arguments ()),
162+ 'arguments ' => json_encode ($ toolCall ->arguments () ?: ( object ) [] ),
163163 ],
164164 ], $ message ->toolCalls );
165165
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ protected function mapAssistantMessage(AssistantMessage $message): void
9595 'type ' => 'function ' ,
9696 'function ' => [
9797 'name ' => $ toolCall ->name ,
98- 'arguments ' => json_encode ($ toolCall ->arguments ()),
98+ 'arguments ' => json_encode ($ toolCall ->arguments () ?: ( object ) [] ),
9999 ],
100100 ], $ message ->toolCalls );
101101
Original file line number Diff line number Diff line change 137137 ]]);
138138});
139139
140+ it ('maps assistant message with tool calls with empty arguments as json object ' , function (): void {
141+ $ messageMap = new MessageMap (
142+ messages: [
143+ new AssistantMessage ('' , [
144+ new ToolCall (
145+ 'tool_1234 ' ,
146+ 'get_schema ' ,
147+ []
148+ ),
149+ ]),
150+ ],
151+ systemPrompts: []
152+ );
153+
154+ expect ($ messageMap ())->toBe ([[
155+ 'role ' => 'assistant ' ,
156+ 'tool_calls ' => [[
157+ 'id ' => 'tool_1234 ' ,
158+ 'type ' => 'function ' ,
159+ 'function ' => [
160+ 'name ' => 'get_schema ' ,
161+ 'arguments ' => '{} ' ,
162+ ],
163+ ]],
164+ ]]);
165+ });
166+
140167it ('maps tool result messages ' , function (): void {
141168 $ messageMap = new MessageMap (
142169 messages: [
Original file line number Diff line number Diff line change 139139 ]]);
140140});
141141
142+ it ('maps assistant message with tool calls with empty arguments as json object ' , function (): void {
143+ $ messageMap = new MessageMap (
144+ messages: [
145+ new AssistantMessage ('' , [
146+ new ToolCall (
147+ 'tool_1234 ' ,
148+ 'get_schema ' ,
149+ []
150+ ),
151+ ]),
152+ ],
153+ systemPrompts: []
154+ );
155+
156+ expect ($ messageMap ())->toBe ([[
157+ 'role ' => 'assistant ' ,
158+ 'tool_calls ' => [[
159+ 'id ' => 'tool_1234 ' ,
160+ 'type ' => 'function ' ,
161+ 'function ' => [
162+ 'name ' => 'get_schema ' ,
163+ 'arguments ' => '{} ' ,
164+ ],
165+ ]],
166+ ]]);
167+ });
168+
142169it ('maps tool result messages ' , function (): void {
143170 $ messageMap = new MessageMap (
144171 messages: [
Original file line number Diff line number Diff line change 9999 ]]);
100100});
101101
102+ it ('maps assistant message with tool calls with empty arguments as json object ' , function (): void {
103+ $ messageMap = new MessageMap (
104+ messages: [
105+ new AssistantMessage ('' , [
106+ new ToolCall (
107+ 'tool_1234 ' ,
108+ 'get_schema ' ,
109+ []
110+ ),
111+ ]),
112+ ],
113+ systemPrompts: []
114+ );
115+
116+ expect ($ messageMap ())->toBe ([[
117+ 'role ' => 'assistant ' ,
118+ 'tool_calls ' => [[
119+ 'id ' => 'tool_1234 ' ,
120+ 'type ' => 'function ' ,
121+ 'function ' => [
122+ 'name ' => 'get_schema ' ,
123+ 'arguments ' => '{} ' ,
124+ ],
125+ ]],
126+ ]]);
127+ });
128+
102129it ('maps tool result messages ' , function (): void {
103130 $ messageMap = new MessageMap (
104131 messages: [
Original file line number Diff line number Diff line change 189189 ]);
190190});
191191
192+ it ('maps assistant message with tool calls with empty arguments as json object ' , function (): void {
193+ $ messageMap = new MessageMap (
194+ messages: [
195+ new AssistantMessage ('' , [
196+ new ToolCall (
197+ 'tool_1234 ' ,
198+ 'get_schema ' ,
199+ [],
200+ 'call_1234 '
201+ ),
202+ ]),
203+ ],
204+ systemPrompts: []
205+ );
206+
207+ expect ($ messageMap ())->toBe ([
208+ [
209+ 'id ' => 'tool_1234 ' ,
210+ 'call_id ' => 'call_1234 ' ,
211+ 'type ' => 'function_call ' ,
212+ 'name ' => 'get_schema ' ,
213+ 'arguments ' => '{} ' ,
214+ ],
215+ ]);
216+ });
217+
192218it ('maps tool result messages ' , function (): void {
193219 $ messageMap = new MessageMap (
194220 messages: [
You can’t perform that action at this time.
0 commit comments