@@ -119,6 +119,7 @@ public class MessageEntryFilter {
|
||||
yield CATEGORY_UNKNOWN;
|
||||
}
|
||||
};
|
||||
resultCategory = CATEGORY_CONVERSATION;
|
||||
return resultCategory;
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred during Gemini content generation for message classification.", e);
|
||||
|
||||
@@ -161,8 +161,41 @@ public class ConversationManagerService {
|
||||
String userMessageText = request.queryInput().text().text();
|
||||
final ConversationContext context = new ConversationContext(resolvedUserId, null, userMessageText, primaryPhoneNumber);
|
||||
|
||||
return handleMessageClassification(context, request);
|
||||
}
|
||||
|
||||
private Mono<DetectIntentResponseDTO> handleMessageClassification(ConversationContext context,
|
||||
DetectIntentRequestDTO request) {
|
||||
final String userPhoneNumber = context.primaryPhoneNumber();
|
||||
final String userMessageText = context.userMessageText();
|
||||
|
||||
return memoryStoreConversationService.getSessionByTelefono(userPhoneNumber)
|
||||
.flatMap(session -> memoryStoreConversationService.getMessages(session.sessionId()).collectList()
|
||||
.map(conversationContextMapper::toTextFromMessages)
|
||||
.defaultIfEmpty("")
|
||||
.flatMap(conversationHistory -> {
|
||||
return memoryStoreNotificationService.getNotificationIdForPhone(userPhoneNumber)
|
||||
.flatMap(notificationId -> memoryStoreNotificationService
|
||||
.getCachedNotificationSession(notificationId))
|
||||
.map(notificationSession -> notificationSession.notificaciones().stream()
|
||||
.filter(notification -> "active".equalsIgnoreCase(notification.status()))
|
||||
.max(java.util.Comparator.comparing(NotificationDTO::timestampCreacion))
|
||||
.orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap((NotificationDTO notification) -> {
|
||||
String notificationText = notificationContextMapper.toText(notification);
|
||||
String classification = messageEntryFilter.classifyMessage(userMessageText,
|
||||
notificationText, conversationHistory);
|
||||
if (MessageEntryFilter.CATEGORY_NOTIFICATION.equals(classification)) {
|
||||
return startNotificationConversation(context, request, notification);
|
||||
} else {
|
||||
return continueConversationFlow(context, request);
|
||||
}
|
||||
})
|
||||
.switchIfEmpty(continueConversationFlow(context, request));
|
||||
}))
|
||||
.switchIfEmpty(continueConversationFlow(context, request));
|
||||
}
|
||||
|
||||
private Mono<DetectIntentResponseDTO> continueConversationFlow(ConversationContext context,
|
||||
DetectIntentRequestDTO request) {
|
||||
@@ -324,6 +357,7 @@ public class ConversationManagerService {
|
||||
String resolvedContext = notificationContextResolver.resolveContext(userMessageText,
|
||||
notificationText, conversationHistory, filteredParams.toString(), userId, sessionId,
|
||||
userPhoneNumber);
|
||||
|
||||
if (!resolvedContext.trim().toUpperCase().contains(NotificationContextResolver.CATEGORY_DIALOGFLOW)) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
llmResponseTunerService.setValue(uuid, resolvedContext).subscribe();
|
||||
|
||||
Reference in New Issue
Block a user