WordPress
This commit is contained in:
+6
-1
@@ -1,16 +1,21 @@
|
||||
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
|
||||
public class SearchController {
|
||||
@RequestMapping("/chat")
|
||||
public class ChatController {
|
||||
|
||||
@Autowired
|
||||
private RagService ragService;
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.homme.demo.controller;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.homme.demo.dto.ProcessedWordFileResponseDto;
|
||||
import com.homme.demo.service.HumbeeService;
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/knowledge-base")
|
||||
public class HumbeeController {
|
||||
|
||||
@Autowired
|
||||
private HumbeeService humbeeService;
|
||||
|
||||
@GetMapping("/build")
|
||||
public List<ProcessedWordFileResponseDto> buildKnowledgeBase() throws Exception {
|
||||
|
||||
return humbeeService.buildKnowledgeBase();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.homme.demo.service.WordPressIngestService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/ingestion")
|
||||
public class IngestController {
|
||||
|
||||
@Autowired
|
||||
private WordPressIngestService wordPressIngestService;
|
||||
|
||||
@GetMapping("/wordpress")
|
||||
public String ingestWordPressArticles(
|
||||
@RequestParam(defaultValue = "7") int days,
|
||||
@RequestParam(required = false) String site) {
|
||||
System.out.println("Scrapping");
|
||||
int saved = wordPressIngestService.ingestWordPressArticles(days, site);
|
||||
return saved + " neue Artikel gespeichert";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.homme.demo.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
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 org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.homme.demo.dto.ApiResponse;
|
||||
import com.homme.demo.dto.FileProcessedDto;
|
||||
import com.homme.demo.dto.UploadWordFileResponseDto;
|
||||
import com.homme.demo.input.ContentInput;
|
||||
import com.homme.demo.service.AzureSpeechService;
|
||||
import com.homme.demo.service.KnowledgeIngestService;
|
||||
import com.homme.demo.service.WordExportService;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/knowledge-base")
|
||||
public class KnowledgeIngestController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private WordExportService wordExportService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeIngestService knowledgeIngestService;
|
||||
|
||||
@Autowired
|
||||
private AzureSpeechService azureSpeechService;
|
||||
|
||||
|
||||
@GetMapping("/build")
|
||||
public List<ApiResponse<FileProcessedDto>> buildKnowledgeBase() throws Exception {
|
||||
return knowledgeIngestService.buildKnowledgeBase();
|
||||
}
|
||||
|
||||
@PostMapping("/transcription")
|
||||
public String transcribe(@RequestParam("file") MultipartFile file) throws IOException{
|
||||
|
||||
|
||||
|
||||
byte[] audioBytes = file.getBytes();
|
||||
String fileName = file.getOriginalFilename();
|
||||
return azureSpeechService.transcribe(audioBytes, fileName);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping(value = "/save-new-interview", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<ApiResponse<FileProcessedDto>> saveNewInterview(@ModelAttribute ContentInput contentInput ) {
|
||||
|
||||
|
||||
System.out.println("rrrr ");
|
||||
try {
|
||||
String rawText;
|
||||
|
||||
|
||||
if (contentInput.getFile() != null && !contentInput.getFile().isEmpty()) {
|
||||
rawText = wordExportService.leseDatei(contentInput.getFile());
|
||||
|
||||
|
||||
} else if (contentInput.getText() != null && !contentInput.getText().isBlank()) {
|
||||
rawText = contentInput.getText();
|
||||
|
||||
} else {
|
||||
return new ResponseEntity<>(ApiResponse.error("Bitte file oder text angeben."), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (rawText == null || rawText.isBlank()) {
|
||||
return new ResponseEntity<>(ApiResponse.error("Kein lesbarer Inhalt gefunden."), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
String title = (contentInput.getTitle() == null || contentInput.getTitle().isBlank())
|
||||
? "Anonymous" : contentInput.getTitle();
|
||||
|
||||
String city = (contentInput.getCity() == null|| contentInput.getCity().isBlank())
|
||||
? "Dortmund" : contentInput.getCity();
|
||||
|
||||
|
||||
|
||||
byte[] docx = wordExportService.createInterviewDocx(rawText);
|
||||
|
||||
String fileName = "%s_%s_%s.docx".formatted(LocalDate.now(),title.trim().replace(" ", "_"),city);
|
||||
|
||||
UploadWordFileResponseDto upload = knowledgeIngestService.uploadWordFile(fileName, docx);
|
||||
|
||||
if(!upload.isSuccess()) {
|
||||
|
||||
return new ResponseEntity<>(ApiResponse.error("Upload fehlgeschlagen: " +upload.getMessage()), HttpStatus.BAD_REQUEST);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ApiResponse<FileProcessedDto> processed = knowledgeIngestService.processOneFile(upload.getLink());
|
||||
return new ResponseEntity<>(processed, HttpStatus.CREATED);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(ApiResponse.error("Fehler beim Speichern: " +e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user