代码功能bug修复

优化问答功能
v_0.0.2
xueqingkun 1 week ago
parent 0bbb27343f
commit 0f7d3f2e76

@ -220,7 +220,7 @@ public class PromptCache {
} }
{} {}/no_think
"""; """;
private static final String DOERE_TABLE_PROMPT = """ private static final String DOERE_TABLE_PROMPT = """
@ -270,7 +270,7 @@ public class PromptCache {
} }
{} {}/no_think
"""; """;
private static final String TEXT_TO_CYPHER_PROMPT = """ private static final String TEXT_TO_CYPHER_PROMPT = """
@ -316,7 +316,7 @@ public class PromptCache {
{query} {query}
Cypher Cypher/no_think
"""; """;
private static final String GENERATE_ANSWER_PROMPT = """ private static final String GENERATE_ANSWER_PROMPT = """
@ -358,7 +358,7 @@ public class PromptCache {
5. **** 5. ****
- 使``````Markdown - 使``````Markdown
- - /no_think
"""; """;
@ -398,7 +398,7 @@ public class PromptCache {
2. 使```Person` 2. 使```Person`
3. MERGE 3. MERGE
### ###
{} {}/no_think
"""; """;
private static final String CLASSIFY_TABLE_PROMPT = """ private static final String CLASSIFY_TABLE_PROMPT = """
@ -440,7 +440,7 @@ public class PromptCache {
{} {}/no_think
"""; """;
private static final String EXTRACT_TABLE_TITLE_PROMPT = """ private static final String EXTRACT_TABLE_TITLE_PROMPT = """
@ -454,7 +454,7 @@ public class PromptCache {
- -
**** ****
{} {}/no_think
"""; """;
@ -535,10 +535,7 @@ public class PromptCache {
2. 2.
- `{"ContentType": 0/1/2}` - `{"ContentType": 0/1/2}`
- `{}` - `{}`/no_think
./no_think
"""; """;
private static final String CLASSIFY_INDUSTRY_PROMPT = """ private static final String CLASSIFY_INDUSTRY_PROMPT = """
@ -548,10 +545,7 @@ public class PromptCache {
### ###
```
{text} {text}
```
### ###
@ -566,12 +560,9 @@ public class PromptCache {
### ###
```
{ {
industryCategory: industryCategory:
} }/no_think
```
"""; """;
private static final String CLASSIFY_INTENT_PROMPT = """ private static final String CLASSIFY_INTENT_PROMPT = """
@ -607,9 +598,10 @@ public class PromptCache {
{ {
"IntentTypeList": [] "IntentTypeList": []
} }/no_think
"""; """;
// 需要大模型进行思考
private static final String CLASSIFY_INTENT_TRAIN_PROMPT = """ private static final String CLASSIFY_INTENT_TRAIN_PROMPT = """
# #
@ -688,7 +680,7 @@ public class PromptCache {
... ...
], ],
"意图2": ... "意图2": ...
} }/no_think
"""; """;
private static final String EXTRACT_ERE_BASE_INTENT_PROMPT = """ private static final String EXTRACT_ERE_BASE_INTENT_PROMPT = """
@ -751,7 +743,7 @@ public class PromptCache {
} }
} }
] ]
} }/no_think
"""; """;
@ -776,7 +768,7 @@ public class PromptCache {
["意图1" "意图2" "意图3", ...] ["意图1" "意图2" "意图3", ...]
## ##
{query} {query}/no_think
"""; """;
@ -814,6 +806,6 @@ public class PromptCache {
5. Cypher 5. Cypher
- Cypher - Cypher
- 使OPTIONAL MATCH - 使OPTIONAL MATCH
- RETURN使 - RETURN使/no_think
"""; """;
} }

