From 24cebae2e3533923d756bfc1140f54359515ec77 Mon Sep 17 00:00:00 2001 From: KARLA ITZEL SALADO Date: Thu, 8 Jan 2026 00:34:37 +0000 Subject: [PATCH] Correccion error 500 --- Dockerfile | 22 ++++---- .../ConversationMessageMapper.java | 10 +++- .../ConversationManagerService.java | 23 ++++---- src/main/resources/application-dev.properties | 55 ++++++++++--------- .../resources/application-prod.properties | 8 +-- src/main/resources/application-qa.properties | 8 +-- src/main/resources/application.properties | 2 +- 7 files changed, 71 insertions(+), 57 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3711dc0..df646be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ +# Copyright 2025 Google. This software is provided as-is, without warranty or representation for any use or purpose. +# Your use of it is subject to your agreement with Google. + # Java 21.0.6 # 'jammy' refers to Ubuntu 22.04 LTS, which is a stable and widely used base. -# FROM maven:3.9.6-eclipse-temurin-21 AS builder -# FROM quay.ocp.banorte.com/base/openjdk-21:maven_3.8 AS builder -# WORKDIR /app -# COPY pom.xml . -# COPY src ./src -# RUN mvn -B clean install -DskipTests -Dmaven.javadoc.skip=true -# FROM eclipse-temurin:21.0.3_9-jre-jammy -FROM quay.ocp.banorte.com/golden/openjdk-21:latest -# COPY --from=builder /app/target/app-jovenes-service-orchestrator-0.0.1-SNAPSHOT.jar app.jar -COPY target/app-jovenes-service-orchestrator-0.0.1-SNAPSHOT.jar app.jar +FROM maven:3.9.6-eclipse-temurin-21 AS builder +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn -B clean install -DskipTests -Dmaven.javadoc.skip=true +FROM registry.access.redhat.com/ubi9/openjdk-21-runtime +COPY --from=builder /app/target/app-jovenes-service-orchestrator-0.0.1-SNAPSHOT.jar app.jar EXPOSE 8080 -ENTRYPOINT ["java", "-jar", "app.jar"] +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java b/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java index 38c37bb..ec167c1 100644 --- a/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java +++ b/src/main/java/com/example/mapper/conversation/ConversationMessageMapper.java @@ -4,6 +4,7 @@ */ package com.example.mapper.conversation; +import com.google.cloud.Timestamp; import com.example.dto.dialogflow.conversation.ConversationMessageDTO; import com.example.dto.dialogflow.conversation.MessageType; @@ -31,9 +32,16 @@ public class ConversationMessageMapper { } public ConversationMessageDTO fromMap(Map map) { + Object timeObject = map.get("tiempo"); + Instant timestamp = null; + if (timeObject instanceof Timestamp) { + timestamp = ((Timestamp) timeObject).toDate().toInstant(); + } else if (timeObject instanceof Instant) { + timestamp = (Instant) timeObject; + } return new ConversationMessageDTO( MessageType.valueOf((String) map.get("entidad")), - (Instant) map.get("tiempo"), + timestamp, (String) map.get("mensaje"), (Map) map.get("parametros"), (String) map.get("canal") diff --git a/src/main/java/com/example/service/conversation/ConversationManagerService.java b/src/main/java/com/example/service/conversation/ConversationManagerService.java index cd646b5..d2a5d80 100644 --- a/src/main/java/com/example/service/conversation/ConversationManagerService.java +++ b/src/main/java/com/example/service/conversation/ConversationManagerService.java @@ -239,22 +239,25 @@ public class ConversationManagerService { DetectIntentRequestDTO request, ConversationSessionDTO session) { Instant now = Instant.now(); if (Duration.between(session.lastModified(), now).toMinutes() < SESSION_RESET_THRESHOLD_MINUTES) { - logger.info("Recent Session Found: Session {} is within the 10-minute threshold. Proceeding to Dialogflow.", + logger.info("Recent Session Found: Session {} is within the 30-minute threshold. Proceeding to Dialogflow.", session.sessionId()); return processDialogflowRequest(session, request, context.userId(), context.userMessageText(), context.primaryPhoneNumber(), false); } else { logger.info( - "Old Session Found: Session {} is older than the threshold. Fetching history and continuing with same session.", + "Old Session Found: Session {} is older than the 30-minute threshold. Fetching history and continuing with same session.", session.sessionId()); - return memoryStoreConversationService.getMessages(session.sessionId()).collectList() - .map(conversationContextMapper::toTextFromMessages) - .defaultIfEmpty("") - .flatMap(conversationHistory -> { - DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory); - return processDialogflowRequest(session, newRequest, context.userId(), context.userMessageText(), - context.primaryPhoneNumber(), false); - }); + return memoryStoreConversationService.getMessages(session.sessionId()) + .collectList() + // Adding use the TextWithLimits to truncate according to business rule 30 days/60 messages + .map(messages -> conversationContextMapper.toTextWithLimits(session, messages)) + .defaultIfEmpty("") + .flatMap(conversationHistory -> { + // Inject historial (max 60 msgs / 30 días / 50KB) + DetectIntentRequestDTO newRequest = request.withParameter(CONV_HISTORY_PARAM, conversationHistory); + return processDialogflowRequest(session, newRequest, context.userId(), context.userMessageText(), + context.primaryPhoneNumber(), false); + }); } } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 513f673..896c348 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -17,62 +17,65 @@ # ========================================================= # Orchestrator general Configuration # ========================================================= -spring.cloud.gcp.project-id=${GCP_PROJECT_ID} +spring.cloud.gcp.project-id=app-jovenes # ========================================================= # Google Firestore Configuration # ========================================================= -spring.cloud.gcp.firestore.project-id=${GCP_PROJECT_ID} -spring.cloud.gcp.firestore.database-id=${GCP_FIRESTORE_DATABASE_ID} -spring.cloud.gcp.firestore.host=${GCP_FIRESTORE_HOST} -spring.cloud.gcp.firestore.port=${GCP_FIRESTORE_PORT} +spring.cloud.gcp.firestore.project-id=app-jovenes +spring.cloud.gcp.firestore.database-id=app-jovenes-cache-database +spring.cloud.gcp.firestore.host=firestore.googleapis.com +spring.cloud.gcp.firestore.port=443 # ========================================================= # Google Memorystore(Redis) Configuration # ========================================================= -spring.data.redis.host=${REDIS_HOST} -spring.data.redis.port=${REDIS_PORT} -#spring.data.redis.password=${REDIS_PWD} +spring.data.redis.host=10.241.0.11 +spring.data.redis.port=6379 +#spring.data.redis.password=23cb4c76-9d96-4c74-b8c0-778fb364877a #spring.data.redis.username=default # SSL Configuration (if using SSL) # spring.data.redis.ssl=true # spring.data.redis.ssl.key-store=classpath:keystore.p12 -# spring.data.redis.ssl.key-store-password=${REDIS_KEY_PWD} +# spring.data.redis.ssl.key-store-password=your-keystore-password # ========================================================= # Google Conversational Agents Configuration +# beto-singlerag-contexto # ========================================================= -dialogflow.cx.project-id=${DIALOGFLOW_CX_PROJECT_ID} -dialogflow.cx.location=${DIALOGFLOW_CX_LOCATION} -dialogflow.cx.agent-id=${DIALOGFLOW_CX_AGENT_ID} -dialogflow.default-language-code=${DIALOGFLOW_DEFAULT_LANGUAGE_CODE} +dialogflow.cx.project-id=app-jovenes +dialogflow.cx.location=us-central1 +dialogflow.cx.agent-id=d55333d2-9543-4f9c-bd7a-d0ee3b3573ac +dialogflow.default-language-code=es # ========================================================= # Google Generative AI (Gemini) Configuration # ========================================================= -google.cloud.project=${GCP_PROJECT_ID} -google.cloud.location=${GCP_LOCATION} -gemini.model.name=${GEMINI_MODEL_NAME} +google.cloud.project=app-jovenes +google.cloud.location=us-central1 +gemini.model.name=gemini-2.5-flash # ========================================================= # (Gemini) MessageFilter Configuration # ========================================================= -messagefilter.geminimodel=${MESSAGE_FILTER_GEMINI_MODEL} -messagefilter.temperature=${MESSAGE_FILTER_TEMPERATURE} -messagefilter.maxOutputTokens=${MESSAGE_FILTER_MAX_OUTPUT_TOKENS} -messagefilter.topP=${MESSAGE_FILTER_TOP_P} +messagefilter.geminimodel=gemini-2.5-flash +messagefilter.temperature=0.1f +messagefilter.maxOutputTokens=800 +messagefilter.topP= 0.1f messagefilter.prompt=prompts/message_filter_prompt.txt # ========================================================= # (DLP) Configuration # ========================================================= -google.cloud.dlp.dlpTemplateCompleteFlow=${DLP_TEMPLATE_COMPLETE_FLOW} +google.cloud.dlp.dlpTemplateCompleteFlow=BNET_INSPECT # ========================================================= # Quick-replies Preset-data # ========================================================= -firestore.data.importer.enabled=${GCP_FIRESTORE_IMPORTER_ENABLE} +firestore.data.importer.enabled=false # ========================================================= # LOGGING Configuration # ========================================================= -logging.level.root=${LOGGING_LEVEL_ROOT:INFO} -logging.level.com.example=${LOGGING_LEVEL_COM_EXAMPLE:INFO} +logging.level.root=INFO +logging.level.com.example=INFO # ========================================================= # ConversationContext Configuration # ========================================================= -conversation.context.message.limit=${CONVERSATION_CONTEXT_MESSAGE_LIMIT} -conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} \ No newline at end of file +conversation.context.message.limit=60 +conversation.context.days.limit=30 +# logs for dev inspection +logging.file.name=logs/orchestrator.log diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index dea84f3..130ef3e 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -30,13 +30,13 @@ spring.cloud.gcp.firestore.port=${GCP_FIRESTORE_PORT} # ========================================================= spring.data.redis.host=${REDIS_HOST} spring.data.redis.port=${REDIS_PORT} -#spring.data.redis.password=${REDIS_PWD} +#spring.data.redis.password=23cb4c76-9d96-4c74-b8c0-778fb364877a #spring.data.redis.username=default # SSL Configuration (if using SSL) # spring.data.redis.ssl=true # spring.data.redis.ssl.key-store=classpath:keystore.p12 -# spring.data.redis.ssl.key-store-password=${REDIS_KEY_PWD} +# spring.data.redis.ssl.key-store-password=your-keystore-password # ========================================================= # Google Conversational Agents Configuration # ========================================================= @@ -66,7 +66,7 @@ google.cloud.dlp.dlpTemplatePersistFlow=${DLP_TEMPLATE_PERSIST_FLOW} # ========================================================= # Quick-replies Preset-data # ========================================================= -firestore.data.importer.enabled=${GCP_FIRESTORE_IMPORTER_ENABLE} +firestore.data.importer.enabled=true # ========================================================= # LOGGING Configuration # ========================================================= @@ -76,4 +76,4 @@ logging.level.com.example=${LOGGING_LEVEL_COM_EXAMPLE:INFO} # ConversationContext Configuration # ========================================================= conversation.context.message.limit=${CONVERSATION_CONTEXT_MESSAGE_LIMIT} -conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} \ No newline at end of file +conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} diff --git a/src/main/resources/application-qa.properties b/src/main/resources/application-qa.properties index dea84f3..130ef3e 100644 --- a/src/main/resources/application-qa.properties +++ b/src/main/resources/application-qa.properties @@ -30,13 +30,13 @@ spring.cloud.gcp.firestore.port=${GCP_FIRESTORE_PORT} # ========================================================= spring.data.redis.host=${REDIS_HOST} spring.data.redis.port=${REDIS_PORT} -#spring.data.redis.password=${REDIS_PWD} +#spring.data.redis.password=23cb4c76-9d96-4c74-b8c0-778fb364877a #spring.data.redis.username=default # SSL Configuration (if using SSL) # spring.data.redis.ssl=true # spring.data.redis.ssl.key-store=classpath:keystore.p12 -# spring.data.redis.ssl.key-store-password=${REDIS_KEY_PWD} +# spring.data.redis.ssl.key-store-password=your-keystore-password # ========================================================= # Google Conversational Agents Configuration # ========================================================= @@ -66,7 +66,7 @@ google.cloud.dlp.dlpTemplatePersistFlow=${DLP_TEMPLATE_PERSIST_FLOW} # ========================================================= # Quick-replies Preset-data # ========================================================= -firestore.data.importer.enabled=${GCP_FIRESTORE_IMPORTER_ENABLE} +firestore.data.importer.enabled=true # ========================================================= # LOGGING Configuration # ========================================================= @@ -76,4 +76,4 @@ logging.level.com.example=${LOGGING_LEVEL_COM_EXAMPLE:INFO} # ConversationContext Configuration # ========================================================= conversation.context.message.limit=${CONVERSATION_CONTEXT_MESSAGE_LIMIT} -conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} \ No newline at end of file +conversation.context.days.limit=${CONVERSATION_CONTEXT_DAYS_LIMIT} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 404a33d..257b306 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -spring.profiles.active=${SPRING_PROFILE} \ No newline at end of file +spring.profiles.active=dev \ No newline at end of file