Solucionado

El error ocurría porque faltaba el caso de Anthropic en la función de análisis de imágenes. Ahora Anthropic Claude puede:

Analizar imágenes con vision
Analizar documentos PDF
Usar el formato correcto de mensajes con system separado
Backend actualizado a v1.2.2
This commit is contained in:
2025-12-04 14:01:58 -03:00
parent a8afaa044f
commit 14d5027170
2 changed files with 66 additions and 18 deletions

View File

@@ -276,7 +276,7 @@ def extract_pdf_text_smart(pdf_content: bytes, max_chars: int = None) -> dict:
}
BACKEND_VERSION = "1.2.1"
BACKEND_VERSION = "1.2.2"
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
# S3/MinIO configuration
@@ -3211,6 +3211,53 @@ NOTA:
ai_response = response.choices[0].message.content
elif ai_config.provider == "anthropic":
import anthropic
client = anthropic.Anthropic(api_key=ai_config.api_key)
if is_pdf:
# Para PDF, solo texto
response = client.messages.create(
model=ai_config.model_name or "claude-sonnet-4-5",
max_tokens=500,
system=system_prompt,
messages=[
{
"role": "user",
"content": f"{user_message}\n\n--- CONTENIDO DEL DOCUMENTO PDF ({len(pdf_text)} caracteres) ---\n{pdf_text[:100000]}"
}
]
)
else:
# Para imagen, usar vision
response = client.messages.create(
model=ai_config.model_name or "claude-sonnet-4-5",
max_tokens=500,
system=system_prompt,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": user_message
},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_b64
}
}
]
}
]
)
ai_response = response.content[0].text
elif ai_config.provider == "gemini":
import google.generativeai as genai
from PIL import Image