|
|
@@ -0,0 +1,31 @@
|
|
|
+package space.anyi.springAiAlibabaLearn.controller;
|
|
|
+
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.ai.chat.client.ChatClient;
|
|
|
+import org.springframework.ai.chat.model.ChatModel;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import space.anyi.springAiAlibabaLearn.tool.MyTool;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/tool")
|
|
|
+public class ToolTestController {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ToolTestController.class);
|
|
|
+ public final ChatClient chatClient;
|
|
|
+
|
|
|
+ public ToolTestController(ChatModel chatModel) {
|
|
|
+ this.chatClient = ChatClient.builder(chatModel)
|
|
|
+ //配置LLM默认的tool,将自定义的tool配置chatClient中
|
|
|
+ .defaultTools(new MyTool())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ @GetMapping("/test")
|
|
|
+ public String toolTest(@RequestParam("message")String message){
|
|
|
+ return chatClient.prompt(message)
|
|
|
+ .call()
|
|
|
+ .content();
|
|
|
+ }
|
|
|
+}
|