如何使用 GPT-4o 和 SpringAI 1.0.0 里程碑生成图像描述

问题描述 投票:0回答:1

我正在使用 Spring AI 1.0.0-M1 尝试将图像提交到 GPT-4o 进行描述。

以下是代码:

@Autowired
final ChatClient chatClient;

@Override
public String getDescription(MultipartFile file) throws IOException {
OpenAiChatOptions chatOptions = OpenAiChatOptions.builder()
        .withModel(OpenAiApi.ChatModel.GPT_4_O.getValue())
        .build();

Resource resource = new ByteArrayResource(file.getBytes());

var userMessage = new UserMessage(
        "Explain what do you see in this picture?", 
        List.of(new Media(MimeTypeUtils.IMAGE_JPEG, resource)));
var response = chatClient.prompt().user(userMessage.getContent()).call().chatResponse();
return response.getResult().getOutput().getContent();

}

我不断收到此消息:

"I'm sorry, but I can't see pictures or images. If you describe the picture to me, I'll do my best to help you understand or analyze it!"

我做错了什么吗?

spring-ai
1个回答
0
投票

您可以在这里找到一个有效的示例: https://github.com/michaelisvy/demo-spring-ai/blob/main/src/main/java/com/spring/image/ImageService.java

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.