@ -30,12 +30,12 @@ public class OllamaChatModelAspect {
// 获取原始参数 // 获取原始参数
Object[] args = joinPoint.getArgs(); Object[] args = joinPoint.getArgs();
// 如果是String类型的call方法修改其参数 // 如果是String类型的call方法修改其参数
if (StrUtil.equals(signature, callStringMessage) && args.length > 0) { /*if (StrUtil.equals(signature, callStringMessage) && args.length > 0) {
args[0] = args[0] + "\n /no_think"; args[0] = args[0] + "\n /no_think";
} }*/
// 执行原方法 // 执行原方法
Object result = joinPoint.proceed(args); Object result = joinPoint.proceed(args);
if (StrUtil.equals(model,"qwen3:30b-a3b") ) { if (StrUtil.equals(model,"qwen3:30b-a3b")|| StrUtil.equals(model,"qwen3:32b")) {
if(StrUtil.equals(signature, callStringMessage)){ if(StrUtil.equals(signature, callStringMessage)){
result = ((String) result).replaceAll("(?is)<think\\b[^>]*>(.*?)</think>", "").trim(); result = ((String) result).replaceAll("(?is)<think\\b[^>]*>(.*?)</think>", "").trim();
} }

@ -95,4 +95,42 @@ public class DomainMetadataDTO {
} }
} }
/**
* ....
* @param erAttributes erAttributes
* @param domainMetadata domainMetadata
*/
public DomainMetadataDTO(List<ErAttribute> erAttributes,DomainMetadata domainMetadata) {
this.id = domainMetadata.getId();
this.domainCategoryId = domainMetadata.getDomainCategoryId();
this.sourceType = domainMetadata.getSourceType();
this.relation = domainMetadata.getRelation();
this.targetType = domainMetadata.getTargetType();
this.generationType = domainMetadata.getGenerationType();
for (ErAttribute erAttribute : erAttributes) {
if(StrUtil.equals(erAttribute.getErType(),"1")){
// 节点数据
if (StrUtil.equals(erAttribute.getErLabel(),this.sourceType)) {
boolean none = this.sourceAttributes.stream().noneMatch(item -> StrUtil.equals(item.getAttrName(), erAttribute.getAttrName()));
if (none){
this.sourceAttributes.add(new ERAttributeDTO(erAttribute));
}
}
if (StrUtil.equals(erAttribute.getErLabel(),this.targetType)) {
boolean none = this.targetAttributes.stream().noneMatch(item -> StrUtil.equals(item.getAttrName(), erAttribute.getAttrName()));
if (none){
this.targetAttributes.add(new ERAttributeDTO(erAttribute));
}
}
}else {
if (StrUtil.equals(erAttribute.getErLabel(),this.relation)) {
if (this.relationAttributes.stream().noneMatch(item -> StrUtil.equals(item.getAttrName(), erAttribute.getAttrName()))){
this.relationAttributes.add(new ERAttributeDTO(erAttribute));
}
}
}
}
}
} }

@ -2,6 +2,8 @@ package com.supervision.pdfqaserver.mapper;
import com.supervision.pdfqaserver.domain.ErAttribute; import com.supervision.pdfqaserver.domain.ErAttribute;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @author Administrator * @author Administrator
@ -11,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/ */
public interface ErAttributeMapper extends BaseMapper<ErAttribute> { public interface ErAttributeMapper extends BaseMapper<ErAttribute> {
List<ErAttribute> listByDomainCategoryId(@Param("domainCategoryId") String domainCategoryId);
} }

@ -52,4 +52,12 @@ public interface DomainMetadataService extends IService<DomainMetadata> {
* @return * @return
*/ */
List<DomainMetadataDTO> listByIntentionIds(List<String> intentionIds); List<DomainMetadataDTO> listByIntentionIds(List<String> intentionIds);
/**
* IDID
* @param intentionIds ID
* @param domainCategoryId ID
* @return
*/
List<DomainMetadataDTO> listByIntentionIds(List<String> intentionIds,String domainCategoryId);
} }

@ -18,4 +18,6 @@ public interface ErAttributeService extends IService<ErAttribute> {
List<ErAttribute> listByDomainMetadataId(String domainMetadataId); List<ErAttribute> listByDomainMetadataId(String domainMetadataId);
List<ErAttribute> listByDomainMetadataIds(List<String> domainMetadataIds); List<ErAttribute> listByDomainMetadataIds(List<String> domainMetadataIds);
List<ErAttribute> listByDomainCategoryId(String domainCategoryId);
} }

