提交 88773e55 作者: 925993793@qq.com

事件分析优化

上级 f5510d77
...@@ -174,8 +174,19 @@ public class EventHomeController { ...@@ -174,8 +174,19 @@ public class EventHomeController {
*/ */
@GetMapping("/hotWordRecommend") @GetMapping("/hotWordRecommend")
public Result<?> hotWordRecommend(@RequestParam String networkName) { public Result<?> hotWordRecommend(@RequestParam String networkName) {
String prompt = "请根据提供的百度/新浪热榜中的网络事件,再结合网络上资讯,推荐一些简短的关键词。以json格式输出:[\"关键词1\",\"关键词2\"]"; String prompt = "你是一个专业信息采集助手,根据用户专题描述生成关键词表达式:\n" +
String result = llmService.model(null, prompt, networkName); "1. 用 + 表示与关系(必须同现),| 表示或关系(任一出现),用()分组\n" +
"2. 执行三步操作:\n" +
" (1) 提取核心实体(如企业/产品名)\n" +
" (2) 将抽象词拆解为3-5个具体场景词(如\"动向\"→\"上升|下降|波动|结构调整\")\n" +
" (3) 扩展同义词/行业关联词\n" +
"3. 排除时间词,+号不超过2个,单组|内词不超过5个\n" +
"4. 输出仅含表达式\n" +
"\n" +
"示例: \n" +
"描述:苹果新款iPhone发布引发市场反响\n" +
"输出:(苹果|iPhone)+(発売|価格|予約状況|市場シェア|消費者反応)";
String result = llmService.model(null,null, prompt, networkName);
if (result.startsWith("```json")) { if (result.startsWith("```json")) {
result = result.substring(7, result.length() - 3); result = result.substring(7, result.length() - 3);
} else if (result.startsWith("```")) { } else if (result.startsWith("```")) {
......
...@@ -8,21 +8,11 @@ public interface LlmService { ...@@ -8,21 +8,11 @@ public interface LlmService {
/** /**
* glm模型调用 * glm模型调用
* *
* @param model 模型类型 * @param modelType 模型类型
* @param system 提示词
* @param content 引用内容
* @return 大模型响应结果
*/
String model(String model, String system, String content);
/**
* 采集词推荐(定制自定义专题)
*
* @param modelName 模型名称 * @param modelName 模型名称
* @param prompt 提示词 * @param system 提示词
* @param content 输入的内容 * @param content 引用内容
* @author lkg * @return 大模型响应结果
* @date 2025/8/16
*/ */
String crawlerWord(String modelName, String prompt, String content); String model(String modelType, String modelName, String system, String content);
} }
...@@ -45,11 +45,14 @@ public class LlmServiceImpl implements LlmService { ...@@ -45,11 +45,14 @@ public class LlmServiceImpl implements LlmService {
private LlmProperties llmProperties; private LlmProperties llmProperties;
@Override @Override
public String model(String modelType, String system, String content) { public String model(String modelType,String modelName, String system, String content) {
if (StringUtils.isEmpty(modelType)) { if (StringUtils.isEmpty(modelType)) {
modelType = llmProperties.getDefaultModelType(); modelType = llmProperties.getDefaultModelType();
} }
LlmProperties.ModelConfig modelConfig = llmProperties.getModelConfig(modelType); LlmProperties.ModelConfig modelConfig = llmProperties.getModelConfig(modelType);
if (StringUtils.isNotEmpty(modelName)) {
modelConfig.setDefaultModel(modelName);
}
if (modelType.equalsIgnoreCase("zhipu")) { if (modelType.equalsIgnoreCase("zhipu")) {
return glmModel(modelConfig, system, content); return glmModel(modelConfig, system, content);
} else if (modelType.equalsIgnoreCase("qwen")) { } else if (modelType.equalsIgnoreCase("qwen")) {
...@@ -62,15 +65,6 @@ public class LlmServiceImpl implements LlmService { ...@@ -62,15 +65,6 @@ public class LlmServiceImpl implements LlmService {
return null; return null;
} }
@Override
public String crawlerWord(String modelName, String prompt, String content) {
LlmProperties.ModelConfig modelConfig = llmProperties.getModelConfig("qwen");
if (StringUtils.isNotEmpty(modelName)) {
modelConfig.setDefaultModel(modelName);
}
return qwenModel(modelConfig, prompt, content);
}
/** /**
* glm模型调用 * glm模型调用
* *
......
...@@ -311,8 +311,27 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -311,8 +311,27 @@ public class AnalysisServiceImpl implements AnalysisService {
if (llmConfig == null) { if (llmConfig == null) {
return null; return null;
} }
String result = llmService.model(llmConfig.getLlmName(), llmConfig.getLlmPrompt(), content); String result = llmService.model(llmConfig.getLlmName(),null, llmConfig.getLlmPrompt(), content);
result = result.replaceAll("```json","").replaceAll("```",""); AnalysisColumnEnum analysisColumnEnum = AnalysisColumnEnum.getByCode(llmConfig.getColumnCode());
String startHeader = null;
if (analysisColumnEnum != null) {
String resType = analysisColumnEnum.getResType();
if (resType.equals("array")) {
startHeader = "[";
} else if (resType.equals("object")) {
startHeader = "{";
}
}
if (startHeader != null && !result.startsWith(startHeader)) {
if (result.startsWith("```json")) {
result = result.substring(7, result.length() - 3);
} else if (result.startsWith("```")) {
result = result.substring(3, result.length() - 3);
} else if (result.contains(startHeader)){
result = result.substring(result.indexOf(startHeader));
}
}
result = result.replaceAll("```json", "").replaceAll("```","");
if (llmConfig.getColumnCode().equals(AnalysisColumnEnum.IMPACT_ASSESSMENT.getCode())) { if (llmConfig.getColumnCode().equals(AnalysisColumnEnum.IMPACT_ASSESSMENT.getCode())) {
EventLlmConfig detailConfig = eventLlmConfigService.getConfig(event.getId(), AnalysisColumnEnum.IMPACT_ASSESSMENT_DETAIL.getCode()); EventLlmConfig detailConfig = eventLlmConfigService.getConfig(event.getId(), AnalysisColumnEnum.IMPACT_ASSESSMENT_DETAIL.getCode());
List<JSONObject> impactList = JSON.parseArray(result, JSONObject.class); List<JSONObject> impactList = JSON.parseArray(result, JSONObject.class);
...@@ -321,7 +340,7 @@ public class AnalysisServiceImpl implements AnalysisService { ...@@ -321,7 +340,7 @@ public class AnalysisServiceImpl implements AnalysisService {
params.put("eventName", event.getEventName()); params.put("eventName", event.getEventName());
params.put("eventSummary", event.getEventDescribe()); params.put("eventSummary", event.getEventDescribe());
params.put("impactOutline", impact); params.put("impactOutline", impact);
String impactDetail = llmService.model(detailConfig.getLlmName(), detailConfig.getLlmPrompt(), params.toJSONString()); String impactDetail = llmService.model(detailConfig.getLlmName(),null, detailConfig.getLlmPrompt(), params.toJSONString());
impact.put("impactDetail", impactDetail); impact.put("impactDetail", impactDetail);
} }
result = JSON.toJSONString(impactList); result = JSON.toJSONString(impactList);
......
...@@ -71,7 +71,7 @@ public class NetWorkEventTask { ...@@ -71,7 +71,7 @@ public class NetWorkEventTask {
public void test(Integer type) { public void test(Integer type) {
List<EventNetwork> networkList = getNetWordEventList(type); List<EventNetwork> networkList = getNetWordEventList(type);
String response = llmService.model(null, PROMPT, JSONObject.toJSONString(networkList)); String response = llmService.model(null,null, PROMPT, JSONObject.toJSONString(networkList));
if (response.contains("```json")) { if (response.contains("```json")) {
response = response.substring(response.indexOf("```json") + 7, response.lastIndexOf("```")); response = response.substring(response.indexOf("```json") + 7, response.lastIndexOf("```"));
} }
...@@ -109,7 +109,7 @@ public class NetWorkEventTask { ...@@ -109,7 +109,7 @@ public class NetWorkEventTask {
} }
if (CollectionUtils.isNotEmpty(finalList)) { if (CollectionUtils.isNotEmpty(finalList)) {
finalList.forEach(network -> network.setLatest(1)); finalList.forEach(network -> network.setLatest(1));
String response = llmService.model(null, PROMPT, JSONObject.toJSONString(finalList)); String response = llmService.model(null,null, PROMPT, JSONObject.toJSONString(finalList));
if (StringUtils.isNotEmpty(response)) { if (StringUtils.isNotEmpty(response)) {
try { try {
if (response.contains("```json")) { if (response.contains("```json")) {
......
...@@ -183,3 +183,28 @@ caiji: ...@@ -183,3 +183,28 @@ caiji:
data-permit: data-permit:
dataPermitGetQueryEntityTest: http://1.95.77.159:10089/permission/ dataPermitGetQueryEntityTest: http://1.95.77.159:10089/permission/
dataPermitGetQueryEntityProd: http://1.95.14.24:8060/ dataPermitGetQueryEntityProd: http://1.95.14.24:8060/
model:
default-modelType: zhipu
configs:
- modelType: zhipu
modelTypeName: 智谱
url: https://open.bigmodel.cn/api/paas/v4/chat/completions
api-key: c5a53bd5f95a4e37a8997deb5d0c6031.orXyRRPNvZiqRaxF
default-model: glm-4-flash #免费
web-search: true
- modelType: qwen
modelTypeName: 千问
url: https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions
api-key: sk-01ee9a6efa394178993a950b768e3753
default-model: qwen-plus #收费
- modelType: deepseek
modelTypeName: deepseek
url: https://api.deepseek.com/v1/chat/completions
api-key: sk-656a8ec451dc47aaad3dacf24fe36f20
default-model: deepseek-chat #收费
- modelType: doubao
modelTypeName: 豆包
url: https://ark.cn-beijing.volces.com/api/v3/chat/completions
api-key: ab54c534-4f3c-41b9-9b27-132cb7954b6f
default-model: doubao-1-5-pro-32k-250115 # Doubao-1.5-pro-32k #收费
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论