Spring AI(多模态)
接上篇:Spring AI(音频转文本、文本转音频)
View Code
1、多模态(可以发一段文字和一张图片)
示例代码如下:
/** * 多模态 * @author ithailin */ @RestController @RequestMapping("/ai") public class MultiModelController { private static final Logger logger = LoggerFactory.getLogger(MultiModelController.class); @Autowired private ChatClient chatClient; @RequestMapping("/mulit") public Object mulit(String msg,String imgUrl) throws MalformedURLException { logger.info("msg:{},imgUrl:{}",msg,imgUrl); Media media = new Media(MimeTypeUtils.IMAGE_PNG,new URL(imgUrl)); UserMessage userMessage = new UserMessage(msg, List.of(media)); OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder().withModel(OpenAiApi.ChatModel.GPT_4_VISION_PREVIEW.getValue()).build(); Prompt prompt = new Prompt(List.of(userMessage), openAiChatOptions); ChatResponse response = chatClient.call(prompt); return response.getResult().getOutput().getContent(); } }
接下篇: