✅ 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:
@@ -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)
|
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
|
||||||
|
|
||||||
# S3/MinIO configuration
|
# S3/MinIO configuration
|
||||||
@@ -3417,6 +3417,7 @@ async def chat_with_ai_assistant(
|
|||||||
user_message: str = Form(""),
|
user_message: str = Form(""),
|
||||||
chat_history: str = Form("[]"),
|
chat_history: str = Form("[]"),
|
||||||
context_photos: str = Form("[]"),
|
context_photos: str = Form("[]"),
|
||||||
|
context_answers: str = Form("[]"),
|
||||||
vehicle_info: str = Form("{}"),
|
vehicle_info: str = Form("{}"),
|
||||||
assistant_prompt: str = Form(""),
|
assistant_prompt: str = Form(""),
|
||||||
assistant_instructions: str = Form(""),
|
assistant_instructions: str = Form(""),
|
||||||
@@ -3438,6 +3439,7 @@ async def chat_with_ai_assistant(
|
|||||||
import json
|
import json
|
||||||
chat_history_list = json.loads(chat_history)
|
chat_history_list = json.loads(chat_history)
|
||||||
context_photos_list = json.loads(context_photos)
|
context_photos_list = json.loads(context_photos)
|
||||||
|
context_answers_list = json.loads(context_answers)
|
||||||
vehicle_info_dict = json.loads(vehicle_info)
|
vehicle_info_dict = json.loads(vehicle_info)
|
||||||
|
|
||||||
print(f"📋 Question ID: {question_id}")
|
print(f"📋 Question ID: {question_id}")
|
||||||
@@ -3445,6 +3447,7 @@ async def chat_with_ai_assistant(
|
|||||||
print(f"💬 User message: {user_message}")
|
print(f"💬 User message: {user_message}")
|
||||||
print(f"📎 Attached files: {len(files)}")
|
print(f"📎 Attached files: {len(files)}")
|
||||||
print(f"📸 Context photos: {len(context_photos_list)} fotos")
|
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")
|
print(f"💭 Chat history: {len(chat_history_list)} mensajes previos")
|
||||||
|
|
||||||
# Procesar archivos adjuntos
|
# Procesar archivos adjuntos
|
||||||
@@ -3523,6 +3526,21 @@ INFORMACIÓN DEL VEHÍCULO:
|
|||||||
status = analysis_text.get('status', 'unknown')
|
status = analysis_text.get('status', 'unknown')
|
||||||
photos_context += f"\n{idx}. Pregunta ID {photo.get('questionId')}: Status={status}\n Observaciones: {obs[:200]}...\n"
|
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
|
# Definir la longitud de respuesta
|
||||||
max_tokens_map = {
|
max_tokens_map = {
|
||||||
'short': 200,
|
'short': 200,
|
||||||
@@ -3559,6 +3577,8 @@ INFORMACIÓN DEL VEHÍCULO:
|
|||||||
CONTEXTO DEL VEHÍCULO Y PREGUNTA:
|
CONTEXTO DEL VEHÍCULO Y PREGUNTA:
|
||||||
{vehicle_context}
|
{vehicle_context}
|
||||||
|
|
||||||
|
{answers_context}
|
||||||
|
|
||||||
{photos_context}
|
{photos_context}
|
||||||
|
|
||||||
{attached_context}
|
{attached_context}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "checklist-frontend",
|
"name": "checklist-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.7",
|
"version": "1.2.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Service Worker para PWA con detección de actualizaciones
|
// Service Worker para PWA con detección de actualizaciones
|
||||||
// IMPORTANTE: Actualizar esta versión cada vez que se despliegue una nueva versión
|
// 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 = [
|
const urlsToCache = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html'
|
'/index.html'
|
||||||
|
|||||||
@@ -5632,6 +5632,7 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM
|
|||||||
|
|
||||||
// Recopilar fotos de preguntas anteriores según configuración
|
// Recopilar fotos de preguntas anteriores según configuración
|
||||||
const contextPhotos = []
|
const contextPhotos = []
|
||||||
|
const contextAnswers = [] // NUEVO: respuestas de texto de preguntas anteriores
|
||||||
const contextQuestionIds = config.context_questions
|
const contextQuestionIds = config.context_questions
|
||||||
? config.context_questions.split(',').map(id => parseInt(id.trim()))
|
? config.context_questions.split(',').map(id => parseInt(id.trim()))
|
||||||
: Object.keys(allAnswers).map(id => parseInt(id))
|
: Object.keys(allAnswers).map(id => parseInt(id))
|
||||||
@@ -5641,6 +5642,8 @@ function AIAssistantChatModal({ question, inspection, allAnswers, messages, setM
|
|||||||
|
|
||||||
previousQuestionIds.forEach(qId => {
|
previousQuestionIds.forEach(qId => {
|
||||||
const answer = allAnswers[qId]
|
const answer = allAnswers[qId]
|
||||||
|
|
||||||
|
// Agregar fotos si existen
|
||||||
if (answer?.photos && answer.photos.length > 0) {
|
if (answer?.photos && answer.photos.length > 0) {
|
||||||
answer.photos.forEach(photoUrl => {
|
answer.photos.forEach(photoUrl => {
|
||||||
contextPhotos.push({
|
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_photos', JSON.stringify(contextPhotos))
|
||||||
|
formData.append('context_answers', JSON.stringify(contextAnswers)) // NUEVO
|
||||||
formData.append('vehicle_info', JSON.stringify({
|
formData.append('vehicle_info', JSON.stringify({
|
||||||
brand: inspection.vehicle_brand,
|
brand: inspection.vehicle_brand,
|
||||||
model: inspection.vehicle_model,
|
model: inspection.vehicle_model,
|
||||||
|
|||||||
@@ -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"
|
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">
|
<p className="text-xs text-indigo-300 font-medium hover:text-indigo-200">
|
||||||
Ayutec v1.2.7
|
Ayutec v1.2.8
|
||||||
</p>
|
</p>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user