luyie
3 months ago
17 changed files with 303 additions and 78 deletions
@ -0,0 +1,56 @@
|
||||
package com.hnac.hzims.bigmodel.api.dto; |
||||
|
||||
import io.swagger.annotations.ApiModel; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/19 10:38 |
||||
*/ |
||||
@Data |
||||
@ApiModel(description = "分析返回信息") |
||||
public class BigModelAnalysisResponseDTO implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "是否成功", required = true) |
||||
private Boolean success = null; |
||||
|
||||
@ApiModelProperty(value = "分析结果数据列表") |
||||
private List<BigModelAnalysisResult> data; |
||||
|
||||
@ApiModelProperty(value = "状态码", required = true) |
||||
private int code; |
||||
|
||||
@ApiModelProperty(value = "返回消息") |
||||
private String msg; |
||||
|
||||
|
||||
@Data |
||||
@ApiModel(description = "分析结果") |
||||
public static class BigModelAnalysisResult implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@ApiModelProperty(value = "承载数据") |
||||
private Object result; |
||||
|
||||
@ApiModelProperty(value = "结果字符串") |
||||
private String resultStr; |
||||
|
||||
@ApiModelProperty(value = "结果描述") |
||||
private String description; |
||||
|
||||
@ApiModelProperty(value = "结果描述") |
||||
private String checkTypeSon; |
||||
} |
||||
|
||||
public Boolean getSuccess() { |
||||
return Optional.ofNullable(success).orElse(Boolean.FALSE); |
||||
} |
||||
} |
@ -1,32 +1,50 @@
|
||||
package com.hnac.hzims.bigmodel.zhipuai.handler; |
||||
|
||||
import com.hnac.hzims.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; |
||||
import org.springblade.core.tool.jackson.JsonUtil; |
||||
|
||||
import java.util.Map; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @Author: ypj |
||||
* @Date: 2024/8/8 14:45 |
||||
*/ |
||||
public interface ZhipuAnalyser<Req, Resp> { |
||||
String QUESTION_PROFILE = "## Profile\n"; |
||||
|
||||
String QUESTION_CONSTRAINS = "## Constrains\n"; |
||||
|
||||
String QUESTION_OUTPUT_FORMAT = "## OutputFormat\n"; |
||||
|
||||
String getAnalysisStrategy(); |
||||
|
||||
String getAnalysisModel(); |
||||
|
||||
String getUrl(); |
||||
|
||||
void setUrl(String url); |
||||
|
||||
String getText(); |
||||
|
||||
void setText(String text); |
||||
|
||||
default boolean isSupport(String strategyCode) { |
||||
return getAnalysisStrategy().equals(strategyCode); |
||||
} |
||||
|
||||
Resp sendRequest(ZhipuAnalysisInfoEntity info, String url); |
||||
Resp sendRequest(String text, String url); |
||||
|
||||
Req getRequest(ZhipuAnalysisInfoEntity info, String url); |
||||
Req getRequest(String text, String url); |
||||
|
||||
String getResult(ZhipuAnalysisInfoEntity info, String url); |
||||
String getResult(String text, String url); |
||||
|
||||
default Map<String, Object> getResultMap(String text, String url) { |
||||
String result = getResult(text, url); |
||||
return Optional.ofNullable(result).map(str -> JsonUtil.toMap(result)).orElse(null); |
||||
} |
||||
|
||||
default Object getResultValue(ZhipuAnalysisInfoEntity info, String url) { |
||||
Map<String, Object> resultMap = JsonUtil.toMap(getResult(info, url)); |
||||
return resultMap.get(info.getResultKey()); |
||||
default Object getResultValue(String text, String key, String url) { |
||||
Map<String, Object> resultMap = getResultMap(text, url); |
||||
return Optional.ofNullable(resultMap).map(data -> data.get(key)).orElse(null); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue