优化 json 格式处理

This commit is contained in:
zk
2026-04-29 18:23:28 +08:00
parent ad8fff3d62
commit d284673a36
5 changed files with 70 additions and 37 deletions
@@ -1,6 +1,7 @@
package org.jiayunet.service;
import org.jiayunet.ai.AiChatAbility;
import org.jiayunet.ai.AiResponseCleanTool;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
@@ -651,7 +652,7 @@ public class JobService {
// 8. 调用AI
String aiResponse = aiChatAbility.chat("job-recommend", systemPrompt, userMessage);
String json = cleanAiResponse(aiResponse);
String json = AiResponseCleanTool.clean(aiResponse);
// 9. 解析AI返回,过滤出选中的岗位
try {
@@ -675,13 +676,4 @@ public class JobService {
}
}
/** 清理AI返回的markdown代码块和控制字符 */
private String cleanAiResponse(String response) {
String json = response.trim();
if (json.startsWith("```")) {
json = json.replaceAll("^```\\w*\\n?", "").replaceAll("\\n?```$", "").trim();
}
json = json.replaceAll("[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]", "");
return json;
}
}