提示词优化

v_0.0.2
daixiaoyi 2 weeks ago
parent ad3135ef90
commit 13616f1878

@ -53,7 +53,7 @@ public class PromptCache {
*/ */
public static final String CLASSIFY_CONTENT_TYPE = "CLASSIFY_CONTENT_TYPE"; public static final String CLASSIFY_CONTENT_TYPE = "CLASSIFY_CONTENT_TYPE";
//------
/** /**
* *
*/ */
@ -576,276 +576,241 @@ public class PromptCache {
private static final String CLASSIFY_INTENT_PROMPT = """ private static final String CLASSIFY_INTENT_PROMPT = """
# #
## ##
## ##
{IntentType} {IntentType}
## ##
1. 1.
2. 2.
3. 3.
4. JSON使```json ```Markdown 4. JSON使```json ```Markdown
## ##
{text} {text}
## ##
```json // 示例1匹配多个意图
// 示例1匹配单个意图
{ 2023...
"text": "本公司注册地址为上海市浦东新区张江高科技园区"
}
{ {
"IntentTypeList": ["公司地址"] "IntentTypeList": ["公司基本情况介绍", "财务报告"]
} }
// 示例2匹配多个意图 // 示例2匹配意图
{
"text": "2023年度财务报告显示公司总部位于北京全年营收..."
}
{ {
"IntentTypeList": ["公司地址", "公司年度报告"] "IntentTypeList": []
}
// 示例3无匹配意图
{
"text": "今天的天气很适合户外活动"
} }
{}
"""; """;
private static final String CLASSIFY_INTENT_TRAIN_PROMPT = """ private static final String CLASSIFY_INTENT_TRAIN_PROMPT = """
# #
## ##
PDF PDF
## ##
{text} {text}
## ##
```json // 示例1
// 示例1
2023...
{
"text": "..." {
} "IntentTypeList": ["意图1", "意图2", "意图3", ...]
}
{
"IntentTypeList": ["...", "..."] // 示例2文本意图无法识别
}
// 示例2文本意图无法识别
{
{ "IntentTypeList": []
"text": "人生短短几个球" }
}
##
{}
``` 1. JSON
2. JSON使```json ```Markdown
## 3.
4. 使......
1. JSON """;
2. JSON使```json ```Markdown
3.
{"IntentTypeList": ["...", "..."]}
-
x {}
3.使......
./no_think
""";
private static final String EXTRACT_INTENT_METADATA_PROMPT = """ private static final String EXTRACT_INTENT_METADATA_PROMPT = """
# #
## ##
JSON JSON
## ##
- -
{text} {text}
- -
{IntentTypeList} {IntentTypeList}
## ##
1. 1.
2. 2.
3. / 3. /
- type - type
- attributes - attributes
4. JSON使```json ```Markdown 4. JSON使```json ```Markdown
5. 使 5. /"公司""收购"
6. "名称""数量"
[
{ ##
"source": { {
"type": "实体类型1", "意图1": [
"attributes": ["属性类型1", "属性类型2",....] {
}, "source": {
"relation": { "type": "实体类型1",
"type": "关系类型", "attributes": ["属性类型1", "属性类型2",....]
"attributes": ["属性类型3"...] },
}, "relation": {
"target": { "type": "关系类型",
"type": "实体类型2", "attributes": ["属性类型3"...]
"attributes": ["属性类型4"...] },
}, "target": {
"intent": "匹配的意图标签" "type": "实体类型2",
}, "attributes": ["属性类型4"...]
{.....} }
] },
...
5. ./no_think ],
"意图2": ...
}
"""; """;
private static final String EXTRACT_ERE_BASE_INTENT_PROMPT = """ private static final String EXTRACT_ERE_BASE_INTENT_PROMPT = """
# #
## ##
JSON
## ##
-
{text} {text}
- -
{domainMetadata} {domainMetadata}
##
1. JSON使```json ```Markdown
2. relationssourcetargetnodesname
3. ``
4.
5.
## ##
{ {
"nodes": [ "nodes": [
{ {
"name":"龙源(酒泉)风力发电有限公司", "name":"龙源电力集团股份有限公司",
"type": "公司", "type": "公司",
"attributes": { "attributes": {
"地址": "雨花台区" "办公地址": "XXX"
} }
}, },
{ {
"name":"2024年电子银行承兑汇票", "name":"XXX公司债券",
"type": "电子银行承兑汇票", "type": "债券",
"attributes": { "attributes": {
"金额": "100.00万元", "利率类型": "XXX",
"打印时间": "2024年10月20号" "发行日期": "XXX"
} }
}, },
{ {
"name": "杭州六小龙", "name": "XXX股",
"type": "公司", "type": "股票",
"attributes": { "attributes": {}
"地址": "杭州高新区"
}
} }
], ],
"relations": [ "relations": [
{ {
"source": "龙源(酒泉)风力发电有限公司", "source": "龙源电力集团股份有限公司",
"target": "2024年电子银行承兑汇票", "target": "XX公司债券",
"type": "持有", "type": "发行",
"attributes": { "attributes": {}
"持有方式": "纸质"
}
}, },
{ {
"source": "龙源(酒泉)风力发电有限公司", "source": "龙源力集团股份有限公司",
"target": "杭州六小龙", "target": "XXX股",
"type": "购", "type": "购",
"attributes": { "attributes": {
"收购类型": "全资收购", "开始时间": "XXX",
"收购时间": "2025年5月28号" "截止时间": "XXX"
} }
} }
],
"typed_triplets": [
[
"公司",
"持有",
"电子银行承兑汇票"
],
[
"公司",
"收购",
"公司"
]
] ]
} }
##
- nodesrelations"名称"
- relationssourcetargetnodesname
- `domainMetadata`
-
-
- JSON使```json ```Markdown./no_think
"""; """;
private static final String CLASSIFY_QUERY_INTENT_PROMPT = """ private static final String CLASSIFY_QUERY_INTENT_PROMPT = """
JSON使 #
#
##
JSON
##
{intents} {intents}
# ##
1. 1.
2. 使 2. 使
3. 3.
4. JSON使```json ```Markdown 4. JSON使```json ```Markdown
# ##
"我昨天买的鞋子怎么还没发货?" xxx
["订单查询"] ["意图1" "意图2" "意图3", ...]
# ##
{query} {query}
"""; """;
private static final String TEXT_TO_CYPHER_2_PROMPT = """ private static final String TEXT_TO_CYPHER_2_PROMPT = """
CypherCypher`neo4j_schema` CypherCypher`neo4j_schema`
{question} {question}
JSON JSON
{schema} {schema}
1. 1.
- 线 - 线
- -
- -
- -
- -
2. 2.
- -
- -
'\\I could not generate a Cypher script; the required information is not part of the Neo4j schema.\\\\n\\n' '\\I could not generate a Cypher script; the required information is not part of the Neo4j schema.\\\\n\\n'
3. MATCH 3. MATCH
- 使 - 使
- 使 - 使
- WHERE - WHERE
4. RETURN 4. RETURN
- 使`RETURN nodes, relationships``RETURN path` - 使`RETURN nodes, relationships``RETURN path`
- RETURN - RETURN
- `RETURN path` - `RETURN path`
5. Cypher 5. Cypher
- Cypher - Cypher
- 使OPTIONAL MATCH - 使OPTIONAL MATCH

@ -1,11 +1,12 @@
package com.supervision.pdfqaserver; package com.supervision.pdfqaserver;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
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.CypherSchemaDTO; import com.supervision.pdfqaserver.dto.*;
import com.supervision.pdfqaserver.dto.EREDTO;
import com.supervision.pdfqaserver.dto.IntentDTO;
import com.supervision.pdfqaserver.dto.TruncateDTO;
import com.supervision.pdfqaserver.service.*; import com.supervision.pdfqaserver.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -210,4 +211,85 @@ class PdfQaServerApplicationTests {
System.out.println("done"); System.out.println("done");
} }
@Autowired
private IntentionService intentionService;
@Test
void testIntentList() {
List<IntentDTO> intentionDTOs = intentionService.queryByDomainCategoryId("1").stream()
.filter(intention -> StrUtil.equals("0",intention.getGenerationType())) // 过滤出手动确认的数据
.map(IntentDTO::new).distinct().toList();
// List<String> digestList = intentionDTOs.stream().map(IntentDTO::getDigest).toList();
System.out.println(intentionDTOs.stream().map(i -> " - " + i.getDigest() + "\n").collect(Collectors.joining()));
}
@Autowired
private DomainMetadataService domainMetadataService;
@Test
void testDomainMetadataList() {
List<DomainMetadataDTO> domainMetadataDTOS = domainMetadataService.listByIntentionIds(List.of("1929814869055692801",
"1929814915000098818",
"1929815089067909122",
"1929815089067909124",
"1929815178012319747",
"1929815201403953154",
"1929815236732575746",
"1929815236799684610",
"1929815586533335043",
"1929815750165716996",
"1929819219706568708"));
String domainMetadata = metadataToJsonStr(domainMetadataDTOS);
System.out.println(domainMetadata);
}
/**
* json
* @param domainMetadataDTOS domainMetadataDTOS
* @return
*/
private String metadataToJsonStr(List<DomainMetadataDTO> domainMetadataDTOS){
JSONArray jsa = new JSONArray();
for (DomainMetadataDTO metadataDTO : domainMetadataDTOS) {
JSONObject metadataJson = new JSONObject();
JSONObject source = new JSONObject();
source.set("type", metadataDTO.getSourceType());
if (metadataDTO.getSourceAttributes() != null) {
JSONArray sourceAttributes = new JSONArray();
for (ERAttributeDTO attribute : metadataDTO.getSourceAttributes()) {
sourceAttributes.add(attribute.getAttrName());
}
source.set("attributes", sourceAttributes);
}
metadataJson.set("source", source);
JSONObject relation = new JSONObject();
relation.set("type", metadataDTO.getRelation());
if (metadataDTO.getRelationAttributes() != null) {
JSONArray relationAttributes = new JSONArray();
for (ERAttributeDTO attribute : metadataDTO.getRelationAttributes()) {
relationAttributes.add(attribute.getAttrName());
}
relation.set("attributes", relationAttributes);
}
metadataJson.set("relation", relation);
JSONObject target = new JSONObject();
target.set("type", metadataDTO.getTargetType());
if (metadataDTO.getTargetAttributes() != null) {
JSONArray targetAttributes = new JSONArray();
for (ERAttributeDTO attribute : metadataDTO.getTargetAttributes()) {
targetAttributes.add(attribute.getAttrName());
}
target.set("attributes", targetAttributes);
}
metadataJson.set("target", target);
jsa.add(metadataJson);
}
return jsa.toString();
}
} }

Loading…
Cancel
Save