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 singleJudge(String url) { List 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; } }