Commit dfbb02cd authored by zhouwei's avatar zhouwei

Merge branch 'dev' into 'master'

Dev

See merge request !13
parents 12eca765 8d94fd24
package com.nanyan.securitylink.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.nanyan.securitylink.dto.AIRequestDTO;
import com.nanyan.securitylink.service.AIService;
......@@ -43,6 +42,16 @@ 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("/urgent/notice/week/summary")
public Response<AIResponse<String>> extractUrgentNoticeWeekSummary(@RequestBody AIRequestDTO AIRequestDTO) {
return Response.SUCCESS(aiService.extractUrgentNoticeWeekSummary(AIRequestDTO));
}
@PostMapping("/news/country/city")
public Response<AIResponse<JSONObject>> collectNewsCountryAndCity(@RequestBody AIRequestDTO AIRequestDTO) {
return Response.SUCCESS(aiService.collectNewsCountryAndCity(AIRequestDTO));
......
......@@ -6,14 +6,25 @@ 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);
AIResponse<String> extractUrgentNoticeWeekSummary(AIRequestDTO aiRequestDTO);
}
......@@ -377,6 +377,132 @@ 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" +
"</examples>";
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<String> extractUrgentNoticeWeekSummary(AIRequestDTO aiRequestDTO) {
ChatInputData chatInputData = new ChatInputData();
String systemPrompt = "```xml\n" +
"<instruction>\n" +
"根据多条文旅部或外交部发布的紧急通知信息,生成一段简短的概括性安全提示。提示需涵盖保险责任相关内容,并以“Security Link在此提醒您”开头。具体要求如下:\n" +
"1. 内容需简洁明了,突出保险责任和风险规避建议。\n" +
"2. 语言风格需正式且具有警示性。\n" +
"3. 不得包含任何XML标签。\n" +
"4. 根据输入信息中的关键风险点(如示威游行、自然灾害等)生成对应的保险责任提示。\n" +
"5. 结尾需提供具体的行动建议(如“避开相关区域”或“联系保险公司”等)。\n" +
"\n" +
"生成步骤:\n" +
"1. 提取输入信息中的核心风险事件(如战争、罢工、自然灾害等)。\n" +
"2. 明确该风险事件在保险条款中的常见责任归属(如“除外责任”或“有限保障”)。\n" +
"3. 组合成标准句式:“Security Link在此提醒您,[风险事件]常被列为[保险责任说明],因此[行动建议]。”\n" +
"4. 检查语句通顺性和专业性,确保无歧义。\n" +
"</instruction>\n" +
"\n" +
"<examples>\n" +
"<example>\n" +
"<input>\n" +
"外交部提醒:某国首都爆发大规模反政府示威,局部地区出现武装冲突\n" +
"</input>\n" +
"<output>\n" +
"Security Link在此提醒您,示威游行及武装冲突事件通常被列为旅行保险的除外责任,建议您暂勿前往相关区域,并确认保单中的战争条款保障范围。\n" +
"</output>\n" +
"</example>\n" +
"\n" +
"<example>\n" +
"<input>\n" +
"文旅部通知:B国沿海地区遭遇百年一遇台风,多趟航班取消\n" +
"</input>\n" +
"<output>\n" +
"Security Link在此提醒您,自然灾害导致的行程中断可能需特定保险条款才予理赔,请立即联系保险公司报备,并保留所有交通票据作为理赔凭证。\n" +
"</output>\n" +
"</example>\n" +
"<format_requirements>\n" +
"1. 严格采用“Security Link在此提醒您”作为开头\n" +
"2. 必须包含“保险”相关表述\n" +
"3. 风险描述需与输入信息完全匹配\n" +
"4. 行动建议需具体可行\n" +
"5. 总字数控制在50-80字之间\n";
buildChatInputData(chatInputData, aiRequestDTO.getInputs().getMsg_info(), systemPrompt);
String apiKey = getModelApiKey();
ChatCompletionResponse chatCompletionResponse = aiRequest(chatInputData, apiKey);
if (CollectionUtils.isNotEmpty(chatCompletionResponse.getChoices())) {
AIResponse<String> aiResponse = new AIResponse<>();
String content = chatCompletionResponse.getChoices().get(0).getMessage().getContent();
aiResponse.setFinish_reason(chatCompletionResponse.getChoices().get(0).getFinish_reason());
if(StringUtils.isNotEmpty(content)){
ResultVO<String> outputs = new ResultVO<>();
List<String> contents = new ArrayList<>();
contents.add(content);
outputs.setResult(contents);
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