@ -147,10 +147,28 @@ public class DomainMetadataServiceImpl extends ServiceImpl<DomainMetadataMapper,
List<ErAttribute> erAttributes = erAttributeService.listByDomainMetadataIds(domainMetadataIds); List<ErAttribute> erAttributes = erAttributeService.listByDomainMetadataIds(domainMetadataIds);
for (IntentionDomainMetadata intentionDomainMetadata : intentionDomainMetadataList) { for (IntentionDomainMetadata intentionDomainMetadata : intentionDomainMetadataList) {
DomainMetadata domainMetadata = this.getById(intentionDomainMetadata.getDomainMetadataId()); DomainMetadata domainMetadata = this.getById(intentionDomainMetadata.getDomainMetadataId());
// 要求合并全局属性
domainMetadataDTOS.add(new DomainMetadataDTO(domainMetadata, erAttributes)); domainMetadataDTOS.add(new DomainMetadataDTO(domainMetadata, erAttributes));
} }
return domainMetadataDTOS; return domainMetadataDTOS;
} }
@Override
public List<DomainMetadataDTO> listByIntentionIds(List<String> intentionIds, String domainCategoryId) {
List<DomainMetadataDTO> domainMetadataDTOS = new ArrayList<>();
List<IntentionDomainMetadata> intentionDomainMetadataList = intentionDomainMetadataService.listByIntentionIds(intentionIds);
if (CollUtil.isEmpty(intentionDomainMetadataList)){
return domainMetadataDTOS;
}
// 查询domainCategoryId下的所有属性
List<ErAttribute> erAttributes = erAttributeService.listByDomainCategoryId(domainCategoryId);
for (IntentionDomainMetadata intentionDomainMetadata : intentionDomainMetadataList) {
DomainMetadata domainMetadata = this.getById(intentionDomainMetadata.getDomainMetadataId());
// 要求合并全局属性
domainMetadataDTOS.add(new DomainMetadataDTO(erAttributes,domainMetadata));
}
return domainMetadataDTOS;
}
} }

@ -9,6 +9,7 @@ import com.supervision.pdfqaserver.service.ErAttributeService;
import com.supervision.pdfqaserver.mapper.ErAttributeMapper; import com.supervision.pdfqaserver.mapper.ErAttributeMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -47,6 +48,14 @@ public class ErAttributeServiceImpl extends ServiceImpl<ErAttributeMapper, ErAtt
} }
return this.lambdaQuery().in(ErAttribute::getDomainMetadataId, domainMetadataIds).list(); return this.lambdaQuery().in(ErAttribute::getDomainMetadataId, domainMetadataIds).list();
} }
@Override
public List<ErAttribute> listByDomainCategoryId(String domainCategoryId) {
if (StrUtil.isEmpty(domainCategoryId)){
return new ArrayList<>();
}
return super.getBaseMapper().listByDomainCategoryId(domainCategoryId);
}
} }

