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}

View File

@@ -1,7 +1,7 @@
{
"name": "checklist-frontend",
"private": true,
"version": "1.2.7",
"version": "1.2.8",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,6 +1,6 @@
// Service Worker para PWA con detección de actualizaciones
// IMPORTANTE: Actualizar esta versión cada vez que se despliegue una nueva versión
const CACHE_NAME = 'ayutec-v1.2.7';
const CACHE_NAME = 'ayutec-v1.2.8';
const urlsToCache = [
'/',
'/index.html'

View File

@@ -5632,6 +5632,7 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM
// Recopilar fotos de preguntas anteriores según configuración
const contextPhotos = []
const contextAnswers = [] // NUEVO: respuestas de texto de preguntas anteriores
const contextQuestionIds = config.context_questions
? config.context_questions.split(',').map(id => parseInt(id.trim()))
: Object.keys(allAnswers).map(id => parseInt(id))
@@ -5641,6 +5642,8 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM
previousQuestionIds.forEach(qId => {
const answer = allAnswers[qId]
// Agregar fotos si existen
if (answer?.photos && answer.photos.length > 0) {
answer.photos.forEach(photoUrl => {
contextPhotos.push({
@@ -5650,9 +5653,22 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM
})
})
}
// NUEVO: Agregar respuestas de texto (incluyendo observations)
if (answer?.value || answer?.observations) {
// Buscar la pregunta para obtener su texto
const questionData = inspection.checklist.questions.find(q => q.id === qId)
contextAnswers.push({
questionId: qId,
questionText: questionData?.text || `Pregunta ${qId}`,
answer: answer.value || '',
observations: answer.observations || ''
})
}
})
formData.append('context_photos', JSON.stringify(contextPhotos))
formData.append('context_answers', JSON.stringify(contextAnswers)) // NUEVO
formData.append('vehicle_info', JSON.stringify({
brand: inspection.vehicle_brand,
model: inspection.vehicle_model,

View File

@@ -153,7 +153,7 @@ export default function Sidebar({ user, activeTab, setActiveTab, sidebarOpen, se
className="w-10 h-10 object-contain bg-white rounded p-1"
/>
<p className="text-xs text-indigo-300 font-medium hover:text-indigo-200">
Ayutec v1.2.7
Ayutec v1.2.8
</p>
</a>
</div>