|
@@ -168,11 +168,17 @@ public class ChatController {
|
|
|
|
|
|
|
|
private List<Map<String, Object>> buildSources(List<Map<String, Object>> docs) {
|
|
private List<Map<String, Object>> buildSources(List<Map<String, Object>> docs) {
|
|
|
return docs.stream()
|
|
return docs.stream()
|
|
|
- .map(d -> Map.<String, Object>of(
|
|
|
|
|
- "name", d.getOrDefault("source", ""),
|
|
|
|
|
- "section", d.getOrDefault("section", ""),
|
|
|
|
|
- "source", d.getOrDefault("source", "")
|
|
|
|
|
- ))
|
|
|
|
|
|
|
+ .map(d -> {
|
|
|
|
|
+ String content = (String) d.getOrDefault("content", "");
|
|
|
|
|
+ // 截取前 500 字作为原文片段
|
|
|
|
|
+ String excerpt = content.length() > 500 ? content.substring(0, 500) + "…" : content;
|
|
|
|
|
+ return Map.<String, Object>of(
|
|
|
|
|
+ "name", d.getOrDefault("source", ""),
|
|
|
|
|
+ "section", d.getOrDefault("section", ""),
|
|
|
|
|
+ "source", d.getOrDefault("source", ""),
|
|
|
|
|
+ "excerpt", excerpt
|
|
|
|
|
+ );
|
|
|
|
|
+ })
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
|