@Bean @Description("calculate sum") public Function<MockCalculate.Request, MockCalculate.Response> add() { returnnewMockCalculateAdd(); }
@Bean @Description("calculate multiplication") public Function<MockCalculate.Request, MockCalculate.Response> multiply() { returnnewMockCalculateMultiply(); }
@Bean @Description("calculate divide") public Function<MockCalculate.Request, MockCalculate.Response> divide() { returnnewMockCalculateDivide(); }
@Override public voidrun(String... args) { ChatClient.Builder builder = ChatClient.builder(chatModel); ChatClient chatClient = builder.build(); ChatClient.CallResponseSpec responseSpec = chatClient.prompt() .system("you are a calculate, you need analyze the user input, and solve it step by step, use the tools to calculate the value.") .user("hello, what is 30 increase 47%") .functions("add", "multiply", "divide") .call(); System.out.println(responseSpec.content()); System.exit(0); } }
add request: Request[n1=0.47, n2=30.0] add request: Request[n1=14.1, n2=30.0] To calculate the increase of47% on 30, I will use the following steps:
1.First, I need to convert the percentage into a decimal by dividing it by 100: 47 / 100 = 0.47 2.Then, I will multiply the original value (30) by thisdecimal: 30 * 0.47 = 14.1 3.Finally, I will add this result to the original value: 30 + 14.1 = 44.1