Spring AI(多模态)

接上篇:Spring AI(音频转文本、文本转音频)
 

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();
    }
}
View Code

 

接下篇:

posted @ 2024-07-18 17:20  DHaiLin  阅读(148)  评论(0编辑  收藏  举报