@@ -48,7 +48,7 @@ public function testConvertTextResult()
4848 $ this ->assertSame ('Hello world ' , $ result ->getContent ());
4949 }
5050
51- public function testConvertToolCallResult ()
51+ public function testConvertToolWithArgsCallResult ()
5252 {
5353 $ converter = new ResultConverter ();
5454 $ httpResponse = self ::createMock (ResponseInterface::class);
@@ -84,6 +84,77 @@ public function testConvertToolCallResult()
8484 $ this ->assertSame (['arg1 ' => 'value1 ' ], $ toolCalls [0 ]->getArguments ());
8585 }
8686
87+ public function testConvertToolWithEmptyArgsCallResult ()
88+ {
89+ $ converter = new ResultConverter ();
90+ $ httpResponse = self ::createMock (ResponseInterface::class);
91+ $ httpResponse ->method ('toArray ' )->willReturn ([
92+ 'choices ' => [
93+ [
94+ 'message ' => [
95+ 'role ' => 'assistant ' ,
96+ 'content ' => null ,
97+ 'tool_calls ' => [
98+ [
99+ 'id ' => 'call_123 ' ,
100+ 'type ' => 'function ' ,
101+ 'function ' => [
102+ 'name ' => 'test_function ' ,
103+ 'arguments ' => '' ,
104+ ],
105+ ],
106+ ],
107+ ],
108+ 'finish_reason ' => 'tool_calls ' ,
109+ ],
110+ ],
111+ ]);
112+
113+ $ result = $ converter ->convert (new RawHttpResult ($ httpResponse ));
114+
115+ $ this ->assertInstanceOf (ToolCallResult::class, $ result );
116+ $ toolCalls = $ result ->getContent ();
117+ $ this ->assertCount (1 , $ toolCalls );
118+ $ this ->assertSame ('call_123 ' , $ toolCalls [0 ]->getId ());
119+ $ this ->assertSame ('test_function ' , $ toolCalls [0 ]->getName ());
120+ $ this ->assertSame ([], $ toolCalls [0 ]->getArguments ());
121+ }
122+
123+ public function testConvertToolWithoutArgsCallResult ()
124+ {
125+ $ converter = new ResultConverter ();
126+ $ httpResponse = self ::createMock (ResponseInterface::class);
127+ $ httpResponse ->method ('toArray ' )->willReturn ([
128+ 'choices ' => [
129+ [
130+ 'message ' => [
131+ 'role ' => 'assistant ' ,
132+ 'content ' => null ,
133+ 'tool_calls ' => [
134+ [
135+ 'id ' => 'call_123 ' ,
136+ 'type ' => 'function ' ,
137+ 'function ' => [
138+ 'name ' => 'test_function ' ,
139+ ],
140+ ],
141+ ],
142+ ],
143+ 'finish_reason ' => 'tool_calls ' ,
144+ ],
145+ ],
146+ ]);
147+
148+ $ result = $ converter ->convert (new RawHttpResult ($ httpResponse ));
149+
150+ $ this ->assertInstanceOf (ToolCallResult::class, $ result );
151+ $ toolCalls = $ result ->getContent ();
152+ $ this ->assertCount (1 , $ toolCalls );
153+ $ this ->assertSame ('call_123 ' , $ toolCalls [0 ]->getId ());
154+ $ this ->assertSame ('test_function ' , $ toolCalls [0 ]->getName ());
155+ $ this ->assertSame ([], $ toolCalls [0 ]->getArguments ());
156+ }
157+
87158 public function testConvertMultipleChoices ()
88159 {
89160 $ converter = new ResultConverter ();
0 commit comments