improve topics and chat source display

This commit is contained in:
Adrien
2026-04-12 18:56:18 +02:00
parent c98fe9ceaa
commit 5f03e1f41b
6 changed files with 328 additions and 166 deletions
@@ -19,9 +19,11 @@ public record TopicSummaryResponse(
String bookId,
String bookTitle,
Integer page,
String chunkText,
String figureId,
String label,
String caption,
String figureType,
String imageUrl
) {
}
@@ -188,7 +188,7 @@ public class TopicSummaryService {
String bookId = book != null ? book.getId().toString() : null;
sources.add(new TopicSummaryResponse.SourceReference(
"TEXT", "S" + (i + 1), bookId, title, s.getPageStart(),
null, null, null, null));
truncate(s.getFullText(), 500), null, null, null, null, null));
}
for (int i = 0; i < figures.size(); i++) {
@@ -203,7 +203,8 @@ public class TopicSummaryService {
String imageUrl = "/api/v1/figures/" + f.getBookId() + "/" + filename;
sources.add(new TopicSummaryResponse.SourceReference(
"FIGURE", "F" + (i + 1), bookId, title, f.getPage(),
f.getId(), f.getLabel(), f.getCaption(), imageUrl));
null, f.getId(), f.getLabel(), f.getCaption(),
f.getFigureType().name(), imageUrl));
}
return sources;
@@ -218,6 +219,11 @@ public class TopicSummaryService {
}
}
private String truncate(String text, int maxChars) {
if (text == null) return "";
return text.length() <= maxChars ? text : text.substring(0, maxChars) + "";
}
private List<TopicSummaryResponse.SourceReference> deserializeSources(String json) {
try {
return objectMapper.readValue(json,