优化text-to-cypher提示词

v_0.0.2
xueqingkun
parent 89140d638f
commit fd4641cc48

@ -793,38 +793,38 @@ public class PromptCache {
private static final String TEXT_TO_CYPHER_2_PROMPT = """
CypherCypher`neo4j_schema`
{question}
JSON
neo4j_schemaJSON
{schema}
1.
- 线
-
-
-
-
2.
-
-
'\\I could not generate a Cypher script; the required information is not part of the Neo4j schema.\\\\n\\n'
3. MATCH
- 使
- 使,****
- ****`-[r:REL_TYPE]->`
- 使
- WHERE
4. RETURN
- 使`RETURN nodes, relationships``RETURN path`
- RETURN
- `RETURN path`
- ********
5. Cypher
- Cypher
- Cypher```cypher ```
- 使OPTIONAL MATCH
- RETURN使/no_think
- ****MATCH ****
- cyphercypher/no_think
""";
}

@ -56,6 +56,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
log.info("没有找到匹配的意图query: {}", query);
return null;
}
log.info("找到匹配的意图query: {}, relations: {}", query, relations.stream().map(Intention::getDigest).collect(Collectors.joining(",")));
List<DomainMetadataDTO> domainMetadataDTOS = domainMetadataService.listByIntentionIds(relations.stream().map(Intention::getId).toList());
CypherSchemaDTO schemaDTO = this.queryRelationSchema(domainMetadataDTOS);
if (CollUtil.isEmpty(schemaDTO.getRelations()) && CollUtil.isEmpty(schemaDTO.getNodes())) {
@ -64,6 +65,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
}
String prompt = promptMap.get(TEXT_TO_CYPHER_2);
String format = StrUtil.format(prompt, Map.of("question", query, "schema", schemaDTO.format()));
log.info("生成Cypher脚本query: {}, format: {}", query, format);
String call = aiCallService.call(format);
if (StrUtil.contains(call,"I could not generate a Cypher script; the required information is not part of the Neo4j schema.")){
log.info("大模型没能生成cypherquery: {}", query);
@ -209,19 +211,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
if (null == rel){
continue;
}
List<RelationExtractionDTO> relSourceType = cypherSchemaDTO.getRelations(sourceType);
List<RelationExtractionDTO> relTargetType = cypherSchemaDTO.getRelations(targetType);
relSourceType.add(rel);
relSourceType.addAll(relTargetType);
for (RelationExtractionDTO relationExtractionDTO : relSourceType) {
boolean none = merged.stream().noneMatch(i -> StrUtil.equals(i.getRelation(), relationExtractionDTO.getRelation()) &&
StrUtil.equals(i.getSourceType(), relationExtractionDTO.getSourceType()) &&
StrUtil.equals(i.getTargetType(), relationExtractionDTO.getTargetType()));
if (none){
merged.add(relationExtractionDTO);
}
}
merged.add(rel);
}
List<EntityExtractionDTO> entityExtractionDTOS = new ArrayList<>();
for (RelationExtractionDTO relationExtractionDTO : merged) {
@ -248,7 +238,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
String prompt = promptMap.get(CLASSIFY_QUERY_INTENT);
List<Intention> result = new ArrayList<>();
log.info("开始分类意图query: {}, intentions size: {}", query, intentions.size());
List<List<Intention>> intentionSplit = CollUtil.split(intentions, 200);
List<List<Intention>> intentionSplit = CollUtil.split(intentions, 300);
for (List<Intention> intentionList : intentionSplit) {
log.info("分类意图query: {}, intentions size: {}", query, intentionList.size());
List<String> intents = intentionList.stream().map(Intention::getDigest).toList();
@ -256,7 +246,7 @@ public class TripleToCypherExecutorImpl implements TripleToCypherExecutor {
"intents", JSONUtil.toJsonStr(intents));
String format = StrUtil.format(prompt, params);
String call = aiCallService.call(format);
log.info("classifyIntents:分类意图结果query: {}, call: {}", query, call);
if (StrUtil.isEmpty(call)) {
return new ArrayList<>();
}

Loading…
Cancel
Save