| | |
| | | |
| | | @Override |
| | | public void getAddQuestion(String id) { |
| | | try { |
| | | AiProductQuestionJob aiProductQuestionJob = aiProductQuestionJobMapper.selectById(id); |
| | | if (ObjectUtil.isEmpty(aiProductQuestionJob)){ |
| | | return; |
| | |
| | | if (2 != aiProductQuestionJobDone.getState()){ |
| | | agentProducer.sendAddQuestionJob(id); |
| | | } |
| | | } catch (Exception e) { |
| | | agentProducer.sendAddQuestionJob(id); |
| | | log.error("知识库异常", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param aiResponse AI返回的原始响应字符串 |
| | | * @return 解析后的问题列表 |
| | | */ |
| | | public List<JSONObject> parseAiQuestionResponse(String aiResponse) { |
| | | public static List<JSONObject> parseAiQuestionResponse(String aiResponse) { |
| | | |
| | | try { |
| | | // 解析外层JSON |
| | | JSONObject outerJson = JSONUtil.parseObj(aiResponse); |
| | | |
| | | // 提取output字段 |
| | | String output = outerJson.getStr("output"); |
| | | log.info("原始输出内容: {}", output); |
| | | |
| | | // 去除<start>和</start>标签,并清理多余字符 |
| | | String jsonContent = output.replace("<start>", "") |
| | | .replace("</start>", "") |
| | | .replace("\\n", "") |
| | | .replace("\\n", "") |
| | | .replace("\\\"", "\"") |
| | | .trim(); |
| | | |
| | | log.info("清理后JSON内容: {}", jsonContent); |
| | | // 解析内部JSON |
| | | JSONObject innerJson = JSONUtil.parseObj(jsonContent); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String s = "{\"output\":\"<start>{\\\"question_list\\\":[{\\\"title\\\":\\\"根据知识库内容,调整T区的三大作用分别是什么?请逐条准确列举。\\\",\\\"answer_list\\\":[{\\\"answer\\\":\\\"1.提升折叠度;2.调整面部比例;3.提升骨性支撑力\\\",\\\"type\\\":2,\\\"analysis\\\":\\\"原文明确列出:'1.提升折叠度(增加正面、侧面转折落差,减少扁平感);2.调整面部比例(通过T区的纵向与横线的调整,优化三庭五眼、四高三底);3.提升骨性支撑力(为软组织提供坚实的\\\\\\\"地基\\\\\\\"抗衰并提升高级的骨感)'\\\"},{\\\"answer\\\":\\\"1.提升折叠度;2.调整三庭五眼;3.增强软组织弹性\\\",\\\"type\\\":1,\\\"analysis\\\":\\\"\\\"},{\\\"answer\\\":\\\"1.提升立体感;2.优化面部比例;3.强化韧带支撑\\\",\\\"type\\\":1,\\\"analysis\\\":\\\"\\\"}]}]}</start>\"}"; |
| | | List<JSONObject> questionList = parseAiQuestionResponse(s); |
| | | System.out.println(questionList); |
| | | |
| | | } |
| | | |
| | | } |