37
37
import org .springframework .util .ReflectionUtils ;
38
38
39
39
import static org .assertj .core .api .Assertions .assertThat ;
40
- import static org .assertj .core .api .Assertions .assertThatCode ;
41
40
import static org .assertj .core .api .AssertionsForClassTypes .assertThatThrownBy ;
42
41
43
42
@ SpringBootTest (classes = OpenAiTestConfiguration .class )
@@ -166,12 +165,12 @@ void methodGetWeatherToolContext() {
166
165
}
167
166
168
167
@ Test
169
- void methodGetWeatherNonStaticButWithToolContext () {
168
+ void methodGetWeatherToolContextButMissingContextArgument () {
170
169
171
170
TestFunctionClass targetObject = new TestFunctionClass ();
172
171
173
- var toolMethod = ReflectionUtils .findMethod (TestFunctionClass .class , "getWeatherNonStatic " , String .class ,
174
- Unit .class );
172
+ var toolMethod = ReflectionUtils .findMethod (TestFunctionClass .class , "getWeatherWithContext " , String .class ,
173
+ Unit .class , ToolContext . class );
175
174
176
175
// @formatter:off
177
176
assertThatThrownBy (() -> ChatClient .create (this .chatModel ).prompt ()
@@ -183,37 +182,13 @@ void methodGetWeatherNonStaticButWithToolContext() {
183
182
.toolMethod (toolMethod )
184
183
.toolObject (targetObject )
185
184
.build ())
186
- .toolContext (Map .of ("tool-context" , "value" ))
187
185
.call ()
188
186
.content ())
189
187
.isInstanceOf (IllegalArgumentException .class )
190
188
.hasMessage ("ToolContext is required by the method as an argument" );
191
189
// @formatter:on
192
190
}
193
191
194
- @ Test
195
- void methodGetWeatherToolContextButWithoutToolContext () {
196
-
197
- TestFunctionClass targetObject = new TestFunctionClass ();
198
-
199
- var toolMethod = ReflectionUtils .findMethod (TestFunctionClass .class , "getWeatherWithContext" , String .class ,
200
- Unit .class , ToolContext .class );
201
-
202
- // @formatter:off
203
- assertThatCode (() ->ChatClient .create (this .chatModel ).prompt ()
204
- .user ("What's the weather like in San Francisco, Tokyo, and Paris? Use Celsius." )
205
- .toolCallbacks (MethodToolCallback .builder ()
206
- .toolDefinition (ToolDefinitions .builder (toolMethod )
207
- .description ("Get the weather in location" )
208
- .build ())
209
- .toolMethod (toolMethod )
210
- .toolObject (targetObject )
211
- .build ())
212
- .call ()
213
- .content ()).doesNotThrowAnyException ();
214
- // @formatter:on
215
- }
216
-
217
192
@ Test
218
193
void methodNoParameters () {
219
194
0 commit comments