1、开通服务
创建API-KEY:
2、代码调用
- 2.1 pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dashscope-sdk-java</artifactId>
<version>2.11.0</version>
</dependency>
- 2.2 code sample
import java.util.Arrays;
import java.util.Collections;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
public class Main {
public static void simpleMultiModalConversationCall()
throws ApiException, NoApiKeyException, UploadFileException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
.content(Arrays.asList(Collections.singletonMap("image", "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"),
Collections.singletonMap("text", "这是什么?"))).build();
MultiModalConversationParam param = MultiModalConversationParam.builder()
.model(MultiModalConversation.Models.QWEN_VL_PLUS)
.message(userMessage)
.apiKey("sk-6ebf4e2********")
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(result);
}
public static void main(String[] args) {
try {
simpleMultiModalConversationCall();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
- 2.3 测试结果
MultiModalConversationResult(requestId=199b6673-e022-9ba4-ab87-da0bbf42d983, usage=MultiModalConversationUsage(inputTokens=1277, outputTokens=60), output=MultiModalConversationOutput(choices=[MultiModalConversationOutput.Choice(finishReason=stop, message=MultiModalMessage(role=assistant, content=[{
text=这张图片显示了一位女士和她的狗在海滩上。她们似乎正在享受彼此的陪伴,狗狗坐在沙滩上,伸出爪子与女士握手或互动。背景是美丽的日落景色,海浪轻轻拍打着海岸线。这是一张充满温馨和友谊的照片。}]))]))