From 58e05dc0e0c6640175bc8620da1ebcf93457b963 Mon Sep 17 00:00:00 2001 From: Ilayaperumal Gopinathan Date: Thu, 6 Feb 2025 11:08:38 +0000 Subject: [PATCH] Fix FunctionCallbackKotlinIT.kt - Update to use ToolCallingChatOptions as functionOptions --- .../ollama/tool/FunctionCallbackKotlinIT.kt | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackKotlinIT.kt b/spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackKotlinIT.kt index 691c22bf9..337b1775f 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackKotlinIT.kt +++ b/spring-ai-spring-boot-autoconfigure/src/test/kotlin/org/springframework/ai/autoconfigure/ollama/tool/FunctionCallbackKotlinIT.kt @@ -20,19 +20,18 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.slf4j.LoggerFactory - import org.springframework.ai.autoconfigure.ollama.BaseOllamaIT import org.springframework.ai.autoconfigure.ollama.OllamaAutoConfiguration import org.springframework.ai.chat.messages.UserMessage import org.springframework.ai.chat.prompt.Prompt -import org.springframework.ai.model.function.FunctionCallback -import org.springframework.ai.model.function.FunctionCallingOptions +import org.springframework.ai.model.tool.ToolCallingChatOptions import org.springframework.ai.ollama.OllamaChatModel -import org.springframework.ai.ollama.api.OllamaOptions import org.springframework.boot.autoconfigure.AutoConfigurations import org.springframework.boot.test.context.runner.ApplicationContextRunner import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Description + class FunctionCallbackKotlinIT : BaseOllamaIT() { @@ -68,8 +67,10 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() { val userMessage = UserMessage( "What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.") + val functionOptions = ToolCallingChatOptions.builder().toolNames("weatherInfo").build() + val response = chatModel - .call(Prompt(listOf(userMessage), OllamaOptions.builder().function("WeatherInfo").build())) + .call(Prompt(listOf(userMessage), functionOptions)) logger.info("Response: $response") @@ -87,9 +88,7 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() { val userMessage = UserMessage( "What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.") - val functionOptions = FunctionCallingOptions.builder() - .function("WeatherInfo") - .build() + val functionOptions = ToolCallingChatOptions.builder().toolNames("weatherInfo").build() val response = chatModel.call(Prompt(listOf(userMessage), functionOptions)); val output = response.getResult().output.text @@ -103,14 +102,9 @@ class FunctionCallbackKotlinIT : BaseOllamaIT() { open class Config { @Bean - open fun weatherFunctionInfo(): FunctionCallback { - return FunctionCallback.builder() - .function("WeatherInfo", MockKotlinWeatherService()) - .description( - "Find the weather conditions, forecasts, and temperatures for a location, like a city or state." - ) - .inputType(KotlinRequest::class.java) - .build() + @Description("Find the weather conditions, forecasts, and temperatures for a location, like a city or state.") + open fun weatherInfo(): Function1 { + return MockKotlinWeatherService() } }