From 528cafe171adc5954070e7c63930af26ef853afd Mon Sep 17 00:00:00 2001 From: luyie Date: Wed, 25 Sep 2024 21:24:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E8=A7=86=E9=A2=91=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=E8=A7=86=E9=A2=91=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java | 12 ++---------- .../zhipuai/service/impl/ZhipuAnalysisServiceImpl.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java index 8176304..8a51335 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java @@ -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 messages = new ArrayList<>(); List> contentList = new ArrayList<>(); Map textMap = new HashMap<>(); @@ -59,7 +51,7 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler { Map typeMap = new HashMap<>(); typeMap.put("type", "image_url"); Map 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); diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java index db67772..6c83614 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java @@ -7,9 +7,9 @@ import com.hnac.gglm.bigmodel.zhipuai.constants.BaseEnum; import com.hnac.gglm.bigmodel.zhipuai.constants.ErrorCode; import com.hnac.gglm.bigmodel.zhipuai.constants.ResultStrategyType; import com.hnac.gglm.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; -import com.hnac.gglm.bigmodel.zhipuai.handler.result.ResultStrategy; import com.hnac.gglm.bigmodel.zhipuai.handler.ZhipuAnalyser; import com.hnac.gglm.bigmodel.zhipuai.handler.ZhipuAnalysisFactory; +import com.hnac.gglm.bigmodel.zhipuai.handler.result.ResultStrategy; import com.hnac.gglm.bigmodel.zhipuai.service.ZhipuAnalysisInfoService; import com.hnac.gglm.bigmodel.zhipuai.service.ZhipuAnalysisService; import com.hnac.gglm.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; @@ -99,7 +99,13 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService { String getSendUrl(ZhipuAnalysisFileRequest request) { if (StringUtil.isNotBlank(request.getUrl())) { - return request.getUrl(); + String base64 = null; + try { + base64 = FileUtil.getBase64(FileUtil.getUrlByteByRequest(request.getUrl())); + } catch (Exception e) { + log.info("get base64 error", e); + } + return StringUtil.isBlank(base64) ? request.getUrl() : base64; } Assert.isTrue(StringUtil.isNotBlank(request.getFilePath()), () -> { throw ErrorCode.GET_FILE_CONTENT_FAILURE.throwException();