提示词适配

master
daixiaoyi 1 month ago
parent 72b87cfd3f
commit d0f1147f38

@ -196,57 +196,44 @@ public class PromptCache {
private static final String TEXT_TO_CYPHER_PROMPT = """
Neo4j Cypher
---
****
- **relationType**
{relationTypeList}
- **sourceType**
{sourceTypeList}
- **targetType**
{targetTypeList}
---
****
1. `Cypher `
2. 使 `WHERE`
3. ****
4. json
3. 使 c r t
4. JSON \\{ "cypherQueries": [ "MATCH ... RETURN c, r, t", ... ] \\}
5. relationTypesourceType targetType
"无法根据数据库结构生成查询"
6. 使relationTypesourceType targetType
---
****
1. - ****
1. - ****
- ** Cypher **
"\\{
"cypherQueries": [
"MATCH (c:Company)-[r:HAS_LEGAL_REP]->(t) RETURN c, r, t",
"MATCH (c:Company)-[r:HAS_PHONE]->(t) RETURN c, r, t",
"MATCH (c:`公司`)-[r:`收购`]->(t:`公司`) RETURN c, r, t",
"MATCH (c:`公司`)-[r:`收购`]->(t:`上市公司`) RETURN c, r, t",
.....
]
\\}"
2. - ****
2. - ****
- ** Cypher **
"\\{
"cypherQueries": [
"MATCH (c:Company)-[r:IssueDocument]->(t:FinancialBill) RETURN c, r, t",
"MATCH (c:`公司`)-[r:`包含`]->(t:`报告`) RETURN c, r, t",
.....
]
\\}"
{query}
Cypher
""";
@ -263,6 +250,7 @@ public class PromptCache {
2.
3.
"您好!当前系统功能聚焦于审计报告相关内容分析,您的问题暂不在支持范围内。如需查询财务数据、票据详情或其他审计相关信息,请提供具体问题,我们将全力协助。"
/no_think
""";
private static final String CHINESE_TO_ENGLISH_PROMPT = """

@ -25,7 +25,14 @@ public class OllamaChatModelAspect {
*/
@Around("execution(* org.springframework.ai.chat.model.ChatModel.call(..))")
public Object aroundMethodExecution(ProceedingJoinPoint joinPoint) throws Throwable {
String signature = joinPoint.getSignature().toString();
// 获取原始参数
Object[] args = joinPoint.getArgs();
// 如果是String类型的call方法修改其参数
if (StrUtil.equals(signature, callStringMessage) && args.length > 0 && args[0] instanceof String originalPrompt) {
args[0] = originalPrompt + "/no_think";
}
// 执行原方法
Object result = joinPoint.proceed();
if (StrUtil.equals(model,"qwen3:30b-a3b") ) {

@ -39,6 +39,9 @@ public class Neo4jRepository {
while (result.hasNext()) {
org.neo4j.driver.Record record = result.next();
// 从 Record 中取出三部分
if (record.get("c") == null || record.get("r") == null || record.get("t") == null) {
continue;
}
Node a = record.get("c").asNode();
Relationship r = record.get("r").asRelationship();
Node b = record.get("t").asNode();

@ -56,19 +56,19 @@ public class ChatServiceImpl implements ChatService {
List<String> targetTypeList = domainMetadataService.list().stream().map(DomainMetadata::getTargetType).distinct().toList();
//将三个集合分别结合chineseEnglishWordsMap的key转化为value集合
List<String> sourceTypeListEnList = sourceTypeList.stream().map(chineseEnglishWordsMap::get).toList();
List<String> relationListEnList = relationList.stream().map(chineseEnglishWordsMap::get).toList();
List<String> targetTypeListEnList = targetTypeList.stream().map(chineseEnglishWordsMap::get).toList();
// List<String> sourceTypeEnList = sourceTypeList.stream().map(chineseEnglishWordsMap::get).toList();
// List<String> relationEnList = relationList.stream().map(chineseEnglishWordsMap::get).toList();
// List<String> targetTypeEnList = targetTypeList.stream().map(chineseEnglishWordsMap::get).toList();
//将三个集合分别转换为英文逗号分隔的字符串
String sourceTypeListEn = String.join(",", sourceTypeListEnList);
String relationListEn = String.join(",", relationListEnList);
String targetTypeListEn = String.join(",", targetTypeListEnList);
log.info("sourceTypeListEn: {}, relationListEn: {}, targetTypeListEn: {}", sourceTypeListEn, relationListEn, targetTypeListEn);
String sourceTypeListEn = String.join(",", sourceTypeList);
String relationListEn = String.join(",", relationList);
String targetTypeListEn = String.join(",", targetTypeList);
//LLM生成CYPHER
SystemPromptTemplate textToCypherTemplate = new SystemPromptTemplate(PromptCache.promptMap.get(TEXT_TO_CYPHER));
Message textToCypherMessage = textToCypherTemplate.createMessage(Map.of(PROMPT_PARAM_SOURCE_TYPE_LIST, sourceTypeListEn, PROMPT_PARAM_RELATION_TYPE_LIST, relationListEn, PROMPT_PARAM_TARGET_TYPE_LIST, targetTypeListEn, PROMPT_PARAM_QUERY, userQuery));
log.info("生成CYPHER语句的消息{}", textToCypherMessage);
String cypherJsonStr = ollamaChatModel.call(textToCypherMessage.getText());
log.info(cypherJsonStr);
List<String> cypherQueries;

Loading…
Cancel
Save