52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
package com.homme.demo.controller;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import com.homme.demo.dto.AskResponse;
|
|
import com.homme.demo.dto.ChatRequest;
|
|
import com.homme.demo.service.RagService;
|
|
|
|
|
|
@RestController
|
|
@RequestMapping("/chat")
|
|
public class ChatController {
|
|
|
|
@Autowired
|
|
private RagService ragService;
|
|
|
|
|
|
@PostMapping("/ask")
|
|
public AskResponse ask(@RequestBody ChatRequest request) {
|
|
|
|
String question = request.getMessage();
|
|
|
|
if (question == null || question.isBlank()) {
|
|
String warn = "Bitte stellen Sie eine Frage.";
|
|
return AskResponse.builder()
|
|
.answer(warn).reply(warn).message(warn)
|
|
.build();
|
|
}
|
|
|
|
String answer = ragService.answerQuestion(question, request.getHistory());
|
|
|
|
return AskResponse.builder()
|
|
.answer(answer).reply(answer).message(answer)
|
|
.build();
|
|
}
|
|
|
|
|
|
@GetMapping("/ask")
|
|
public AskResponse askGet(@RequestParam String question) {
|
|
|
|
return AskResponse.builder()
|
|
.answer(ragService.answerQuestion(question))
|
|
.build();
|
|
}
|
|
}
|