提交 7ae25444 作者: 925993793@qq.com

定制专题翻译接口

上级 96349670
...@@ -3,6 +3,7 @@ package com.zzsn.event.external.controller; ...@@ -3,6 +3,7 @@ package com.zzsn.event.external.controller;
import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
...@@ -20,10 +21,9 @@ import com.zzsn.event.service.InformationService; ...@@ -20,10 +21,9 @@ import com.zzsn.event.service.InformationService;
import com.zzsn.event.service.SubjectService; import com.zzsn.event.service.SubjectService;
import com.zzsn.event.service.SubjectSimpleService; import com.zzsn.event.service.SubjectSimpleService;
import com.zzsn.event.util.HttpUtil; import com.zzsn.event.util.HttpUtil;
import com.zzsn.event.util.ObjectUtil;
import com.zzsn.event.util.RedisUtil; import com.zzsn.event.util.RedisUtil;
import com.zzsn.event.vo.InfoDataSearchCondition; import com.zzsn.event.vo.*;
import com.zzsn.event.vo.SubjectDetailVO;
import com.zzsn.event.vo.SubjectSimpleVO;
import com.zzsn.event.vo.es.DisplayInfo; import com.zzsn.event.vo.es.DisplayInfo;
import com.zzsn.event.xxljob.service.IXxlJobInfoService; import com.zzsn.event.xxljob.service.IXxlJobInfoService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
...@@ -72,6 +72,8 @@ public class ExternalController { ...@@ -72,6 +72,8 @@ public class ExternalController {
@Value("${caiji.keywordCrawler.url:}") @Value("${caiji.keywordCrawler.url:}")
private String keywordCrawlerUrl; private String keywordCrawlerUrl;
@Value("${translate.url:}")
private String TRANSLATE_URL;
/** /**
* 创建专题 * 创建专题
...@@ -291,7 +293,7 @@ public class ExternalController { ...@@ -291,7 +293,7 @@ public class ExternalController {
* @date 2025/8/16 * @date 2025/8/16
*/ */
@GetMapping("/gatherSummary") @GetMapping("/gatherSummary")
public Result<?> gatherSummary(@RequestParam String subjectId) { public Result<?> gatherSummary(@RequestParam String subjectId, @RequestParam String language) {
InfoDataSearchCondition searchCondition = new InfoDataSearchCondition(); InfoDataSearchCondition searchCondition = new InfoDataSearchCondition();
searchCondition.setSubjectId(subjectId); searchCondition.setSubjectId(subjectId);
searchCondition.setCategory(2); searchCondition.setCategory(2);
...@@ -310,16 +312,23 @@ public class ExternalController { ...@@ -310,16 +312,23 @@ public class ExternalController {
Subject subject = subjectService.getById(subjectId); Subject subject = subjectService.getById(subjectId);
params.put("subject", subject.getSubjectName()); params.put("subject", subject.getSubjectName());
params.put("summaryList", summaryList); params.put("summaryList", summaryList);
String languageCN = "中文";
if ("zh-CN".equals(language)) {
languageCN = "中文";
} else if ("en".equals(language)) {
languageCN = "英文";
} else if ("ja".equals(language)) {
languageCN = "日文";
}
String prompt = "将用户上传的多篇资讯摘要文本和主题整合为一段连贯、精炼的综合摘要(约500字)。要求:\n" + String prompt = "将用户上传的多篇资讯摘要文本和主题整合为一段连贯、精炼的综合摘要(约500字)。要求:\n" +
"1)将输入的json解析,subject是主题,summary是摘要,提炼核心主题与高度共识的关键发现;\n" + "1)将输入的json解析,subject是主题,summary是摘要,提炼核心主题与高度共识的关键发现;\n" +
"2)客观指出存在的分歧点及其原因;\n" + "2)客观指出存在的分歧点及其原因;\n" +
"3)简述观点或技术的演进趋势;\n" + "3)简述观点或技术的演进趋势;\n" +
"4)语言需严谨中性,直接输出整合后的段落,无需分节分段或小标题。\n" + "4)语言需严谨中性,直接输出整合后的段落,无需分节分段或小标题。\n" +
"5)识别输入的语种,生成的语种和输入保持一致\n" +
"\n" + "\n" +
"约束:\n" + "约束:\n" +
"1.输出禁止分段\n" + "1.输出禁止分段\n" +
"2.输出的语言和输入保持一致\n" + "2.必须输出" + languageCN + "的摘要\n" +
"\n" + "\n" +
"使用示例:\n" + "使用示例:\n" +
"输入:\n" + "输入:\n" +
...@@ -345,4 +354,31 @@ public class ExternalController { ...@@ -345,4 +354,31 @@ public class ExternalController {
public Result<?> getGatherSummary(@RequestParam String subjectId) { public Result<?> getGatherSummary(@RequestParam String subjectId) {
return Result.OK(redisUtil.get("GATHER_SUMMARY::" + subjectId)); return Result.OK(redisUtil.get("GATHER_SUMMARY::" + subjectId));
} }
/**
* 翻译
*
* @param params 参数
* @author lkg
* @date 2024/8/21
*/
@PostMapping("/translate")
public Result<?> translate(@RequestBody JSONObject params) {
String language = params.getString("language");
String summary = params.getString("summary");
TranslateVO translateVO = new TranslateVO();
translateVO.setFrom("auto");
translateVO.setTo(language);
List<String> content = new ArrayList<>();
content.add(summary);
translateVO.setContent(content);
List<String> data = new ArrayList<>();
try {
String s = HttpUtil.doPost(TRANSLATE_URL, ObjectUtil.objectToJSONObject(translateVO), 10000);
data = JSONArray.parseArray(s, String.class);
} catch (Exception e) {
e.printStackTrace();
}
return Result.OK(data);
}
} }
...@@ -138,7 +138,7 @@ scoreRule: ...@@ -138,7 +138,7 @@ scoreRule:
yearScore: 3 yearScore: 3
beforeYearScore: 1 beforeYearScore: 1
translate: translate:
url: http://114.116.116.241:8018/translate/getTranslateInfoWithTag url: http://1.95.51.144:8018/translate/getTranslateInfoWithTag
python: python:
#python打分接口-弃用 #python打分接口-弃用
scoreModelUrl: http://114.116.36.231:8080/score scoreModelUrl: http://114.116.36.231:8080/score
......
...@@ -140,7 +140,7 @@ scoreRule: ...@@ -140,7 +140,7 @@ scoreRule:
yearScore: 3 yearScore: 3
beforeYearScore: 1 beforeYearScore: 1
translate: translate:
url: http://114.116.116.241:8018/translate/getTranslateInfoWithTag url: http://1.95.51.144:8018/translate/getTranslateInfoWithTag
python: python:
#python打分接口-弃用 #python打分接口-弃用
scoreModelUrl: http://114.116.36.231:8080/score scoreModelUrl: http://114.116.36.231:8080/score
......
...@@ -140,7 +140,7 @@ scoreRule: ...@@ -140,7 +140,7 @@ scoreRule:
yearScore: 3 yearScore: 3
beforeYearScore: 1 beforeYearScore: 1
translate: translate:
url: http://114.116.116.241:8018/translate/getTranslateInfoWithTag url: http://1.95.51.144:8018/translate/getTranslateInfoWithTag
python: python:
#python打分接口-弃用 #python打分接口-弃用
scoreModelUrl: http://114.116.36.231:8080/score scoreModelUrl: http://114.116.36.231:8080/score
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论