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 { ...@@ -230,6 +230,8 @@ public class AIMark implements Serializable {
/** 接口头信息*/ /** 接口头信息*/
private JSONObject header; private JSONObject header;
private String waitFor;
public String getUrl() { public String getUrl() {
return url; return url;
} }
...@@ -261,5 +263,13 @@ public class AIMark implements Serializable { ...@@ -261,5 +263,13 @@ public class AIMark implements Serializable {
public void setHeader(JSONObject header) { public void setHeader(JSONObject header) {
this.header = header; this.header = header;
} }
public String getWaitFor() {
return waitFor;
}
public void setWaitFor(String waitFor) {
this.waitFor = waitFor;
}
} }
} }
...@@ -18,12 +18,22 @@ public class AiApiResult { ...@@ -18,12 +18,22 @@ public class AiApiResult {
private String negLabel; private String negLabel;
private String related;
private String project; private String project;
private String result; private String result;
private Long createAt; private Long createAt;
public String getRelated() {
return related;
}
public void setRelated(String related) {
this.related = related;
}
public String getNegLabel() { public String getNegLabel() {
return negLabel; return negLabel;
} }
......
...@@ -6,20 +6,19 @@ package com.zhiwei.middleware.automatic.server.pojo.enums; ...@@ -6,20 +6,19 @@ package com.zhiwei.middleware.automatic.server.pojo.enums;
**/ **/
public enum AiInterfaceEnums { 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 project;
final String projectId; final String projectId;
final String waitFor; AiInterfaceEnums(String project, String projectId) {
AiInterfaceEnums(String project, String projectId, String waitFor) {
this.project = project; this.project = project;
this.projectId = projectId; this.projectId = projectId;
this.waitFor = waitFor;
} }
public String getProject() { public String getProject() {
...@@ -30,10 +29,6 @@ public enum AiInterfaceEnums { ...@@ -30,10 +29,6 @@ public enum AiInterfaceEnums {
return projectId; return projectId;
} }
public String getWaitFor() {
return waitFor;
}
public static AiInterfaceEnums create(String projectId) { public static AiInterfaceEnums create(String projectId) {
for (AiInterfaceEnums enums : AiInterfaceEnums.values()) { for (AiInterfaceEnums enums : AiInterfaceEnums.values()) {
if (enums.getProjectId().equals(projectId)) { if (enums.getProjectId().equals(projectId)) {
......
...@@ -58,7 +58,7 @@ public abstract class AbstractAiTaskService implements AiTaskService { ...@@ -58,7 +58,7 @@ public abstract class AbstractAiTaskService implements AiTaskService {
return null; return null;
} }
long endTime = System.currentTimeMillis() - now; long endTime = System.currentTimeMillis() - now;
AiApiResult aiRes = aiApiResultConversion(s); AiApiResult aiRes = aiApiResultConversion(s, aiParam);
if (Objects.isNull(aiRes)) { if (Objects.isNull(aiRes)) {
requestResIncomplete(timeKey); requestResIncomplete(timeKey);
log.info("项目:{},数据url:{},耗时:{},ai接口返回信息不完整:{}", aiInterfaceEnums.getProject(), param.getJSONObject("data").getString(GenericAttribute.URL), endTime, s); log.info("项目:{},数据url:{},耗时:{},ai接口返回信息不完整:{}", aiInterfaceEnums.getProject(), param.getJSONObject("data").getString(GenericAttribute.URL), endTime, s);
...@@ -86,7 +86,7 @@ public abstract class AbstractAiTaskService implements AiTaskService { ...@@ -86,7 +86,7 @@ public abstract class AbstractAiTaskService implements AiTaskService {
protected JSONObject aiInterfaceParamBuild(AiInterfaceParam aiParam) { protected JSONObject aiInterfaceParamBuild(AiInterfaceParam aiParam) {
JSONObject param = new JSONObject(); 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 data = new JSONObject();
JSONObject json = aiParam.getJson(); JSONObject json = aiParam.getJson();
data.put("author", json.getString(GenericAttribute.ES_SOURCE)); data.put("author", json.getString(GenericAttribute.ES_SOURCE));
...@@ -134,34 +134,37 @@ public abstract class AbstractAiTaskService implements AiTaskService { ...@@ -134,34 +134,37 @@ public abstract class AbstractAiTaskService implements AiTaskService {
} }
@Override @Override
public AiApiResult aiApiResultConversion(String interfaceRes) { public AiApiResult aiApiResultConversion(String interfaceRes, AiInterfaceParam aiParam) {
JSONObject res = JSONObject.parseObject(interfaceRes); JSONObject res = JSONObject.parseObject(interfaceRes);
if (Objects.nonNull(res)) { if (Objects.isNull(res)) {
JSONObject waitRes = res.getJSONObject(aiInterfaceEnums.getWaitFor()); return null;
if (Objects.nonNull(waitRes)) { }
JSONObject result = waitRes.getJSONObject("result"); JSONObject waitRes = res.getJSONObject(aiParam.getAiMark().getInterfaceRelation().getWaitFor());
if (Objects.nonNull(result)) { if (Objects.isNull(waitRes)) {
aiApiResultTitleSubString(result); return null;
if (waitRes.getString("status").equals("DONE") || (!StringUtils.isEmpty(result.getString("sent")) && StringUtils.isEmpty("dedup"))) { }
AiApiResult aiRes = new AiApiResult(); JSONObject result = waitRes.getJSONObject("result");
aiRes.setId(waitRes.getString("result_id")); if (Objects.isNull(result)) {
aiRes.setCreateAt(System.currentTimeMillis()); return null;
aiRes.setInfo_class(result.getString("info_class")); }
aiRes.setNoise(result.getString("denoise")); aiApiResultTitleSubString(result);
aiRes.setSent(result.getString("sent")); if (waitRes.getString("status").equals("DONE") || (!StringUtils.isEmpty(result.getString("sent")) && StringUtils.isEmpty("dedup"))) {
aiRes.setStatus(waitRes.getString("status")); AiApiResult aiRes = new AiApiResult();
aiRes.setNegLabel(result.getString("neg_label")); aiRes.setId(waitRes.getString("result_id"));
aiRes.setResult(res.toJSONString()); aiRes.setCreateAt(System.currentTimeMillis());
aiRes.setProject(aiInterfaceEnums.getProject()); aiRes.setInfo_class(result.getString("info_class"));
aiApiResultDao.insert(aiRes); aiRes.setNoise(result.getString("denoise"));
return aiRes; aiRes.setSent(result.getString("sent"));
} else { aiRes.setStatus(waitRes.getString("status"));
return aiApiResultDao.findOne(new Query(Criteria.where("_id").is(result.getString("dedup")))); 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 @Override
...@@ -215,6 +218,9 @@ public abstract class AbstractAiTaskService implements AiTaskService { ...@@ -215,6 +218,9 @@ public abstract class AbstractAiTaskService implements AiTaskService {
case "neg_label" : case "neg_label" :
relateValue = result.getNegLabel(); relateValue = result.getNegLabel();
break; break;
case "related" :
relateValue = result.getRelated();
break;
} }
return relateValue; return relateValue;
} }
......
...@@ -39,7 +39,7 @@ public interface AiTaskService { ...@@ -39,7 +39,7 @@ public interface AiTaskService {
* @param interfaceRes 接口返回值 * @param interfaceRes 接口返回值
* @return AiApiResult * @return AiApiResult
*/ */
AiApiResult aiApiResultConversion(String interfaceRes); AiApiResult aiApiResultConversion(String interfaceRes, AiInterfaceParam aiParam);
void requestMarkTotalCount(String timeKey); 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