@@ -119,6 +119,7 @@ public class MessageEntryFilter {
|
|||||||
yield CATEGORY_UNKNOWN;
|
yield CATEGORY_UNKNOWN;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
resultCategory = CATEGORY_CONVERSATION;
|
||||||
return resultCategory;
|
return resultCategory;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("An error occurred during Gemini content generation for message classification.", e);
|
logger.error("An error occurred during Gemini content generation for message classification.", e);
|
||||||
|
|||||||
@@ -161,7 +161,40 @@ public class ConversationManagerService {
|
|||||||
String userMessageText = request.queryInput().text().text();
|
String userMessageText = request.queryInput().text().text();
|
||||||
final ConversationContext context = new ConversationContext(resolvedUserId, null, userMessageText, primaryPhoneNumber);
|
final ConversationContext context = new ConversationContext(resolvedUserId, null, userMessageText, primaryPhoneNumber);
|
||||||
|
|
||||||
return continueConversationFlow(context, request);
|
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,
|
private Mono<DetectIntentResponseDTO> continueConversationFlow(ConversationContext context,
|
||||||
@@ -324,6 +357,7 @@ public class ConversationManagerService {
|
|||||||
String resolvedContext = notificationContextResolver.resolveContext(userMessageText,
|
String resolvedContext = notificationContextResolver.resolveContext(userMessageText,
|
||||||
notificationText, conversationHistory, filteredParams.toString(), userId, sessionId,
|
notificationText, conversationHistory, filteredParams.toString(), userId, sessionId,
|
||||||
userPhoneNumber);
|
userPhoneNumber);
|
||||||
|
|
||||||
if (!resolvedContext.trim().toUpperCase().contains(NotificationContextResolver.CATEGORY_DIALOGFLOW)) {
|
if (!resolvedContext.trim().toUpperCase().contains(NotificationContextResolver.CATEGORY_DIALOGFLOW)) {
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
llmResponseTunerService.setValue(uuid, resolvedContext).subscribe();
|
llmResponseTunerService.setValue(uuid, resolvedContext).subscribe();
|
||||||
|
|||||||
Reference in New Issue
Block a user