//package com.smppw.modaq.infrastructure.components;
//
//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.NoApiKeyException;
//import com.alibaba.dashscope.exception.UploadFileException;
//import cn.hutool.core.map.MapUtil;
//import cn.hutool.core.util.StrUtil;
//
//import java.util.Arrays;
//import java.util.Collections;
//import java.util.Map;
//
//public class AliyunAIRPC {
//    private Object callOCR(String localPath, String userMsg) throws NoApiKeyException, UploadFileException {
//        String filePath = "file://" + localPath;
//        MultiModalConversation conv = new MultiModalConversation();
//        Map<String, Object> map = MapUtil.newHashMap();
//        map.put("image", filePath);
//        // 输入图像的最大像素阈值，超过该值图像会按原比例缩小，直到总像素低于max_pixels
//        map.put("max_pixels", "6422528");
//        // 输入图像的最小像素阈值，小于该值图像会按原比例放大，直到总像素大于min_pixels
//        map.put("min_pixels", "3136");
//        // 开启图像自动转正功能
//        map.put("enable_rotate", true);
//        MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
//                .content(Arrays.asList(
//                        map,
//                        // qwen-vl-ocr-latest未设置内置任务时，支持在以下text字段中传入Prompt，若未传入则使用默认的Prompt：Please output only the text content from the image without any additional descriptions or formatting.
//                        // 如调用qwen-vl-ocr-1028，模型会使用固定Prompt：Read all the text in the image.，不支持用户在text中传入自定义Prompt
//                        Collections.singletonMap("text", userMsg))).build();
//        String dashscopeApiKey = System.getenv("DASHSCOPE_API_KEY");
//        if (StrUtil.isBlank(dashscopeApiKey)) {
//            dashscopeApiKey = "sk-7f1caa54f94047db91d4e36f7ee811c5";
//        }
//        MultiModalConversationParam param = MultiModalConversationParam.builder()
//                // 若没有配置环境变量，请用百炼API Key将下行替换为：.apiKey("sk-xxx")
//                .apiKey(dashscopeApiKey)
//                .model("qwen-vl-ocr-latest")
//                .message(userMessage)
//                .topP(0.001)
//                .temperature(0.1f)
//                .maxLength(8192)
//                .build();
//        MultiModalConversationResult result = conv.call(param);
//        return result.getOutput().getChoices().get(0).getMessage().getContent().get(0).get("text");
//    }
//}
