|
5 | 5 | import com.sap.ai.sdk.app.services.SpringAiOpenAiService; |
6 | 6 | import com.sap.ai.sdk.foundationmodels.openai.OpenAiModel; |
7 | 7 | import org.junit.jupiter.api.Test; |
| 8 | +import org.springframework.ai.chat.messages.AssistantMessage; |
8 | 9 | import org.springframework.ai.chat.model.ChatResponse; |
9 | 10 |
|
| 11 | +import java.util.List; |
| 12 | + |
10 | 13 | class SpringAiOpenAiTest { |
11 | 14 |
|
12 | 15 | private final SpringAiOpenAiService service = new SpringAiOpenAiService(); |
@@ -47,6 +50,23 @@ void testToolCallingWithExecution() { |
47 | 50 | assertThat(response.getResult().getOutput().getText()).contains("Potsdam", "Toulouse", "°C"); |
48 | 51 | } |
49 | 52 |
|
| 53 | + @Test |
| 54 | + void testToolCallingWithoutExecution() { |
| 55 | + ChatResponse response = service.toolCalling(false); |
| 56 | + assertThat(response.getResult().getOutput().getText()).contains("Potsdam", "Toulouse", "°C"); |
| 57 | + List<AssistantMessage.ToolCall> toolCalls = response.getResult().getOutput().getToolCalls(); |
| 58 | + assertThat(toolCalls).hasSize(2); |
| 59 | + AssistantMessage.ToolCall toolCall1 = toolCalls.get(0); |
| 60 | + AssistantMessage.ToolCall toolCall2 = toolCalls.get(1); |
| 61 | + assertThat(toolCall1.type()).isEqualTo("function"); |
| 62 | + assertThat(toolCall2.type()).isEqualTo("function"); |
| 63 | + assertThat(toolCall1.name()).isEqualTo("getCurrentWeather"); |
| 64 | + assertThat(toolCall2.name()).isEqualTo("getCurrentWeather"); |
| 65 | + assertThat(toolCall1.arguments()) |
| 66 | + .isEqualTo("{\"arg0\": {\"location\": \"Potsdam\", \"unit\": \"C\"}}"); |
| 67 | + assertThat(toolCall2.arguments()) |
| 68 | + .isEqualTo("{\"arg0\": {\"location\": \"Toulouse\", \"unit\": \"C\"}}"); |
| 69 | + } |
50 | 70 | @Test |
51 | 71 | void testChatMemory() { |
52 | 72 | ChatResponse response = service.ChatMemory(); |
|
0 commit comments