Skip to content

Commit 58e05dc

Browse files
committed
Fix FunctionCallbackKotlinIT.kt
- Update to use ToolCallingChatOptions as functionOptions
1 parent f3c0ea0 commit 58e05dc

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackKotlinIT.kt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ import org.assertj.core.api.Assertions.assertThat
2020
import org.junit.jupiter.api.BeforeAll
2121
import org.junit.jupiter.api.Test
2222
import org.slf4j.LoggerFactory
23-
2423
import org.springframework.ai.autoconfigure.ollama.BaseOllamaIT
2524
import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration
2625
import org.springframework.ai.chat.messages.UserMessage
2726
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
3028
import org.springframework.ai.ollama.OllamaChatModel
31-
import org.springframework.ai.ollama.api.OllamaOptions
3229
import org.springframework.boot.autoconfigure.AutoConfigurations
3330
import org.springframework.boot.test.context.runner.ApplicationContextRunner
3431
import org.springframework.context.annotation.Bean
3532
import org.springframework.context.annotation.Configuration
33+
import org.springframework.context.annotation.Description
34+
3635

3736
class FunctionCallbackKotlinIT : BaseOllamaIT() {
3837

@@ -68,8 +67,10 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
6867
val userMessage = UserMessage(
6968
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.")
7069

70+
val functionOptions = ToolCallingChatOptions.builder().toolNames("weatherInfo").build()
71+
7172
val response = chatModel
72-
.call(Prompt(listOf(userMessage), OllamaOptions.builder().function("WeatherInfo").build()))
73+
.call(Prompt(listOf(userMessage), functionOptions))
7374

7475
logger.info("Response: $response")
7576

@@ -87,9 +88,7 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
8788
val userMessage = UserMessage(
8889
"What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.")
8990

90-
val functionOptions = FunctionCallingOptions.builder()
91-
.function("WeatherInfo")
92-
.build()
91+
val functionOptions = ToolCallingChatOptions.builder().toolNames("weatherInfo").build()
9392

9493
val response = chatModel.call(Prompt(listOf(userMessage), functionOptions));
9594
val output = response.getResult().output.text
@@ -103,14 +102,9 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() {
103102
open class Config {
104103

105104
@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()
114108
}
115109

116110
}

0 commit comments

Comments
 (0)