|
|
@ -2,6 +2,7 @@ package com.hnac.gglm.bigmodel.zhipuai.handler; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Assert; |
|
|
|
import cn.hutool.core.lang.Assert; |
|
|
|
import com.hnac.gglm.bigmodel.zhipuai.constants.ErrorCode; |
|
|
|
import com.hnac.gglm.bigmodel.zhipuai.constants.ErrorCode; |
|
|
|
|
|
|
|
import com.hnac.hzims.common.utils.FileUtil; |
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
import com.zhipu.oapi.Constants; |
|
|
|
import com.zhipu.oapi.Constants; |
|
|
|
import com.zhipu.oapi.service.v4.model.ChatCompletionRequest; |
|
|
|
import com.zhipu.oapi.service.v4.model.ChatCompletionRequest; |
|
|
@ -11,6 +12,7 @@ import com.zhipu.oapi.service.v4.model.ModelApiResponse; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springblade.core.tool.jackson.JsonUtil; |
|
|
|
import org.springblade.core.tool.jackson.JsonUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
@ -43,6 +45,12 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ChatCompletionRequest getRequest(String text, String url) { |
|
|
|
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<ChatMessage> messages = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> contentList = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> contentList = new ArrayList<>(); |
|
|
|
Map<String, Object> textMap = new HashMap<>(); |
|
|
|
Map<String, Object> textMap = new HashMap<>(); |
|
|
@ -51,7 +59,7 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler { |
|
|
|
Map<String, Object> typeMap = new HashMap<>(); |
|
|
|
Map<String, Object> typeMap = new HashMap<>(); |
|
|
|
typeMap.put("type", "image_url"); |
|
|
|
typeMap.put("type", "image_url"); |
|
|
|
Map<String, Object> urlMap = new HashMap<>(); |
|
|
|
Map<String, Object> urlMap = new HashMap<>(); |
|
|
|
urlMap.put("url", url); |
|
|
|
urlMap.put("url", StringUtil.isBlank(base64) ? url : base64); |
|
|
|
typeMap.put("image_url", urlMap); |
|
|
|
typeMap.put("image_url", urlMap); |
|
|
|
contentList.add(textMap); |
|
|
|
contentList.add(textMap); |
|
|
|
contentList.add(typeMap); |
|
|
|
contentList.add(typeMap); |
|
|
|