Commit 371ba051 by shentao

Merge branch 'feature' into 'release'

2024/07/11 嘉楠科技ai标注接入

See merge request !116
parents f12d1d20 de1ef24e
......@@ -230,6 +230,8 @@ public class AIMark implements Serializable {
/** 接口头信息*/
private JSONObject header;
private String waitFor;
public String getUrl() {
return url;
}
......@@ -261,5 +263,13 @@ public class AIMark implements Serializable {
public void setHeader(JSONObject header) {
this.header = header;
}
public String getWaitFor() {
return waitFor;
}
public void setWaitFor(String waitFor) {
this.waitFor = waitFor;
}
}
}
......@@ -18,12 +18,22 @@ public class AiApiResult {
private String negLabel;
private String related;
private String project;
private String result;
private Long createAt;
public String getRelated() {
return related;
}
public void setRelated(String related) {
this.related = related;
}
public String getNegLabel() {
return negLabel;
}
......
......@@ -6,20 +6,19 @@ package com.zhiwei.middleware.automatic.server.pojo.enums;
**/
public enum AiInterfaceEnums {
FEI_HE("飞鹤", "62baa19f4d9a553ac3e7cd9b", "feihe-compet-tagger"),
FEI_HE("飞鹤", "62baa19f4d9a553ac3e7cd9b"),
LAO_XIANG_JI("老乡鸡", "665d8791b36dd11c5e453955", "laoxiangji-tagger");
LAO_XIANG_JI("老乡鸡", "665d8791b36dd11c5e453955"),
JIA_NAN_KE_JI("嘉楠科技", "65efecab7d8b3a478260e7b6");
final String project;
final String projectId;
final String waitFor;
AiInterfaceEnums(String project, String projectId, String waitFor) {
AiInterfaceEnums(String project, String projectId) {
this.project = project;
this.projectId = projectId;
this.waitFor = waitFor;
}
public String getProject() {
......@@ -30,10 +29,6 @@ public enum AiInterfaceEnums {
return projectId;
}
public String getWaitFor() {
return waitFor;
}
public static AiInterfaceEnums create(String projectId) {
for (AiInterfaceEnums enums : AiInterfaceEnums.values()) {
if (enums.getProjectId().equals(projectId)) {
......
......@@ -58,7 +58,7 @@ public abstract class AbstractAiTaskService implements AiTaskService {
return null;
}
long endTime = System.currentTimeMillis() - now;
AiApiResult aiRes = aiApiResultConversion(s);
AiApiResult aiRes = aiApiResultConversion(s, aiParam);
if (Objects.isNull(aiRes)) {
requestResIncomplete(timeKey);
log.info("项目:{},数据url:{},耗时:{},ai接口返回信息不完整:{}", aiInterfaceEnums.getProject(), param.getJSONObject("data").getString(GenericAttribute.URL), endTime, s);
......@@ -86,7 +86,7 @@ public abstract class AbstractAiTaskService implements AiTaskService {
protected JSONObject aiInterfaceParamBuild(AiInterfaceParam aiParam) {
JSONObject param = new JSONObject();
param.put("wait_for", new String[]{aiInterfaceEnums.getWaitFor()});
param.put("wait_for", new String[]{aiParam.getAiMark().getInterfaceRelation().getWaitFor()});
JSONObject data = new JSONObject();
JSONObject json = aiParam.getJson();
data.put("author", json.getString(GenericAttribute.ES_SOURCE));
......@@ -134,34 +134,37 @@ public abstract class AbstractAiTaskService implements AiTaskService {
}
@Override
public AiApiResult aiApiResultConversion(String interfaceRes) {
public AiApiResult aiApiResultConversion(String interfaceRes, AiInterfaceParam aiParam) {
JSONObject res = JSONObject.parseObject(interfaceRes);
if (Objects.nonNull(res)) {
JSONObject waitRes = res.getJSONObject(aiInterfaceEnums.getWaitFor());
if (Objects.nonNull(waitRes)) {
JSONObject result = waitRes.getJSONObject("result");
if (Objects.nonNull(result)) {
aiApiResultTitleSubString(result);
if (waitRes.getString("status").equals("DONE") || (!StringUtils.isEmpty(result.getString("sent")) && StringUtils.isEmpty("dedup"))) {
AiApiResult aiRes = new AiApiResult();
aiRes.setId(waitRes.getString("result_id"));
aiRes.setCreateAt(System.currentTimeMillis());
aiRes.setInfo_class(result.getString("info_class"));
aiRes.setNoise(result.getString("denoise"));
aiRes.setSent(result.getString("sent"));
aiRes.setStatus(waitRes.getString("status"));
aiRes.setNegLabel(result.getString("neg_label"));
aiRes.setResult(res.toJSONString());
aiRes.setProject(aiInterfaceEnums.getProject());
aiApiResultDao.insert(aiRes);
return aiRes;
} else {
return aiApiResultDao.findOne(new Query(Criteria.where("_id").is(result.getString("dedup"))));
}
}
}
if (Objects.isNull(res)) {
return null;
}
JSONObject waitRes = res.getJSONObject(aiParam.getAiMark().getInterfaceRelation().getWaitFor());
if (Objects.isNull(waitRes)) {
return null;
}
JSONObject result = waitRes.getJSONObject("result");
if (Objects.isNull(result)) {
return null;
}
aiApiResultTitleSubString(result);
if (waitRes.getString("status").equals("DONE") || (!StringUtils.isEmpty(result.getString("sent")) && StringUtils.isEmpty("dedup"))) {
AiApiResult aiRes = new AiApiResult();
aiRes.setId(waitRes.getString("result_id"));
aiRes.setCreateAt(System.currentTimeMillis());
aiRes.setInfo_class(result.getString("info_class"));
aiRes.setNoise(result.getString("denoise"));
aiRes.setSent(result.getString("sent"));
aiRes.setStatus(waitRes.getString("status"));
aiRes.setNegLabel(result.getString("neg_label"));
aiRes.setRelated(result.getString("related"));
aiRes.setResult(res.toJSONString());
aiRes.setProject(aiInterfaceEnums.getProject());
aiApiResultDao.insert(aiRes);
return aiRes;
} else {
return aiApiResultDao.findOne(new Query(Criteria.where("_id").is(result.getString("dedup"))));
}
return null;
}
@Override
......@@ -215,6 +218,9 @@ public abstract class AbstractAiTaskService implements AiTaskService {
case "neg_label" :
relateValue = result.getNegLabel();
break;
case "related" :
relateValue = result.getRelated();
break;
}
return relateValue;
}
......
......@@ -39,7 +39,7 @@ public interface AiTaskService {
* @param interfaceRes 接口返回值
* @return AiApiResult
*/
AiApiResult aiApiResultConversion(String interfaceRes);
AiApiResult aiApiResultConversion(String interfaceRes, AiInterfaceParam aiParam);
void requestMarkTotalCount(String timeKey);
......
package com.zhiwei.middleware.automatic.son.task.aiTask;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.middleware.automatic.server.pojo.AiInterfaceParam;
import com.zhiwei.middleware.automatic.server.pojo.enums.AiInterfaceEnums;
import com.zhiwei.middleware.automatic.server.util.RedissonUtil;
import com.zhiwei.middleware.automatic.son.dao.AiApiResultDao;
import org.springframework.stereotype.Service;
/**
* author:liu-yu
* date: 2024/7/10 16:43
**/
@Service
public class AiTaskServiceJNKJ extends AbstractAiTaskService {
public AiTaskServiceJNKJ(RedissonUtil redissonUtil, AiApiResultDao aiApiResultDao) {
super(AiInterfaceEnums.JIA_NAN_KE_JI, redissonUtil, aiApiResultDao);
}
@Override
public JSONObject httpParamByMetadata(AiInterfaceParam aiParam) {
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment