|
32 | 32 | import org.springframework.ai.chat.model.ChatResponse; |
33 | 33 | import org.springframework.ai.chat.model.Generation; |
34 | 34 | import org.springframework.ai.chat.prompt.Prompt; |
| 35 | +import org.springframework.ai.model.function.FunctionCallingOptions; |
| 36 | +import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions; |
35 | 37 | import org.springframework.ai.openai.OpenAiChatModel; |
36 | 38 | import org.springframework.ai.openai.OpenAiChatOptions; |
37 | 39 | import org.springframework.ai.openai.api.OpenAiApi.ChatModel; |
@@ -103,6 +105,31 @@ void functionCallWithPortableFunctionCallingOptions() { |
103 | 105 | }); |
104 | 106 | } |
105 | 107 |
|
| 108 | + @Test |
| 109 | + void functionCallWithPortableFunctionCallingOptions2() { |
| 110 | + contextRunner |
| 111 | + .withPropertyValues("spring.ai.openai.chat.options.model=" + ChatModel.GPT_4_O_MINI.getName(), |
| 112 | + "spring.ai.openai.chat.options.temperature=0.1") |
| 113 | + .run(context -> { |
| 114 | + |
| 115 | + OpenAiChatModel chatModel = context.getBean(OpenAiChatModel.class); |
| 116 | + |
| 117 | + // Test weatherFunction |
| 118 | + UserMessage userMessage = new UserMessage( |
| 119 | + "What's the weather like in San Francisco, Tokyo, and Paris?"); |
| 120 | + |
| 121 | + PortableFunctionCallingOptions functionOptions = FunctionCallingOptions.builder() |
| 122 | + .withFunction("weatherFunction") |
| 123 | + .build(); |
| 124 | + |
| 125 | + ChatResponse response = chatModel.call(new Prompt(List.of(userMessage), functionOptions)); |
| 126 | + |
| 127 | + logger.info("Response: {}", response.getResult().getOutput().getContent()); |
| 128 | + |
| 129 | + assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15"); |
| 130 | + }); |
| 131 | + } |
| 132 | + |
106 | 133 | @Test |
107 | 134 | void streamFunctionCallTest() { |
108 | 135 | contextRunner |
|
0 commit comments