@ -116,7 +116,7 @@ public class TripleConversionPipelineImpl implements TripleConversionPipeline {
log.info("makeOutDomainMetadata:format{}", format); log.info("makeOutDomainMetadata:format{}", format);
String call = aiCallService.call(format); String call = aiCallService.call(format);
log.info("makeOutDomainMetadata:响应结果:{}", call); log.info("makeOutDomainMetadata:响应结果:{}", call);
return parseDomainMetadata(call); return parseDomainMetadataObj(call);
} }
/** /**
@ -186,6 +186,59 @@ public class TripleConversionPipelineImpl implements TripleConversionPipeline {
return domainMetadataDTOS; return domainMetadataDTOS;
} }
private List<DomainMetadataDTO> parseDomainMetadataObj(String jsonStr) {
JSONObject entries = JSONUtil.parseObj(jsonStr);
List<DomainMetadataDTO> domainMetadataDTOS = new ArrayList<>();
for (Map.Entry<String, Object> entry : entries) {
String intent = entry.getKey();// 意图
Object value = entry.getValue();
JSONArray jsonArray = JSONUtil.parseArray(value);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
DomainMetadataDTO domainMetadataDTO = new DomainMetadataDTO();
JSONObject source = jsonObject.getJSONObject("source");
JSONObject relation = jsonObject.getJSONObject("relation");
JSONObject target = jsonObject.getJSONObject("target");
domainMetadataDTO.setIntentDigest(intent);
if (null != source){
String type = source.getStr("type");
JSONArray attributes = source.getJSONArray("attributes");
if (StrUtil.isNotEmpty(type)){
domainMetadataDTO.setSourceType(type);
}
if (CollUtil.isNotEmpty(attributes)){
List<ERAttributeDTO> erAttributeDTOS = attributes.stream().map(at -> new ERAttributeDTO(at.toString())).collect(Collectors.toList());
domainMetadataDTO.setSourceAttributes(erAttributeDTOS);
}
}
if (null != relation){
String type = relation.getStr("type");
JSONArray attributes = relation.getJSONArray("attributes");
if (StrUtil.isNotEmpty(type)){
domainMetadataDTO.setRelation(type);
}
if (CollUtil.isNotEmpty(attributes)){
List<ERAttributeDTO> erAttributeDTOS = attributes.stream().map(at -> new ERAttributeDTO(at.toString())).collect(Collectors.toList());
domainMetadataDTO.setRelationAttributes(erAttributeDTOS);
}
}
if (null != target){
String type = target.getStr("type");
JSONArray attributes = target.getJSONArray("attributes");
if (StrUtil.isNotEmpty(type)){
domainMetadataDTO.setTargetType(type);
}
if (CollUtil.isNotEmpty(attributes)){
List<ERAttributeDTO> erAttributeDTOS = attributes.stream().map(at -> new ERAttributeDTO(at.toString())).collect(Collectors.toList());
domainMetadataDTO.setTargetAttributes(erAttributeDTOS);
}
}
domainMetadataDTOS.add(domainMetadataDTO);
}
}
return domainMetadataDTOS;
}
@Override @Override
public EREDTO doEre(TruncateDTO truncateDTO, List<IntentDTO> intents) { public EREDTO doEre(TruncateDTO truncateDTO, List<IntentDTO> intents) {
if (StrUtil.equals(truncateDTO.getLayoutType(),String.valueOf(LayoutTypeEnum.TEXT.getCode()))){ if (StrUtil.equals(truncateDTO.getLayoutType(),String.valueOf(LayoutTypeEnum.TEXT.getCode()))){
@ -197,7 +250,7 @@ public class TripleConversionPipelineImpl implements TripleConversionPipeline {
if (CollUtil.isEmpty(intentIds)) { if (CollUtil.isEmpty(intentIds)) {
return null; return null;
} }
List<DomainMetadataDTO> domainMetadataDTOS = domainMetadataService.listByIntentionIds(intentIds); List<DomainMetadataDTO> domainMetadataDTOS = domainMetadataService.listByIntentionIds(intentIds,CollUtil.getFirst(intents).getDomainCategoryId());
log.info("doEre:领域元数据列表个数:{}", domainMetadataDTOS.size()); log.info("doEre:领域元数据列表个数:{}", domainMetadataDTOS.size());
domainMetadataDTOS = domainMetadataDTOS.stream() domainMetadataDTOS = domainMetadataDTOS.stream()
.filter(domainMetadataDTO -> StrUtil.equals(domainMetadataDTO.getGenerationType(), "0"))// 过滤出手动确认的数据 .filter(domainMetadataDTO -> StrUtil.equals(domainMetadataDTO.getGenerationType(), "0"))// 过滤出手动确认的数据

@ -251,9 +251,9 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
List<List<Intention>> intentionSplit = CollUtil.split(intentions, 200); List<List<Intention>> intentionSplit = CollUtil.split(intentions, 200);
for (List<Intention> intentionList : intentionSplit) { for (List<Intention> intentionList : intentionSplit) {
log.info("分类意图query: {}, intentions size: {}", query, intentionList.size()); log.info("分类意图query: {}, intentions size: {}", query, intentionList.size());
String intents = intentionList.stream().map(i -> " - " + i.getDigest() + "\n").collect(Collectors.joining()); List<String> intents = intentionList.stream().map(Intention::getDigest).toList();
Map<String, Object> params = Map.of("query", query, Map<String, Object> params = Map.of("query", query,
"intents", intents); "intents", JSONUtil.toJsonStr(intents));
String format = StrUtil.format(prompt, params); String format = StrUtil.format(prompt, params);
String call = aiCallService.call(format); String call = aiCallService.call(format);

@ -20,4 +20,12 @@
attr_name,attr_value_type,er_type, attr_name,attr_value_type,er_type,
create_time,update_time create_time,update_time
</sql> </sql>
<select id="listByDomainCategoryId" resultType="com.supervision.pdfqaserver.domain.ErAttribute">
select er.*
from domain_metadata dm
join er_attribute er on dm.id = er.domain_metadata_id
where dm.generation_type = '0'
and dm.domain_category_id = #{domainCategoryId}
and er.er_label is not null
</select>
</mapper> </mapper>

@ -3,7 +3,6 @@ package com.supervision.pdfqaserver;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.supervision.pdfqaserver.constant.DocumentContentTypeEnum; import com.supervision.pdfqaserver.constant.DocumentContentTypeEnum;
import com.supervision.pdfqaserver.domain.PdfAnalysisOutput; import com.supervision.pdfqaserver.domain.PdfAnalysisOutput;
import com.supervision.pdfqaserver.dto.*; import com.supervision.pdfqaserver.dto.*;
@ -289,7 +288,11 @@ class PdfQaServerApplicationTests {
} }
return jsa.toString(); return jsa.toString();
}
@Test
public void domainCategoryListTest() {
List<DomainMetadataDTO> domainMetadataDTOS = domainMetadataService.listByIntentionIds(List.of("1928020787140612097"), "1");
System.out.println(domainMetadataDTOS);
} }
} }

Loading…
Cancel
Save