Java智能之Spring AI:5分钟打造智能聊天模型的利器
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/api/chat")
public class ChatController {
private final ChatService chatService;
@Autowired
public ChatController(ChatService chatService) {
this.chatService = chatService;
}
@GetMapping("/message")
@ResponseBody
public MessageResponse getMessage(String text) {
return chatService.generateMessage(text);
}
}
这段代码展示了如何在Spring框架中创建一个简单的聊天控制器,它接收用户输入的文本并调用ChatService
来生成回复。这个例子简单明了,展示了如何将智能聊天模型集成到现代Web应用程序中。
评论已关闭