Commit 2cfaa25a authored by zhouwei's avatar zhouwei

新增提取紧急通知概要信息接口

parent be361a3e
......@@ -43,6 +43,11 @@ public class AIController {
return Response.SUCCESS(aiService.dealUrgentNotice(AIRequestDTO));
}
@PostMapping("/urgent/notice/summary")
public Response<AIResponse<JSONObject>> extractUrgentNoticeSummary(@RequestBody AIRequestDTO AIRequestDTO) {
return Response.SUCCESS(aiService.extractUrgentNoticeSummary(AIRequestDTO));
}
@PostMapping("/news/country/city")
public Response<AIResponse<JSONObject>> collectNewsCountryAndCity(@RequestBody AIRequestDTO AIRequestDTO) {
return Response.SUCCESS(aiService.collectNewsCountryAndCity(AIRequestDTO));
......
......@@ -6,14 +6,23 @@ import com.nanyan.securitylink.vo.AIResponse;
import com.nanyan.securitylink.vo.CodeVO;
public interface AIService {
//翻译
AIResponse<String> translate(AIRequestDTO AIRequestDTO, String requestId);
//新闻打标签
AIResponse<CodeVO> newsTags(AIRequestDTO AIRequestDTO);
//自然灾害打标签
AIResponse<CodeVO> naturalDisasterTag(AIRequestDTO aiRequestDTO);
//新闻翻译和打标签
AIResponse<JSONObject> newsTagAndTranslate(AIRequestDTO aiRequestDTO);
//提取紧急通知信息中等级、国家、城市等信息
AIResponse<JSONObject> dealUrgentNotice(AIRequestDTO aiRequestDTO);
//提取新闻中的国家和城市信息
AIResponse<JSONObject> collectNewsCountryAndCity(AIRequestDTO aiRequestDTO);
//提取紧急通知概要信息
AIResponse<JSONObject> extractUrgentNoticeSummary(AIRequestDTO aiRequestDTO);
}
......@@ -377,6 +377,94 @@ public class AIServiceImpl implements AIService {
return null;
}
/**
* 提取紧急通知概要信息
* @param aiRequestDTO
* @return
*/
@Override
public AIResponse<JSONObject> extractUrgentNoticeSummary(AIRequestDTO aiRequestDTO) {
ChatInputData chatInputData = new ChatInputData();
String systemPrompt = "```xml\n" +
"<instruction>\n" +
"根据文旅部及外交部紧急通知消息,你需要完成以下任务:\n" +
"1. 提炼关键信息并输出指定格式的JSON。\n" +
"2. 提炼相关主体事件(无需考虑使馆提醒部分,但保留时间),输出字段为summary。\n" +
"3. 提取该事件的注意事项(尽量控制在50字内,用通俗的单句表达),输出字段为note。\n" +
"4. 提取事件类型,输出字段为event。\n" +
"\n" +
"请按照以下步骤操作:\n" +
"- 仔细阅读输入的通知消息,确保理解所有关键信息。\n" +
"- 从通知中提取与主体事件直接相关的内容,包括时间、地点、事件描述等,但忽略使馆提醒部分。\n" +
"- 用简洁的语言总结注意事项,确保通俗易懂且不超过50字。\n" +
"- 根据事件性质判断事件类型(如自然灾害、政治事件、公共卫生事件等)。\n" +
"- 将提取的信息整理为JSON格式,确保字段名与要求一致(summary、note、event)。\n" +
"- 输出时不要包含任何XML标签,仅提供纯JSON格式内容。\n" +
"\n" +
"请确保输出内容准确、简洁,且完全基于输入信息。不要添加任何未提及的细节或推测。\n" +
"</instruction>\n" +
"\n" +
"<examples>\n" +
"<example>\n" +
"<input>\n" +
"文旅部及外交部紧急通知:近日,某国发生大规模示威活动,部分地区出现暴力冲突。使馆提醒中国公民避免前往示威区域。\n" +
"</input>\n" +
"<output>\n" +
"{\n" +
" \"summary\": \"某国近日发生大规模示威活动,部分地区出现暴力冲突\",\n" +
" \"note\": \"避免前往示威区域以防卷入冲突\",\n" +
" \"event\": \"政治事件\"\n" +
"}\n" +
"</output>\n" +
"</example>\n" +
"\n" +
"<example>\n" +
"<input>\n" +
"文旅部及外交部紧急通知:受台风影响,某岛国机场关闭至明日18时。使馆建议旅客暂缓行程并关注航班动态。\n" +
"</input>\n" +
"<output>\n" +
"{\n" +
" \"summary\": \"某岛国受台风影响,机场关闭至明日18时\",\n" +
" \"note\": \"暂缓行程并密切关注航班动态\",\n" +
" \"event\": \"自然灾害\"\n" +
"}\n" +
"</output>\n" +
"</example>\n" +
"\n" +
"<example>\n" +
"<input>\n" +
"文旅部及外交部紧急通知:某地爆发不明原因呼吸道疾病,已造成多人感染。使馆提醒公民保持个人卫生并避免接触患者。\n" +
"</input>\n" +
"<output>\n" +
"{\n" +
" \"summary\": \"某地爆发不明原因呼吸道疾病,已造成多人感染\",\n" +
" \"note\": \"保持个人卫生并避免接触患者\",\n" +
" \"event\": \"公共卫生事件\"\n" +
"}\n" +
"</output>\n" +
"</example";
buildChatInputData(chatInputData, aiRequestDTO.getInputs().getMsg_info(), systemPrompt);
String apiKey = getModelApiKey();
ChatCompletionResponse chatCompletionResponse = aiRequest(chatInputData, apiKey);
if (CollectionUtils.isNotEmpty(chatCompletionResponse.getChoices())) {
AIResponse<JSONObject> aiResponse = new AIResponse<>();
String content = chatCompletionResponse.getChoices().get(0).getMessage().getContent();
aiResponse.setFinish_reason(chatCompletionResponse.getChoices().get(0).getFinish_reason());
if(StringUtils.isNotEmpty(content)){
content = content.replaceAll("```json","").replaceAll("```", "");
JSONObject jsonObject = JSONArray.parseObject(content, JSONObject.class);
ResultVO<JSONObject> outputs = new ResultVO<>();
List<JSONObject> jsonObjects = new ArrayList<>();
jsonObjects.add(jsonObject);
outputs.setResult(jsonObjects);
aiResponse.setOutputs(outputs);
}
return aiResponse;
}
return null;
}
@Override
public AIResponse<JSONObject> dealUrgentNotice(AIRequestDTO aiRequestDTO) {
ChatInputData chatInputData = new ChatInputData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment