提示词优化

v_0.0.2
daixiaoyi 1 week ago
parent ad3135ef90
commit 13616f1878

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

@ -1,11 +1,12 @@
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.domain.PdfAnalysisOutput;
import com.supervision.pdfqaserver.dto.CypherSchemaDTO;
import com.supervision.pdfqaserver.dto.EREDTO;
import com.supervision.pdfqaserver.dto.IntentDTO;
import com.supervision.pdfqaserver.dto.TruncateDTO;
import com.supervision.pdfqaserver.dto.*;
import com.supervision.pdfqaserver.service.*;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
@ -210,4 +211,85 @@ class PdfQaServerApplicationTests {
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