49 lines
1.3 KiB
Java
49 lines
1.3 KiB
Java
package com.homme.demo.controller;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
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.service.RagService;
|
|
|
|
|
|
@CrossOrigin(origins = "${homme.cors.allowed-origins}")
|
|
@RestController
|
|
@RequestMapping("/chat")
|
|
public class ChatController {
|
|
|
|
@Autowired
|
|
private RagService ragService;
|
|
|
|
|
|
@PostMapping("/ask")
|
|
public AskResponse ask(@RequestParam String question) {
|
|
|
|
|
|
|
|
if (question == null || question.isBlank()) {
|
|
return AskResponse.builder()
|
|
.answer("Bitte stellen Sie eine Frage.")
|
|
.build();
|
|
}
|
|
|
|
return AskResponse.builder()
|
|
.answer(ragService.answerQuestion(question))
|
|
.build();
|
|
}
|
|
|
|
|
|
@GetMapping("/ask")
|
|
public AskResponse askGet(@RequestParam String question) {
|
|
|
|
return AskResponse.builder()
|
|
.answer(ragService.answerQuestion(question))
|
|
.build();
|
|
}
|
|
}
|