1、聊天程序(调用一次接口)
package com.ithailin.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.openai.OpenAiChatModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * 聊天程序 * @author ithailin */ @ResponseBody @Controller @RequestMapping("/ai") public class ChatController { private static final Logger logger = LoggerFactory.getLogger(ChatController.class); /** * spring-ai 自动装配的,可以注入使用 */ @Autowired private OpenAiChatModel openAiChatModel; /** * 调用openai的接口 * @param msg:我们提问的消息 * @return */ @RequestMapping("/chat") public String chat(String msg){ logger.info("msg:{}",msg ); String called = openAiChatModel.call(msg); return called; } }View Code
标签:String,AI,Spring,springframework,ai,聊天,import,msg,org From: https://www.cnblogs.com/jhdhl/p/18302803