Skip to content

Commit 7a1ed24

Browse files
committed
feat: add summary
1 parent d8486dc commit 7a1ed24

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

backend/src/main/java/ch/xxx/aidoclibchat/adapter/controller/SiteSummaryController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
package ch.xxx.aidoclibchat.adapter.controller;
1414

1515
import org.springframework.web.bind.annotation.GetMapping;
16+
import org.springframework.web.bind.annotation.PathVariable;
1617
import org.springframework.web.bind.annotation.RequestMapping;
1718
import org.springframework.web.bind.annotation.RestController;
1819

20+
import ch.xxx.aidoclibchat.domain.model.dto.SiteSummaryDto;
1921
import ch.xxx.aidoclibchat.usecase.service.SiteSummaryService;
2022

2123
@RestController
@@ -28,7 +30,7 @@ public SiteSummaryController(SiteSummaryService siteSummaryService) {
2830
}
2931

3032
@GetMapping("/joke-about/{topic}")
31-
public String getJokeAboutTopic(String topic) {
33+
public SiteSummaryDto getJokeAboutTopic(@PathVariable String topic) {
3234
return this.siteSummaryService.getJokeAboutTopic(topic);
3335
}
3436
}

backend/src/main/java/ch/xxx/aidoclibchat/adapter/controller/TableController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
@RestController
2929
@RequestMapping("rest/table")
3030
public class TableController {
31-
private TableMapper tableMapper;
32-
private TableService tableService;
31+
private final TableMapper tableMapper;
32+
private final TableService tableService;
3333

3434
public TableController(TableMapper tableMapper, TableService tableService) {
3535
this.tableMapper = tableMapper;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Record.java to edit this template
4+
*/
5+
6+
package ch.xxx.aidoclibchat.domain.model.dto;
7+
8+
/**
9+
*
10+
* @author sven
11+
*/
12+
public record SiteSummaryDto(String summary) { }

backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/SiteSummaryService.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,29 @@
1212
*/
1313
package ch.xxx.aidoclibchat.usecase.service;
1414

15+
import org.springframework.ai.chat.client.ChatClient;
16+
import org.springframework.ai.chat.client.ChatClient.Builder;
1517
import org.springframework.stereotype.Service;
1618

19+
import ch.xxx.aidoclibchat.domain.model.dto.SiteSummaryDto;
20+
1721
@Service
1822
public class SiteSummaryService {
19-
public String getJokeAboutTopic(String topic) {
20-
// Placeholder implementation
21-
return "Why did the " + topic + " go to the party? Because it wanted to have a blast!";
23+
private final ChatClient chatClient;
24+
25+
private final String promptStr = """
26+
Tell me a joke about the following topic and put in in the summary property.
27+
28+
Topic:
29+
30+
""";
31+
32+
public SiteSummaryService(Builder builder) {
33+
this.chatClient = builder.build();
34+
}
35+
36+
public SiteSummaryDto getJokeAboutTopic(String topic) {
37+
var result = this.chatClient.prompt(this.promptStr + topic).call().entity(SiteSummaryDto.class);
38+
return result;
2239
}
2340
}

0 commit comments

Comments
 (0)