Commit d0dac12c authored by R10's avatar R10

Merge branch 'release_gdghg' of ssh://gitlab.gsstcloud.com:10022/poc/poc-api into release_gdghg

parents d15dd3d0 139e4906
...@@ -286,26 +286,8 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -286,26 +286,8 @@ public class AiBiServiceImpl implements AiBiService {
echartJSONObject.put("sql_result", dbChainResult.getSqlResult()); echartJSONObject.put("sql_result", dbChainResult.getSqlResult());
echartJSONObject.put("question", input); echartJSONObject.put("question", input);
AbstractFunctionResult<String> functionResult = eChartGenerateFunction.doFunction(echartJSONObject.toJSONString(), null, null, null); AbstractFunctionResult<String> functionResult = eChartGenerateFunction.doFunction(echartJSONObject.toJSONString(), null, null, null);
//输出EChart String eChartOption = functionResult.getFunctionResult();
if (functionResult != null && StringUtils.isNotBlank(functionResult.getFunctionResult())) { functionRecord = outputECharts(eChartOption, sseUtil, functionRecord);
JSONObject jsonObject = JSONObject.parseObject(functionResult.getFunctionResult());
if (!jsonObject.containsKey("skip")) {
ToolFunction toolFunction = new ToolFunction();
toolFunction.setName("echart_function");
toolFunction.setResult(functionResult.getFunctionResult());
toolFunction.setDisplayFormat("json");
toolFunction.setArguments(null);
result = new LargeModelDemandResult();
result.setCode("0");
result.setFunction(toolFunction);
result.setDbChainResult(null);
result.setKnowledgeContentResult(null);
String toolFunctionJson = JsonUtils.serialize(result);
sseUtil.send(toolFunctionJson);
functionRecord = toolFunctionJson;
}
}
} }
} else if (StringUtils.isNotBlank(fileUrl)) { } else if (StringUtils.isNotBlank(fileUrl)) {
CSVChainResponse csvChainResponse = new CSVChainResponse(); CSVChainResponse csvChainResponse = new CSVChainResponse();
...@@ -313,12 +295,20 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -313,12 +295,20 @@ public class AiBiServiceImpl implements AiBiService {
csvChainResponse.setContext(null); csvChainResponse.setContext(null);
csvChainResponse.setFilePath(fileUrl); csvChainResponse.setFilePath(fileUrl);
csvChainResult = chainService.csvChain(csvChainResponse); csvChainResult = chainService.csvChain(csvChainResponse);
if (csvChainResult != null) { if (csvChainResult != null) {
String[] csvRes = JsonUtils.deSerialize(csvChainResult.getResult(), String[].class); LargeModelDemandResult result = new LargeModelDemandResult();
if (ArrayUtils.isNotEmpty(csvRes)) { result.setCode("0");
result.setFunction(null);
result.setDbChainResult(null);
result.setKnowledgeContentResult(null);
result.setCsvChainResult(csvChainResult);
sseUtil.send(JsonUtils.serialize(result));
if (StringUtils.isNotBlank(csvChainResult.getResult())) {
JSONObject echartJSONObject = new JSONObject(); JSONObject echartJSONObject = new JSONObject();
echartJSONObject.put("sql", null); echartJSONObject.put("sql", StringUtils.EMPTY);
echartJSONObject.put("sql_result", csvRes.toString()); echartJSONObject.put("sql_result", csvChainResult.getResult());
echartJSONObject.put("question", input); echartJSONObject.put("question", input);
AbstractFunctionResult<String> functionResult = eChartGenerateFunction.doFunction(echartJSONObject.toJSONString(), null, null, null); AbstractFunctionResult<String> functionResult = eChartGenerateFunction.doFunction(echartJSONObject.toJSONString(), null, null, null);
String eChartOption = functionResult.getFunctionResult(); String eChartOption = functionResult.getFunctionResult();
...@@ -367,9 +357,9 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -367,9 +357,9 @@ public class AiBiServiceImpl implements AiBiService {
} }
private String outputECharts(String eChartOption, SSEUtil sseUtil, String functionRecord) throws IOException { private String outputECharts(String eChartOption, SSEUtil sseUtil, String functionRecord) throws IOException {
//输出EChart //输出EChart
if (eChartOption != null) { if (eChartOption != null && StringUtils.isNotBlank(eChartOption)) {
JSONObject jsonObject = JSONObject.parseObject(eChartOption); JSONObject jsonObject = JSONObject.parseObject(eChartOption);
if (!jsonObject.containsKey("skip")) { if (!jsonObject.containsKey("skip")) {
ToolFunction toolFunction = new ToolFunction(); ToolFunction toolFunction = new ToolFunction();
......
package cn.com.poc.ai_dialogues.aggregate.impl; package cn.com.poc.ai_dialogues.aggregate.impl;
import cn.com.poc.agent_application.aggregate.AgentApplicationService;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
import cn.com.poc.agent_application.query.AgentApplicationDialoguesRecordQueryItem; import cn.com.poc.agent_application.query.AgentApplicationDialoguesRecordQueryItem;
import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService; import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService;
...@@ -16,7 +17,9 @@ import cn.com.poc.ai_dialogues.service.BizAiDialoguesGuessYouAskService; ...@@ -16,7 +17,9 @@ import cn.com.poc.ai_dialogues.service.BizAiDialoguesGuessYouAskService;
import cn.com.poc.ai_dialogues.service.BizAiDialoguesProblemAssociationService; import cn.com.poc.ai_dialogues.service.BizAiDialoguesProblemAssociationService;
import cn.com.poc.ai_dialogues.service.BizAiDialoguesService; import cn.com.poc.ai_dialogues.service.BizAiDialoguesService;
import cn.com.poc.common.constant.CommonConstant; import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.constant.XLangConstant;
import cn.com.poc.common.service.BizFileUploadRecordService; import cn.com.poc.common.service.BizFileUploadRecordService;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.common.utils.StringUtils; import cn.com.poc.common.utils.StringUtils;
import cn.com.poc.expose.dto.DialoguesContextDto; import cn.com.poc.expose.dto.DialoguesContextDto;
...@@ -34,10 +37,8 @@ import org.slf4j.LoggerFactory; ...@@ -34,10 +37,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.security.SecureRandom;
import java.util.Collections; import java.util.*;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -70,6 +71,9 @@ public class AiDialoguesServiceImpl implements AiDialoguesService { ...@@ -70,6 +71,9 @@ public class AiDialoguesServiceImpl implements AiDialoguesService {
@Resource @Resource
private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService; private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService;
@Resource
private RedisService redisService;
@Override @Override
public String create(AiDialoguesTypeEnum type, Long userId) throws Exception { public String create(AiDialoguesTypeEnum type, Long userId) throws Exception {
return bizAiDialoguesService.create(type.getType(), userId); return bizAiDialoguesService.create(type.getType(), userId);
...@@ -232,15 +236,33 @@ public class AiDialoguesServiceImpl implements AiDialoguesService { ...@@ -232,15 +236,33 @@ public class AiDialoguesServiceImpl implements AiDialoguesService {
@Override @Override
public List<String> guessYouAsk(String type) throws Exception { public List<String> guessYouAsk(String type) throws Exception {
List<BizAiDialoguesGuessYouAskEntity> entities = bizAiDialoguesGuessYouAskService.findByExample(new BizAiDialoguesGuessYouAskEntity(), null); //
// 新增随机逻辑 String redisKey = "AGENT_APPLICATION_RECOMMEND_QUESTIONS:" + XLangConstant.ZH_CN;
if (CollectionUtils.isNotEmpty(entities)) {
Collections.shuffle(entities); // 打乱顺序 long size = redisService.lGetListSize(redisKey);
return entities.stream() if (size < 8) {
.limit(8) // 取前八个 redisService.del(redisKey);
.map(BizAiDialoguesGuessYouAskEntity::getQuestion) return Collections.emptyList();
.collect(Collectors.toList());
} }
return Collections.emptyList();
List<Object> lastRecomendIdSet = null;
Set<Long> indexSet = new HashSet<>(8);
SecureRandom secureRandom = new SecureRandom();
do {
long id = secureRandom.nextInt((int) size);
if (CollectionUtils.isNotEmpty(lastRecomendIdSet) && lastRecomendIdSet.stream().anyMatch(v -> String.valueOf(v).equals(String.valueOf(id)))) {
continue;
}
indexSet.add(id);
} while (indexSet.size() < 8);
List<String> result = new ArrayList<>(8);
for (Long index : indexSet) {
Object str = redisService.lGetIndex(redisKey, index);
result.add(str.toString());
}
return result;
} }
} }
...@@ -85,6 +85,7 @@ public class BizKnowledgeDatabaseConvert { ...@@ -85,6 +85,7 @@ public class BizKnowledgeDatabaseConvert {
BizKnowledgeDatabaseDto bizKnowledgeDatabaseDto = new BizKnowledgeDatabaseDto(); BizKnowledgeDatabaseDto bizKnowledgeDatabaseDto = new BizKnowledgeDatabaseDto();
bizKnowledgeDatabaseDto.setId(item.getId()); bizKnowledgeDatabaseDto.setId(item.getId());
bizKnowledgeDatabaseDto.setMemberId(item.getMemberId()); bizKnowledgeDatabaseDto.setMemberId(item.getMemberId());
bizKnowledgeDatabaseDto.setExample(item.getMemberId() == 0);
bizKnowledgeDatabaseDto.setTitle(item.getTitle()); bizKnowledgeDatabaseDto.setTitle(item.getTitle());
bizKnowledgeDatabaseDto.setDesc(item.getDbDesc()); bizKnowledgeDatabaseDto.setDesc(item.getDbDesc());
bizKnowledgeDatabaseDto.setDbType(item.getDbType()); bizKnowledgeDatabaseDto.setDbType(item.getDbType());
......
...@@ -23,6 +23,19 @@ public class BizKnowledgeDatabaseDto { ...@@ -23,6 +23,19 @@ public class BizKnowledgeDatabaseDto {
this.id = id; this.id = id;
} }
/**
* 是否为示例 true-示例 ,false-非示例
*/
private boolean example;
public boolean getExample() {
return example;
}
public void setExample(boolean example) {
this.example = example;
}
/** /**
* member_id * member_id
* 用户ID * 用户ID
......
SELECT id, member_id, title, db_desc, db_type, db_host, db_port, db_name, db_username, db_password, is_deleted, CREATOR, CREATED_TIME, MODIFIER, MODIFIED_TIME, SYS_VERSION FROM biz_knowledge_database SELECT id,
where is_deleted = 'N' member_id,
<<and member_id = :memberId>> title,
db_desc,
db_type,
db_host,
db_port,
db_name,
db_username,
db_password,
is_deleted,
CREATOR,
CREATED_TIME,
MODIFIER,
MODIFIED_TIME,
SYS_VERSION
FROM biz_knowledge_database
where is_deleted = 'N' and (member_id = 0 <<or member_id = :memberId>>)
<<and LOCATE(:search ,title)>> <<and LOCATE(:search ,title)>>
order by MODIFIED_TIME desc order by member_id, MODIFIED_TIME desc
\ No newline at end of file \ No newline at end of file
...@@ -80,7 +80,7 @@ public class DatabaseRestImpl implements DatabaseRest { ...@@ -80,7 +80,7 @@ public class DatabaseRestImpl implements DatabaseRest {
Long userId = userBaseEntity.getUserId(); Long userId = userBaseEntity.getUserId();
BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(id.longValue()); BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(id.longValue());
if (bizKnowledgeDatabaseEntity == null || !bizKnowledgeDatabaseEntity.getMemberId().equals(userId.intValue())) { if (bizKnowledgeDatabaseEntity == null || (!bizKnowledgeDatabaseEntity.getMemberId().equals(0) && !bizKnowledgeDatabaseEntity.getMemberId().equals(userId.intValue()))) {
throw new BusinessException("no database found"); throw new BusinessException("no database found");
} }
BizKnowledgeDatabaseDto bizKnowledgeDatabaseDto = BizKnowledgeDatabaseConvert.entityToDto(bizKnowledgeDatabaseEntity); BizKnowledgeDatabaseDto bizKnowledgeDatabaseDto = BizKnowledgeDatabaseConvert.entityToDto(bizKnowledgeDatabaseEntity);
...@@ -108,7 +108,8 @@ public class DatabaseRestImpl implements DatabaseRest { ...@@ -108,7 +108,8 @@ public class DatabaseRestImpl implements DatabaseRest {
List<BizKnowledgeDatabaseDto> result = new ArrayList<>(); List<BizKnowledgeDatabaseDto> result = new ArrayList<>();
for (Integer id : ids) { for (Integer id : ids) {
BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(id.longValue()); BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(id.longValue());
if (bizKnowledgeDatabaseEntity == null || !bizKnowledgeDatabaseEntity.getMemberId().equals(userId.intValue())) { if (bizKnowledgeDatabaseEntity == null || (!bizKnowledgeDatabaseEntity.getMemberId().equals(0)
&& !bizKnowledgeDatabaseEntity.getMemberId().equals(userId.intValue()))) {
continue; continue;
} }
BizKnowledgeDatabaseDto bizKnowledgeDatabaseDto = BizKnowledgeDatabaseConvert.entityToDto(bizKnowledgeDatabaseEntity); BizKnowledgeDatabaseDto bizKnowledgeDatabaseDto = BizKnowledgeDatabaseConvert.entityToDto(bizKnowledgeDatabaseEntity);
...@@ -235,13 +236,13 @@ public class DatabaseRestImpl implements DatabaseRest { ...@@ -235,13 +236,13 @@ public class DatabaseRestImpl implements DatabaseRest {
} }
@Override @Override
public DatabaseTableDataDto getTableData( DatabaseTableDataResponseDto dto, PagingInfo pagingInfo) { public DatabaseTableDataDto getTableData(DatabaseTableDataResponseDto dto, PagingInfo pagingInfo) {
Assert.notNull(dto.getId(), "id can not be null"); Assert.notNull(dto.getId(), "id can not be null");
Assert.notNull(dto.getTable(), "table can not be null"); Assert.notNull(dto.getTable(), "table can not be null");
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException(); UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
Long userId = userBaseEntity.getUserId(); Long userId = userBaseEntity.getUserId();
BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(dto.getId().longValue()); BizKnowledgeDatabaseEntity bizKnowledgeDatabaseEntity = bizKnowledgeDatabaseService.get(dto.getId().longValue());
if (bizKnowledgeDatabaseEntity == null || !bizKnowledgeDatabaseEntity.getMemberId().equals(userId.intValue())) { if (bizKnowledgeDatabaseEntity == null || (!bizKnowledgeDatabaseEntity.getMemberId().equals(0) && !bizKnowledgeDatabaseEntity.getMemberId().equals(userId.intValue()))) {
throw new BusinessException("no database found"); throw new BusinessException("no database found");
} }
......
package cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel; package cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel;
import cn.com.poc.agent_application.entity.KnowledgeContentResult; import cn.com.poc.agent_application.entity.KnowledgeContentResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.csvchain.CSVChainResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult; import cn.com.poc.thirdparty.resource.demand.ai.entity.dbchain.DBChainResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.ToolFunction; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.ToolFunction;
import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Usage; import cn.com.poc.thirdparty.resource.demand.ai.entity.dialogue.Usage;
...@@ -19,6 +20,8 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab ...@@ -19,6 +20,8 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab
private ToolFunction function; private ToolFunction function;
private CSVChainResult csvChainResult;
private List<DBChainResult> dbChainResult; private List<DBChainResult> dbChainResult;
private List<KnowledgeContentResult> knowledgeContentResult; private List<KnowledgeContentResult> knowledgeContentResult;
...@@ -43,6 +46,14 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab ...@@ -43,6 +46,14 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab
this.knowledgeContentResult = knowledgeContentResult; this.knowledgeContentResult = knowledgeContentResult;
} }
public CSVChainResult getCsvChainResult() {
return csvChainResult;
}
public void setCsvChainResult(CSVChainResult csvChainResult) {
this.csvChainResult = csvChainResult;
}
public String getCode() { public String getCode() {
return code; return code;
} }
......
...@@ -82,9 +82,9 @@ public class ASRApi { ...@@ -82,9 +82,9 @@ public class ASRApi {
public GetDetailResult getDetail(String sessionId) { public GetDetailResult getDetail(String sessionId) {
Assert.notBlank(sessionId); Assert.notBlank(sessionId);
HttpUriRequest httpUriRequest = RequestBuilder.post() HttpUriRequest httpUriRequest = RequestBuilder.post()
.setUri(ENDPOINT + GET_DETAIL_API) .setUri(ENDPOINT + GET_DETAIL_API + "?sessionId=" + sessionId)
// .addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())) // .addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()))
.addParameter("sessionId", sessionId) // .addParameter("sessionId", sessionId)
.build(); .build();
return LocalHttpClient.executeJsonResult(httpUriRequest, GetDetailResult.class); return LocalHttpClient.executeJsonResult(httpUriRequest, GetDetailResult.class);
} }
......
...@@ -23,10 +23,6 @@ public class ChainServiceImpl implements ChainService { ...@@ -23,10 +23,6 @@ public class ChainServiceImpl implements ChainService {
private Logger logger = LoggerFactory.getLogger(ChainServiceImpl.class); private Logger logger = LoggerFactory.getLogger(ChainServiceImpl.class);
@Value(value = "${large-model.apikey}")
private String API_KEY;
@Resource @Resource
private AIDialogueService aiDialogueService; private AIDialogueService aiDialogueService;
...@@ -53,17 +49,21 @@ public class ChainServiceImpl implements ChainService { ...@@ -53,17 +49,21 @@ public class ChainServiceImpl implements ChainService {
@Override @Override
public CSVChainResult csvChain(CSVChainResponse response) { public CSVChainResult csvChain(CSVChainResponse response) {
logger.info("csvChain response : {}", response); logger.info("csvChain response : {}", response);
response.setApiKey(API_KEY); try {
CSVChainResult csvChainResult = aiDialogueService.csvChain(response); CSVChainResult csvChainResult = aiDialogueService.csvChain(response);
if (csvChainResult == null || csvChainResult.getStatus().equals("error")) { if (csvChainResult == null || csvChainResult.getStatus().equals("error")) {
logger.error("csvChain result error : {} , response:{}", csvChainResult, response); logger.error("csvChain result error : {} , response:{}", csvChainResult, response);
return null; return null;
} }
if (StringUtils.isBlank(csvChainResult.getResult())) { if (StringUtils.isBlank(csvChainResult.getResult())) {
logger.warn("csvChain result sqlResult is blank : {} , response:{}", csvChainResult, response); logger.warn("csvChain result sqlResult is blank : {} , response:{}", csvChainResult, response);
return null;
}
return csvChainResult;
} catch (Exception e) {
logger.error("csv chain error:{}", e.getMessage());
return null; return null;
} }
return csvChainResult;
} }
} }
...@@ -33,7 +33,7 @@ public class ASRTest { ...@@ -33,7 +33,7 @@ public class ASRTest {
@Test @Test
public void test_asrGetDetail() { public void test_asrGetDetail() {
String sessionId = "meeting_assistant_c9c7021dd0db4ecda6bf7eb3a325e745_4"; String sessionId = "a9ee310bb9754a089cf64429b9e42ea5";
AsrOfflineDetailResult asrServiceDetail = asrService.getDetail(sessionId); AsrOfflineDetailResult asrServiceDetail = asrService.getDetail(sessionId);
System.out.println(JsonUtils.serialize(asrServiceDetail)); System.out.println(JsonUtils.serialize(asrServiceDetail));
} }
......
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