chat-log-build
This commit is contained in:
@@ -21,7 +21,7 @@ public class HommeApplication {
|
|||||||
private AzureWebSearchAgentService azureWebSearchAgentService;
|
private AzureWebSearchAgentService azureWebSearchAgentService;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Main hömme");
|
|
||||||
SpringApplication.run(HommeApplication.class, args);
|
SpringApplication.run(HommeApplication.class, args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.homme.demo.entity;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "chat_log")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ChatLog {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String question;
|
||||||
|
|
||||||
|
@Column(columnDefinition = "TEXT")
|
||||||
|
private String answer;
|
||||||
|
|
||||||
|
private Double bestDistance;
|
||||||
|
|
||||||
|
private Boolean usedWeb;
|
||||||
|
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.homme.demo.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.homme.demo.entity.ChatLog;
|
||||||
|
|
||||||
|
public interface ChatLogRepository extends JpaRepository<ChatLog, Integer> {
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
package com.homme.demo.service;
|
package com.homme.demo.service;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.homme.demo.entity.ChatLog;
|
||||||
import com.homme.demo.entity.DocumentChunck;
|
import com.homme.demo.entity.DocumentChunck;
|
||||||
|
import com.homme.demo.repository.ChatLogRepository;
|
||||||
import com.homme.demo.repository.DocumentChunckRepository;
|
import com.homme.demo.repository.DocumentChunckRepository;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +30,9 @@ public class RagService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private DocumentChunckRepository documentChunckRepository;
|
private DocumentChunckRepository documentChunckRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ChatLogRepository chatLogRepository;
|
||||||
|
|
||||||
private static final double DISTANCE_THRESHOULD = 0.68;
|
private static final double DISTANCE_THRESHOULD = 0.68;
|
||||||
|
|
||||||
// ===== system: Rolle, Ton und Regeln (statisch) =====
|
// ===== system: Rolle, Ton und Regeln (statisch) =====
|
||||||
@@ -101,7 +107,7 @@ public class RagService {
|
|||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional
|
||||||
public String answerQuestion(String question) {
|
public String answerQuestion(String question) {
|
||||||
|
|
||||||
long t1 = System.currentTimeMillis();
|
long t1 = System.currentTimeMillis();
|
||||||
@@ -121,9 +127,10 @@ public class RagService {
|
|||||||
String webResults = "Kein Webkontext verfuegbar." ;
|
String webResults = "Kein Webkontext verfuegbar." ;
|
||||||
|
|
||||||
boolean hatRelevantenKontext = false;
|
boolean hatRelevantenKontext = false;
|
||||||
|
Double bestDistance = null;
|
||||||
if(!rows.isEmpty()) {
|
if(!rows.isEmpty()) {
|
||||||
|
|
||||||
double bestDistance = ((Number) rows.get(0)[1]).doubleValue();
|
bestDistance = ((Number) rows.get(0)[1]).doubleValue();
|
||||||
hatRelevantenKontext = bestDistance <= DISTANCE_THRESHOULD;
|
hatRelevantenKontext = bestDistance <= DISTANCE_THRESHOULD;
|
||||||
System.out.println("bestDistance "+ bestDistance+ " hatRelevantenKontext "+hatRelevantenKontext);
|
System.out.println("bestDistance "+ bestDistance+ " hatRelevantenKontext "+hatRelevantenKontext);
|
||||||
|
|
||||||
@@ -173,9 +180,22 @@ public class RagService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
long t2 = System.currentTimeMillis();
|
long t2 = System.currentTimeMillis();
|
||||||
String answer = azureMistralService.askMistral(SYSTEM_PROMPT, userPrompt, 250);
|
String answer = azureMistralService.askMistral(SYSTEM_PROMPT, userPrompt, 800);
|
||||||
System.out.println("Mistarl = "+ (System.currentTimeMillis() - t2)+ "ms");
|
System.out.println("Mistarl = "+ (System.currentTimeMillis() - t2)+ "ms");
|
||||||
|
|
||||||
|
Double roundedDistance = (bestDistance == null)
|
||||||
|
? null
|
||||||
|
: Math.round(bestDistance * 100.0) / 100.0;
|
||||||
|
|
||||||
|
ChatLog log = ChatLog.builder()
|
||||||
|
.question(question)
|
||||||
|
.answer(answer)
|
||||||
|
.bestDistance(roundedDistance)
|
||||||
|
.usedWeb(!hatRelevantenKontext)
|
||||||
|
.createdAt(LocalDateTime.now())
|
||||||
|
.build();
|
||||||
|
chatLogRepository.save(log);
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user