diff --git a/.gitignore b/.gitignore index bf2517a..d0ac215 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /hzims-biz-common/target /hzims-service/*/target /hzims-service-api/*/target +target log *.iml diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/BigModelAnalysisClient.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/BigModelAnalysisClient.java index 381bd06..bb0532d 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/BigModelAnalysisClient.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/BigModelAnalysisClient.java @@ -2,7 +2,7 @@ package com.hnac.hzims.bigmodel.api.feign; import com.hnac.hzims.bigmodel.api.dto.BigModelAnalysisDTO; import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisService; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisRequest; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.PostMapping; @@ -21,6 +21,6 @@ public class BigModelAnalysisClient implements IBigModelAnalysisClient { @Override @PostMapping(PREFIX_API + "/analysis") public R analysis(BigModelAnalysisDTO analysisInfo) { - return R.data(analysisService.analysis(ZhipuAnalysisRequest.of(analysisInfo))); + return R.data(analysisService.analysis(ZhipuAnalysisFileRequest.of(analysisInfo))); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfigProperties.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfigProperties.java index 827fae6..bfb5a98 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfigProperties.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfigProperties.java @@ -10,7 +10,7 @@ import org.springframework.stereotype.Component; * @Date: 2024/8/8 14:03 */ @Data -@ConfigurationProperties(prefix = "zhipuai") +@ConfigurationProperties(prefix = "bigmodel.zhipuai") public class ZhipuAiConfigProperties { private String apiSecret; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuAnalysisInfoController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuAnalysisInfoController.java new file mode 100644 index 0000000..5675fa0 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuAnalysisInfoController.java @@ -0,0 +1,39 @@ +package com.hnac.hzims.bigmodel.zhipuai.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisInfoService; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisInfoVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +/** + * @Author: ypj + * @Date: 2024/8/12 20:22 + */ +@RestController +@Api(value = "智谱分析信息管理", tags = "智谱分析信息管理") +@RequestMapping("/zhipu/info") +@AllArgsConstructor +public class ZhipuAnalysisInfoController { + private final ZhipuAnalysisInfoService analysisInfoService; + + @PostMapping("/save") + @ApiOperation("保存智谱分析信息") + @ApiOperationSupport(order = 1) + public R save(@RequestBody @Validated ZhipuAnalysisInfoVO request) { + return R.status(analysisInfoService.save(request.toEntity())); + } + + @GetMapping("/remove") + @ApiOperation("批量删除智谱分析信息") + @ApiOperationSupport(order = 2) + public R remove (@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) { + return R.status(analysisInfoService.removeByIds(Func.toLongList(",",ids))); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuController.java index 13db651..cbdfe95 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/controller/ZhipuController.java @@ -2,8 +2,8 @@ package com.hnac.hzims.bigmodel.zhipuai.controller; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisService; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisRequest; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisResponse; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; @@ -30,7 +30,7 @@ public class ZhipuController { @PostMapping("/analysis") @ApiOperation("分析") @ApiOperationSupport(order = 1) - public R analysis(@RequestBody @Valid ZhipuAnalysisRequest request) { + public R analysis(@RequestBody @Valid ZhipuAnalysisFileRequest request) { return R.data(analysisService.analysis(request)); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/entity/ZhipuAnalysisInfoEntity.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/entity/ZhipuAnalysisInfoEntity.java index ffac88d..7375afd 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/entity/ZhipuAnalysisInfoEntity.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/entity/ZhipuAnalysisInfoEntity.java @@ -1,25 +1,53 @@ package com.hnac.hzims.bigmodel.zhipuai.entity; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import org.springblade.core.mp.base.BaseEntity; /** * @Author: ypj * @Date: 2024/8/8 15:17 */ +@ApiModel(value ="大模型分析信息") @Data +@EqualsAndHashCode(callSuper = false) +@TableName("hzims_analysis_info") public class ZhipuAnalysisInfoEntity extends BaseEntity { - private String resultType; + @ApiModelProperty(value = "策略编码") + @TableField("CODE") + private String code; + @ApiModelProperty(value = "策略名称") + @TableField("NAME") private String name; - private String code; - + @ApiModelProperty(value = "调用模型名称") + @TableField("MODEL") private String model; + @ApiModelProperty(value = "模型交互内容") + @TableField("REQUEST_CONTENT") private String requestContent; + @ApiModelProperty(value = "结果解析策略") + @TableField("RESULT_STRATEGY") private String resultStrategy; + @ApiModelProperty(value = "结果类型") + @TableField("RESULT_TYPE") + private String resultType; + + @ApiModelProperty(value = "结果查询key值") + @TableField("RESULT_KEY") + private String resultKey; + + @ApiModelProperty(value = "结果对比内容") + @TableField("RESULT_CONDITION") + private String resultCondition; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/AbstractZhipuAnalysisHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/AbstractZhipuAnalysisHandler.java index f63d689..796fbb9 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/AbstractZhipuAnalysisHandler.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/AbstractZhipuAnalysisHandler.java @@ -16,8 +16,4 @@ public abstract class AbstractZhipuAnalysisHandler implements ZhipuAnalyser { @Resource protected ClientV4 client; - @Override - public String getBase64(String url) { - return Base64.getEncoder().encodeToString(getFileBytes(url)); - } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalyser.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalyser.java index 4bb7d5f..b7696ba 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalyser.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalyser.java @@ -8,10 +8,6 @@ import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; */ public interface ZhipuAnalyser { - String getBase64(String url); - - byte[] getFileBytes(String url); - String getAnalysisStrategy(); String getAnalysisModel(); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java index e04838f..e24865b 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java @@ -38,11 +38,6 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler { } @Override - public byte[] getFileBytes(String url) { - return new byte[0]; - } - - @Override public ModelApiResponse sendRequest(ZhipuAnalysisInfoEntity info, String url) { ChatCompletionRequest request = getRequest(info, url); log.info("send zhipu ai request :{}", request); @@ -59,7 +54,7 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler { Map typeMap = new HashMap<>(); typeMap.put("type", "image_url"); Map urlMap = new HashMap<>(); - urlMap.put("url", getBase64(url)); + urlMap.put("url", url); typeMap.put("image_url", urlMap); contentList.add(textMap); contentList.add(typeMap); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerTest.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerTest.java index 4527301..31780b5 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerTest.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerTest.java @@ -1,22 +1,9 @@ package com.hnac.hzims.bigmodel.zhipuai.handler; -import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; -import com.zhipu.oapi.Constants; -import com.zhipu.oapi.service.v4.model.ChatCompletionRequest; -import com.zhipu.oapi.service.v4.model.ChatMessage; -import com.zhipu.oapi.service.v4.model.ChatMessageRole; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * @Author: ypj * @Date: 2024/8/12 10:11 @@ -32,26 +19,4 @@ public class ZhipuAnalysisHandlerTest extends ZhipuAnalysisHandlerGlm4v { return model; } - @Override - public byte[] getFileBytes(String url) { - File file = new File(url); - FileInputStream fileInputStream = null; - try { - fileInputStream = new FileInputStream(file); - byte[] bytes = new byte[(int) file.length()]; - fileInputStream.read(bytes); - return bytes; - } catch (Exception e) { - log.error("读取文件出错", e); - } finally { - if (null != fileInputStream) { - try { - fileInputStream.close(); - } catch (IOException ignore) { - } - } - } - return null; - } - } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/mapper/ZhipuAnalysisInfoMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/mapper/ZhipuAnalysisInfoMapper.java new file mode 100644 index 0000000..0e993b6 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/mapper/ZhipuAnalysisInfoMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.zhipuai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; + +/** + * @Author: ypj + * @Date: 2024/8/12 20:05 + */ +public interface ZhipuAnalysisInfoMapper extends BaseMapper { +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisInfoService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisInfoService.java new file mode 100644 index 0000000..823b870 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisInfoService.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.zhipuai.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; + +/** + * @Author: ypj + * @Date: 2024/8/12 20:03 + */ +public interface ZhipuAnalysisInfoService extends IService { +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisService.java index 08290a8..f6649ca 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/ZhipuAnalysisService.java @@ -1,8 +1,8 @@ package com.hnac.hzims.bigmodel.zhipuai.service; import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisRequest; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisResponse; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileResponse; /** * @Author: ypj @@ -10,7 +10,7 @@ import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisResponse; */ public interface ZhipuAnalysisService { - ZhipuAnalysisResponse analysis(ZhipuAnalysisRequest request); + ZhipuAnalysisFileResponse analysis(ZhipuAnalysisFileRequest request); - ZhipuAnalysisInfoEntity getAnalysisInfo(ZhipuAnalysisRequest request); + ZhipuAnalysisInfoEntity getAnalysisInfo(ZhipuAnalysisFileRequest request); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisInfoServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisInfoServiceImpl.java new file mode 100644 index 0000000..8dc9e47 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisInfoServiceImpl.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.bigmodel.zhipuai.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; +import com.hnac.hzims.bigmodel.zhipuai.mapper.ZhipuAnalysisInfoMapper; +import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisInfoService; +import org.springframework.stereotype.Service; + +/** + * @Author: ypj + * @Date: 2024/8/12 20:03 + */ +@Service +public class ZhipuAnalysisInfoServiceImpl extends ServiceImpl implements ZhipuAnalysisInfoService { +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java index b0eed30..6ea5bd6 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java @@ -4,11 +4,15 @@ import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; import com.hnac.hzims.bigmodel.zhipuai.handler.ZhipuAnalyser; import com.hnac.hzims.bigmodel.zhipuai.handler.ZhipuAnalysisFactory; import com.hnac.hzims.bigmodel.zhipuai.service.ZhipuAnalysisService; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisRequest; -import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisResponse; +import com.hnac.hzims.bigmodel.zhipuai.utils.ZhipuUtil; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; +import com.hnac.hzims.bigmodel.zhipuai.vo.ZhipuAnalysisFileResponse; +import com.hnac.hzinfo.exception.HzServiceException; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; import java.util.Objects; @@ -23,17 +27,34 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService { private final ZhipuAnalysisFactory analysisFactory; @Override - public ZhipuAnalysisResponse analysis(ZhipuAnalysisRequest request) { + public ZhipuAnalysisFileResponse analysis(ZhipuAnalysisFileRequest request) { + Assert.isTrue(StringUtil.isBlank(request.getFilePath()) && StringUtil.isBlank(request.getFileContent()) && StringUtil.isBlank(request.getUrl()), () -> { + throw new HzServiceException("文件为空"); + }); ZhipuAnalysisInfoEntity info = getAnalysisInfo(request); ZhipuAnalyser analyser = analysisFactory.getAnalysisStrategy(info.getModel()); - String resultStr = analyser.getResult(info, request.getUrl()); - ZhipuAnalysisResponse response = new ZhipuAnalysisResponse(); + + String resultStr = analyser.getResult(info, getSendUrl(request)); + ZhipuAnalysisFileResponse response = new ZhipuAnalysisFileResponse(); response.setResultStr(resultStr); return response; } + String getSendUrl(ZhipuAnalysisFileRequest request) { + if (StringUtil.isNotBlank(request.getUrl())) { + return request.getUrl(); + } + if (StringUtil.isNotBlank(request.getFileContent())) { + return request.getFileContent(); + } + if (StringUtil.isNotBlank(request.getFilePath())) { + return ZhipuUtil.getBase64(request.getFilePath()); + } + return null; + } + @Override - public ZhipuAnalysisInfoEntity getAnalysisInfo(ZhipuAnalysisRequest request) { + public ZhipuAnalysisInfoEntity getAnalysisInfo(ZhipuAnalysisFileRequest request) { if (Objects.isNull(request.getCode())) { return request.toAnalysisInfo(); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/utils/ZhipuUtil.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/utils/ZhipuUtil.java new file mode 100644 index 0000000..cec9ca8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/utils/ZhipuUtil.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.bigmodel.zhipuai.utils; + +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Base64; + +/** + * @Author: ypj + * @Date: 2024/8/12 21:07 + */ +@Slf4j +public class ZhipuUtil { + + public static byte[] getFileBytes(String filePath) { + File file = new File(filePath); + FileInputStream fileInputStream = null; + try { + fileInputStream = new FileInputStream(file); + byte[] bytes = new byte[(int) file.length()]; + fileInputStream.read(bytes); + return bytes; + } catch (Exception e) { + log.error("读取文件出错", e); + } finally { + if (null != fileInputStream) { + try { + fileInputStream.close(); + } catch (IOException ignore) { + } + } + } + return null; + } + + public static String getBase64(byte[] bytes) { + return Base64.getEncoder().encodeToString(bytes); + } + + public static String getBase64(String filePath) { + return getBase64(getFileBytes(filePath)); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisRequest.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisFileRequest.java similarity index 79% rename from hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisRequest.java rename to hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisFileRequest.java index c2fefc1..50a0fae 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisRequest.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisFileRequest.java @@ -12,7 +12,7 @@ import lombok.Data; */ @Data @ApiModel(value = "智谱分析请求", description = "智谱分析请求") -public class ZhipuAnalysisRequest { +public class ZhipuAnalysisFileRequest { @ApiModelProperty("策略编码") private String code; @@ -25,6 +25,9 @@ public class ZhipuAnalysisRequest { @ApiModelProperty("本地文件路径") private String filePath; + @ApiModelProperty("文件内容") + private String fileContent; + @ApiModelProperty("发送内容") private String content; @@ -33,14 +36,14 @@ public class ZhipuAnalysisRequest { public ZhipuAnalysisInfoEntity toAnalysisInfo() { ZhipuAnalysisInfoEntity info = new ZhipuAnalysisInfoEntity(); + info.setCode(this.getCode()); info.setModel(this.getModel()); info.setRequestContent(this.content); - info.setModel(this.getModel()); return info; } - public static ZhipuAnalysisRequest of(BigModelAnalysisDTO analysisDTO) { - ZhipuAnalysisRequest request = new ZhipuAnalysisRequest(); + public static ZhipuAnalysisFileRequest of(BigModelAnalysisDTO analysisDTO) { + ZhipuAnalysisFileRequest request = new ZhipuAnalysisFileRequest(); request.setCode(analysisDTO.getCode()); request.setUrl(analysisDTO.getUrl()); return request; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisResponse.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisFileResponse.java similarity index 89% rename from hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisResponse.java rename to hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisFileResponse.java index 592e3af..1755fad 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisResponse.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisFileResponse.java @@ -10,7 +10,7 @@ import lombok.Data; */ @Data @ApiModel(value = "智谱分析返回",description = "智谱分析返回") -public class ZhipuAnalysisResponse { +public class ZhipuAnalysisFileResponse { @ApiModelProperty("返回结果") String resultStr; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisInfoVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisInfoVO.java new file mode 100644 index 0000000..574dfd8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/vo/ZhipuAnalysisInfoVO.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.bigmodel.zhipuai.vo; + +import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.tool.utils.BeanUtil; + +import javax.validation.constraints.NotNull; + +/** + * @Author: ypj + * @Date: 2024/8/8 15:17 + */ +@ApiModel(value = "大模型分析信息") +@Data +@EqualsAndHashCode(callSuper = false) +public class ZhipuAnalysisInfoVO { + + @ApiModelProperty(value = "策略编码") + @NotNull + private String code; + + @ApiModelProperty(value = "策略名称") + private String name; + + @ApiModelProperty(value = "调用模型名称") + @NotNull + private String model; + + @ApiModelProperty(value = "模型交互内容") + private String requestContent; + + @ApiModelProperty(value = "结果解析策略") + private String resultStrategy; + + @ApiModelProperty(value = "结果类型") + private String resultType; + + @ApiModelProperty(value = "结果查询key值") + private String resultKey; + + @ApiModelProperty(value = "结果对比内容") + private String resultCondition; + + public ZhipuAnalysisInfoEntity toEntity() { + return BeanUtil.copy(this, ZhipuAnalysisInfoEntity.class); + } +}