Seventh Commit
This commit is contained in:
+2
-5
@@ -7,9 +7,6 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "9192:9192"
|
- "9192:9192"
|
||||||
environment:
|
|
||||||
- DB_PASSWORD=Neu2026!
|
|
||||||
- HUMBEE_PASSWORD=Neu2026!
|
|
||||||
- AZURE_EMBEDDING_KEY=7QT99mzRAZEYTH9aETqPfNZ15637VSpe6POp9y3C1gCGbhg85dMHJQQJ99CFACPV0roXJ3w3AAAAACOGvNH3
|
|
||||||
- OPENAI_API_MISTRAL_KEY=7QT99mzRAZEYTH9aETqPfNZ15637VSpe6POp9y3C1gCGbhg85dMHJQQJ99CFACPV0roXJ3w3AAAAACOGvNH3
|
|
||||||
|
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -7,26 +7,24 @@ import java.util.List;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import com.homme.demo.dto.ProcessedWordFileResponseDto;
|
import com.homme.demo.dto.ProcessedWordFileResponseDto;
|
||||||
import com.homme.demo.service.HumbeeService;
|
import com.homme.demo.service.HumbeeService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RestController("humbee")
|
@RestController
|
||||||
|
@RequestMapping("/knowledge-base")
|
||||||
public class HumbeeController {
|
public class HumbeeController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private HumbeeService humbeeService;
|
private HumbeeService humbeeService;
|
||||||
|
|
||||||
|
@GetMapping("/build")
|
||||||
|
public List<ProcessedWordFileResponseDto> buildKnowledgeBase() throws Exception {
|
||||||
|
|
||||||
@GetMapping("/word-links")
|
|
||||||
public List<ProcessedWordFileResponseDto> getWordLinks() throws Exception {
|
|
||||||
|
|
||||||
return humbeeService.getWordLinks();
|
return humbeeService.buildKnowledgeBase();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ package com.homme.demo.controller;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.homme.demo.dto.AskResponse;
|
import com.homme.demo.dto.AskResponse;
|
||||||
import com.homme.demo.input.AskRequest;
|
|
||||||
import com.homme.demo.service.RagService;
|
import com.homme.demo.service.RagService;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -19,9 +17,9 @@ public class SearchController {
|
|||||||
|
|
||||||
|
|
||||||
@PostMapping("/ask")
|
@PostMapping("/ask")
|
||||||
public AskResponse ask(@RequestBody AskRequest request) {
|
public AskResponse ask(@RequestParam String question) {
|
||||||
|
|
||||||
String question = (request == null) ? null : request.getQuestion();
|
|
||||||
|
|
||||||
if (question == null || question.isBlank()) {
|
if (question == null || question.isBlank()) {
|
||||||
return AskResponse.builder()
|
return AskResponse.builder()
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.homme.demo.input;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request body for the chatbot endpoint: { "question": "..." }.
|
|
||||||
*/
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
public class AskRequest {
|
|
||||||
|
|
||||||
private String question;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -16,8 +16,8 @@ public class DocumentChunckService {
|
|||||||
if(text == null || text.isBlank())
|
if(text == null || text.isBlank())
|
||||||
return chunks;
|
return chunks;
|
||||||
|
|
||||||
int chunkSize = 6000;
|
int chunkSize = 1200;
|
||||||
int overlab = 200;
|
int overlab = 150;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
|
||||||
while(start < text.length()) {
|
while(start < text.length()) {
|
||||||
|
|||||||
@@ -73,13 +73,13 @@ public class HumbeeService {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
public List<ProcessedWordFileResponseDto> getWordLinks() throws Exception{
|
public List<ProcessedWordFileResponseDto> buildKnowledgeBase() throws Exception{
|
||||||
|
|
||||||
login();
|
login();
|
||||||
String json = getDiroctoryJson();
|
String json = getDiroctoryJson();
|
||||||
List<String> links = extractWordLinks(json);
|
List<String> links = extractWordLinks(json);
|
||||||
|
int numFiles = 0;
|
||||||
|
int numFilesResult =0;
|
||||||
ExecutorService pool = Executors.newFixedThreadPool(6);
|
ExecutorService pool = Executors.newFixedThreadPool(6);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class HumbeeService {
|
|||||||
|
|
||||||
for(String link :links) {
|
for(String link :links) {
|
||||||
|
|
||||||
|
numFiles++;
|
||||||
futures.add(pool.submit(() -> processOneFile(link)));
|
futures.add(pool.submit(() -> processOneFile(link)));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -95,6 +95,7 @@ public class HumbeeService {
|
|||||||
|
|
||||||
for(Future<ProcessedWordFileResponseDto> f: futures) {
|
for(Future<ProcessedWordFileResponseDto> f: futures) {
|
||||||
|
|
||||||
|
numFilesResult++;
|
||||||
result.add(f.get());
|
result.add(f.get());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -104,6 +105,7 @@ public class HumbeeService {
|
|||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new RuntimeException("Fehler bei paralleler Dateiverarbeitung: " + e.getMessage());
|
throw new RuntimeException("Fehler bei paralleler Dateiverarbeitung: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
System.out.println("$$$$$$$$ ="+links.size()+" numFiles = "+numFiles +" numFilesResult= "+ numFilesResult);
|
||||||
pool.shutdown();
|
pool.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +154,6 @@ public class HumbeeService {
|
|||||||
public void login() {
|
public void login() {
|
||||||
|
|
||||||
String loginPath = "/account/login";
|
String loginPath = "/account/login";
|
||||||
|
|
||||||
sessionCookies.clear();
|
sessionCookies.clear();
|
||||||
Map<String, String> requestBody = new HashMap<>();
|
Map<String, String> requestBody = new HashMap<>();
|
||||||
requestBody.put("email", email);
|
requestBody.put("email", email);
|
||||||
@@ -165,7 +166,6 @@ public class HumbeeService {
|
|||||||
.bodyValue(requestBody)
|
.bodyValue(requestBody)
|
||||||
.exchangeToMono(res -> Mono.just(res))
|
.exchangeToMono(res -> Mono.just(res))
|
||||||
.block();
|
.block();
|
||||||
System.out.println("response = "+response);
|
|
||||||
|
|
||||||
if(response == null) {
|
if(response == null) {
|
||||||
throw new RuntimeException("Anmeldung fehlgeschlagen: Keine Antwort vom Server.");
|
throw new RuntimeException("Anmeldung fehlgeschlagen: Keine Antwort vom Server.");
|
||||||
@@ -213,7 +213,7 @@ public class HumbeeService {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public List<String> extractWordLinks(String json) throws Exception{
|
public List<String> extractWordLinks(String json) throws Exception{
|
||||||
|
|
||||||
List<String> links = new ArrayList<>();
|
List<String> links = new ArrayList<>();
|
||||||
@@ -231,7 +231,8 @@ public class HumbeeService {
|
|||||||
for(JsonNode action: quickActions) {
|
for(JsonNode action: quickActions) {
|
||||||
String id = action.path("id").asText();
|
String id = action.path("id").asText();
|
||||||
String href = action.path("href").asText();
|
String href = action.path("href").asText();
|
||||||
if("download".equals(id) && (href.contains(".docx?") || href.contains(".doc?"))) {
|
|
||||||
|
if("download".equals(id) && (href.contains(".docx?") || href.contains(".doc?") || href.contains(".txt"))) {
|
||||||
links.add("https://cloud.humbee.de"+href);
|
links.add("https://cloud.humbee.de"+href);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -278,6 +279,11 @@ public class HumbeeService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(downloadHref.contains(".txt")){
|
||||||
|
|
||||||
|
return decodeBytes(fileBytes);
|
||||||
|
|
||||||
|
}
|
||||||
throw new RuntimeException("Nicht unterstützer Dateityp");
|
throw new RuntimeException("Nicht unterstützer Dateityp");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -287,6 +293,26 @@ public class HumbeeService {
|
|||||||
throw new RuntimeException("Nicht angeledet. Bitte zuerst einloggen.");
|
throw new RuntimeException("Nicht angeledet. Bitte zuerst einloggen.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String decodeBytes(byte[] bytes) {
|
||||||
|
if (bytes == null || bytes.length == 0) return "";
|
||||||
|
|
||||||
|
|
||||||
|
if (bytes.length >= 3 && (bytes[0]&0xFF)==0xEF && (bytes[1]&0xFF)==0xBB && (bytes[2]&0xFF)==0xBF)
|
||||||
|
return new String(bytes, 3, bytes.length-3, java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
if (bytes.length >= 2 && (bytes[0]&0xFF)==0xFF && (bytes[1]&0xFF)==0xFE)
|
||||||
|
return new String(bytes, 2, bytes.length-2, java.nio.charset.StandardCharsets.UTF_16LE);
|
||||||
|
if (bytes.length >= 2 && (bytes[0]&0xFF)==0xFE && (bytes[1]&0xFF)==0xFF)
|
||||||
|
return new String(bytes, 2, bytes.length-2, java.nio.charset.StandardCharsets.UTF_16BE);
|
||||||
|
|
||||||
|
int nulls = 0;
|
||||||
|
for (int i = 1; i < Math.min(bytes.length, 400); i += 2)
|
||||||
|
if (bytes[i] == 0) nulls++;
|
||||||
|
if (nulls > 50)
|
||||||
|
return new String(bytes, java.nio.charset.StandardCharsets.UTF_16LE);
|
||||||
|
|
||||||
|
return new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ spring.application.name=Homme
|
|||||||
# Load secrets from .env (classpath) so ${DB_PASSWORD}, ${HUMBEE_PASSWORD},
|
# Load secrets from .env (classpath) so ${DB_PASSWORD}, ${HUMBEE_PASSWORD},
|
||||||
# ${AZURE_EMBEDDING_KEY}, ${OPENAI_API_MISTRAL_KEY} below resolve from it.
|
# ${AZURE_EMBEDDING_KEY}, ${OPENAI_API_MISTRAL_KEY} below resolve from it.
|
||||||
# "optional:" => app still starts if .env is absent (e.g. secrets come from real env vars).
|
# "optional:" => app still starts if .env is absent (e.g. secrets come from real env vars).
|
||||||
#spring.config.import=optional:classpath:/.env[.properties]
|
spring.config.import=optional:classpath:/.env[.properties]
|
||||||
|
|
||||||
server.port =9192
|
server.port =9192
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user