Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
75 lines (67 loc) · 3.26 KB

File metadata and controls

75 lines (67 loc) · 3.26 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import com.alibaba.dashscope.embeddings.BatchTextEmbedding;
import com.alibaba.dashscope.embeddings.BatchTextEmbeddingParam;
import com.alibaba.dashscope.embeddings.BatchTextEmbeddingResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.task.AsyncTaskListResult;
import com.alibaba.dashscope.utils.JsonUtils;
public class BatchTextEmbeddingUsage {
public static void basicCall() throws ApiException, NoApiKeyException {
BatchTextEmbeddingParam param = BatchTextEmbeddingParam.builder()
.model(BatchTextEmbedding.Models.TEXT_EMBEDDING_ASYNC_V1)
.url("https://modelscope.oss-cn-beijing.aliyuncs.com/resource/text_embedding_file.txt")
.build();
BatchTextEmbedding textEmbedding = new BatchTextEmbedding();
BatchTextEmbeddingResult result = textEmbedding.call(param);
System.out.println(result);
}
// 创建批处理任务,
public static BatchTextEmbeddingResult createTask() throws ApiException, NoApiKeyException {
BatchTextEmbeddingParam param = BatchTextEmbeddingParam.builder()
.model(BatchTextEmbedding.Models.TEXT_EMBEDDING_ASYNC_V1)
.url("https://modelscope.oss-cn-beijing.aliyuncs.com/resource/text_embedding_file.txt")
.build();
BatchTextEmbedding textEmbedding = new BatchTextEmbedding();
return textEmbedding.asyncCall(param);
}
// 获取任务状态
public static void fetchTaskStatus(BatchTextEmbeddingResult result)
throws ApiException, NoApiKeyException {
BatchTextEmbedding textEmbedding = new BatchTextEmbedding();
result = textEmbedding.fetch(result, null);
System.out.println(result);
}
// 等待任务结束,wait内部封装了轮询逻辑,会一直等待任务结束
public static void waitTask(BatchTextEmbeddingResult result)
throws ApiException, NoApiKeyException {
BatchTextEmbedding textEmbedding = new BatchTextEmbedding();
result = textEmbedding.wait(result, null);
System.out.println(result);
}
// 取消任务,只能取消处于pending状态的任务
public static void cancelTask(BatchTextEmbeddingResult result)
throws ApiException, NoApiKeyException {
BatchTextEmbedding textEmbedding = new BatchTextEmbedding();
result = textEmbedding.cancel(result, null);
System.out.println(result);
}
// 查询已经提交的任务
public static void list() throws ApiException, NoApiKeyException {
AsyncTaskListParam param = AsyncTaskListParam.builder().pageNo(1).pageSize(20).build();
BatchTextEmbedding textEmbedding = new BatchTextEmbedding();
AsyncTaskListResult result = textEmbedding.list(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
BatchTextEmbeddingResult task = createTask();
fetchTaskStatus(task);
waitTask(task);
// list();
} catch (ApiException | NoApiKeyException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.