|
|
|
@ -2,7 +2,6 @@ package com.hnac.gglm.bigmodel.zhipuai.handler;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Assert; |
|
|
|
|
import com.hnac.gglm.bigmodel.zhipuai.constants.ErrorCode; |
|
|
|
|
import com.hnac.hzims.common.utils.FileUtil; |
|
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
|
import com.zhipu.oapi.Constants; |
|
|
|
|
import com.zhipu.oapi.service.v4.model.ChatCompletionRequest; |
|
|
|
@ -12,7 +11,6 @@ import com.zhipu.oapi.service.v4.model.ModelApiResponse;
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.tool.jackson.JsonUtil; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
@ -39,18 +37,12 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler {
|
|
|
|
|
@Override |
|
|
|
|
public ModelApiResponse sendRequest(String text, String url) { |
|
|
|
|
ChatCompletionRequest request = getRequest(text, url); |
|
|
|
|
log.info("send zhipu ai request ,text is {},url is {}", text, url); |
|
|
|
|
log.info("send zhipu ai request ,text is {}", text); |
|
|
|
|
return client.invokeModelApi(request); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ChatCompletionRequest getRequest(String text, String url) { |
|
|
|
|
String base64 = null; |
|
|
|
|
try { |
|
|
|
|
base64 = FileUtil.getBase64(FileUtil.getUrlByteByRequest(url)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("get base64 error", e); |
|
|
|
|
} |
|
|
|
|
List<ChatMessage> messages = new ArrayList<>(); |
|
|
|
|
List<Map<String, Object>> contentList = new ArrayList<>(); |
|
|
|
|
Map<String, Object> textMap = new HashMap<>(); |
|
|
|
@ -59,7 +51,7 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler {
|
|
|
|
|
Map<String, Object> typeMap = new HashMap<>(); |
|
|
|
|
typeMap.put("type", "image_url"); |
|
|
|
|
Map<String, Object> urlMap = new HashMap<>(); |
|
|
|
|
urlMap.put("url", StringUtil.isBlank(base64) ? url : base64); |
|
|
|
|
urlMap.put("url", url); |
|
|
|
|
typeMap.put("image_url", urlMap); |
|
|
|
|
contentList.add(textMap); |
|
|
|
|
contentList.add(typeMap); |
|
|
|
|