@@ -20,19 +20,18 @@ import org.assertj.core.api.Assertions.assertThat
20
20
import org.junit.jupiter.api.BeforeAll
21
21
import org.junit.jupiter.api.Test
22
22
import org.slf4j.LoggerFactory
23
-
24
23
import org.springframework.ai.autoconfigure.ollama.BaseOllamaIT
25
24
import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration
26
25
import org.springframework.ai.chat.messages.UserMessage
27
26
import org.springframework.ai.chat.prompt.Prompt
28
- import org.springframework.ai.model.function.FunctionCallback
29
- import org.springframework.ai.model.function.FunctionCallingOptions
27
+ import org.springframework.ai.model.tool.ToolCallingChatOptions
30
28
import org.springframework.ai.ollama.OllamaChatModel
31
- import org.springframework.ai.ollama.api.OllamaOptions
32
29
import org.springframework.boot.autoconfigure.AutoConfigurations
33
30
import org.springframework.boot.test.context.runner.ApplicationContextRunner
34
31
import org.springframework.context.annotation.Bean
35
32
import org.springframework.context.annotation.Configuration
33
+ import org.springframework.context.annotation.Description
34
+
36
35
37
36
class FunctionCallbackKotlinIT : BaseOllamaIT () {
38
37
@@ -68,8 +67,10 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
68
67
val userMessage = UserMessage (
69
68
" What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations." )
70
69
70
+ val functionOptions = ToolCallingChatOptions .builder().toolNames(" weatherInfo" ).build()
71
+
71
72
val response = chatModel
72
- .call(Prompt (listOf (userMessage), OllamaOptions .builder().function( " WeatherInfo " ).build() ))
73
+ .call(Prompt (listOf (userMessage), functionOptions ))
73
74
74
75
logger.info(" Response: $response " )
75
76
@@ -87,9 +88,7 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
87
88
val userMessage = UserMessage (
88
89
" What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations." )
89
90
90
- val functionOptions = FunctionCallingOptions .builder()
91
- .function(" WeatherInfo" )
92
- .build()
91
+ val functionOptions = ToolCallingChatOptions .builder().toolNames(" weatherInfo" ).build()
93
92
94
93
val response = chatModel.call(Prompt (listOf (userMessage), functionOptions));
95
94
val output = response.getResult().output.text
@@ -103,14 +102,9 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
103
102
open class Config {
104
103
105
104
@Bean
106
- open fun weatherFunctionInfo (): FunctionCallback {
107
- return FunctionCallback .builder()
108
- .function(" WeatherInfo" , MockKotlinWeatherService ())
109
- .description(
110
- " Find the weather conditions, forecasts, and temperatures for a location, like a city or state."
111
- )
112
- .inputType(KotlinRequest ::class .java)
113
- .build()
105
+ @Description(" Find the weather conditions, forecasts, and temperatures for a location, like a city or state." )
106
+ open fun weatherInfo (): Function1 <KotlinRequest , KotlinResponse > {
107
+ return MockKotlinWeatherService ()
114
108
}
115
109
116
110
}
0 commit comments