JudgeRepository.java
2 KB
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
package com.hjx.parent.api;
import android.annotation.SuppressLint;
import com.google.gson.Gson;
import com.prws.common.net.NetWorks;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Single;
import retrofit2.Retrofit;
public class JudgeRepository {
private static final Gson gson = new Gson();
private static final ChatApi api;
static {
Retrofit retrofit = NetWorks.retrofit;
api = retrofit.create(ChatApi.class);
}
public static Single<Integer> singleJudge(String url) {
List<ChatMessage> messages = new ArrayList<>();
messages.add(ChatMessage.fromImage("system", setting, url));
return api.aiChat(JudgeRepository.url, token, new ChatRequest(model, messages))
.map(response -> {
if (response.choices == null) return null;
return response.choices.stream().findFirst()
.map(it -> it.message)
.map(ChatMessage::getTextContent)
.orElse(null);
})
.map(json -> {
JudgeResult result = gson.fromJson(json, JudgeResult.class);
return result.result;
})
;
}
private static final String model = "doubao-1-5-thinking-vision-pro-250428";
private static final String url = "https://ark.cn-beijing.volces.com/api/v3/chat/completions";
private static final String token = "Bearer a877087e-bb74-471b-8f2a-01e6b2220699";
private static final String setting =
"批改图片中的题目, 判断作答是否正确,并以Json格式返回结果,需要包含以下字段: \n" +
"result(批改结果, 枚举 0:不确定; 1:正确; 2:错误; 3:未作答).\n" +
"Json示例(供参考,无需复制): {\"result\": 1}\n" +
"一个图片中一般只会有一个题目, 返回一个结果即可.";
private static class JudgeResult {
public int result;
}
}