Problema solucionado - Backend v1.2.6 / Frontend v1.2.8

Cambios implementados:

Frontend:
Ahora envía context_answers con todas las respuestas de preguntas anteriores (texto + observaciones)
Incluye el texto de la pregunta para mejor contexto
Funciona con la configuración de IDs de preguntas o todas las anteriores
Backend:
Recibe y procesa context_answers
Agrega sección "RESPUESTAS DE PREGUNTAS ANTERIORES" al system prompt
Muestra pregunta, respuesta y observaciones de cada pregunta previa
This commit is contained in:
2025-12-04 14:35:58 -03:00
parent 56decba945
commit 387897acfc
5 changed files with 40 additions and 4 deletions

View File

@@ -278,7 +278,7 @@ def extract_pdf_text_smart(pdf_content: bytes, max_chars: int = None) -> dict:
}
BACKEND_VERSION = "1.2.5"
BACKEND_VERSION = "1.2.6"
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
# S3/MinIO configuration
@@ -3417,6 +3417,7 @@ async def chat_with_ai_assistant(
user_message: str = Form(""),
chat_history: str = Form("[]"),
context_photos: str = Form("[]"),
context_answers: str = Form("[]"),
vehicle_info: str = Form("{}"),
assistant_prompt: str = Form(""),
assistant_instructions: str = Form(""),
@@ -3438,6 +3439,7 @@ async def chat_with_ai_assistant(
import json
chat_history_list = json.loads(chat_history)
context_photos_list = json.loads(context_photos)
context_answers_list = json.loads(context_answers)
vehicle_info_dict = json.loads(vehicle_info)
print(f"📋 Question ID: {question_id}")
@@ -3445,6 +3447,7 @@ async def chat_with_ai_assistant(
print(f"💬 User message: {user_message}")
print(f"📎 Attached files: {len(files)}")
print(f"📸 Context photos: {len(context_photos_list)} fotos")
print(f"📝 Context answers: {len(context_answers_list)} respuestas previas")
print(f"💭 Chat history: {len(chat_history_list)} mensajes previos")
# Procesar archivos adjuntos
@@ -3523,6 +3526,21 @@ INFORMACIÓN DEL VEHÍCULO:
status = analysis_text.get('status', 'unknown')
photos_context += f"\n{idx}. Pregunta ID {photo.get('questionId')}: Status={status}\n Observaciones: {obs[:200]}...\n"
# NUEVO: Construir contexto de respuestas de texto de preguntas anteriores
answers_context = ""
if context_answers_list:
answers_context = f"\n\nRESPUESTAS DE PREGUNTAS ANTERIORES ({len(context_answers_list)} respuestas):\n"
for idx, ans in enumerate(context_answers_list, 1):
question_text = ans.get('questionText', f"Pregunta {ans.get('questionId')}")
answer_value = ans.get('answer', '')
observations = ans.get('observations', '')
answers_context += f"\n{idx}. {question_text}\n"
if answer_value:
answers_context += f" Respuesta: {answer_value}\n"
if observations:
answers_context += f" Observaciones: {observations}\n"
# Definir la longitud de respuesta
max_tokens_map = {
'short': 200,
@@ -3559,6 +3577,8 @@ INFORMACIÓN DEL VEHÍCULO:
CONTEXTO DEL VEHÍCULO Y PREGUNTA:
{vehicle_context}
{answers_context}
{photos_context}
{attached_context}