前言
ONE-PEACE是一個圖文音三模態通用表征模型,在語義分割、音文檢索、音頻分類和視覺定位幾個任務都達到了新SOTA表現,在視頻分類、圖像分類圖文檢索、以及多模態經典benchmark也都取得了比較領先的結果。
快速調用
調用前準備
已開通服務并獲得API-KEY:開通DashScope并創建API-KEY
已安裝最新版SDK:安裝DashScope SDK。
代碼示例
API-KEY設置
export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY
在完成了上面的API-KEY的設置之后,就可以通過下面的示例代碼提交請求了。
import dashscope
def image_call():
input = [{'image': 'https://dashscope.oss-cn-beijing.aliyuncs.com/images/256_1.png'},
]
result = dashscope.MultiModalEmbedding.call(model=dashscope.MultiModalEmbedding.Models.multimodal_embedding_one_peace_v1,
input=input,
auto_truncation=True)
print(result)
if __name__ == '__main__':
image_call()
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.embeddings.MultiModalEmbedding;
import com.alibaba.dashscope.embeddings.MultiModalEmbeddingItemImage;
import com.alibaba.dashscope.embeddings.MultiModalEmbeddingParam;
import com.alibaba.dashscope.embeddings.MultiModalEmbeddingResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import java.util.Arrays;
public class Main {
public static void imageEmbedding() throws ApiException, NoApiKeyException, UploadFileException {
MultiModalEmbedding embedding = new MultiModalEmbedding();
MultiModalEmbeddingItemImage image =
new MultiModalEmbeddingItemImage(
"https://dashscope.oss-cn-beijing.aliyuncs.com/images/256_1.png");
MultiModalEmbeddingParam param =
MultiModalEmbeddingParam.builder()
.model(MultiModalEmbedding.Models.MULTIMODAL_EMBEDDING_ONE_PEACE_V1)
.contents(Arrays.asList(image))
.build();
MultiModalEmbeddingResult result = embedding.call(param);
System.out.print(result);
}
public static void main(String[] args){
try {
imageEmbedding();
} catch (ApiException | NoApiKeyException | UploadFileException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
示例輸出
上面示例代碼請求正常完成之后,將會收到如下示例的返回結果。
{
"status_code": 200,
"request_id": "4fe2cde6-ba37-973f-9db8-2cd74a908a9f",
"code": "",
"message": "",
"output": {
"embedding": [ # The embedding vector
-0.0200169887393713,
.,
.,
.,
]
},
"usage": {
"image": {
"measure": 1,
"weight": 1
},
"total_usage": 4,
"audio": {
"measure": 1,
"weight": 2
},
"text": {
"measure": 1,
"weight": 1
}
}
}
了解更多
有關ONE-PEACE多模態向量表征API的詳細調用文檔可前往API詳情頁面進行了解。
文檔內容是否對您有幫助?