火山方舟里的配置教程就不说了,一定要选择支持图片理解的ai模型,具体代码如下,如果有图片的外网链接的话,可直接拿外网链接传入识别,如果图片没有链接访问的话,可以尝试转base64传入,或者上传到oss
public static void main(String[] args) {
// 4. 调用大模型Chat
ArkService service = new ArkService("你的apikey");
String url1="http:/外网ip:端口/image_1.jpg";
System.out.println("----- image input -----");
final List<ChatMessage> messages = new ArrayList<>();
final List<ChatCompletionContentPart> multiParts = new ArrayList<>();
multiParts.add(ChatCompletionContentPart.builder().type("text").text(
"。识别图片中的简历,并输出json字符串格式"
).build());
multiParts.add(ChatCompletionContentPart.builder().type("image_url").imageUrl(
new ChatCompletionContentPart.ChatCompletionContentPartImageURL(url1)
).build());
final ChatMessage userMessage = ChatMessage.builder().role(ChatMessageRole.USER)
.multiContent(multiParts).build();
messages.add(userMessage);
ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
.model("你的模型ep-开头的id")
.messages(messages)
.build();
service.createChatCompletion(chatCompletionRequest).getChoices().forEach(choice -> System.out.println(choice.getMessage().getContent()));
// shutdown service
service.shutdownExecutor();
}