✅ Backend v1.2.5
Cambios implementados: Streaming habilitado para OpenAI: Ahora usa stream=True en las llamadas al chat Procesamiento en tiempo real: El servidor recibe chunks de la respuesta y los concatena Mejor experiencia: Las respuestas largas se generan más rápido (el servidor empieza a recibir antes) Cómo funciona:
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
from fastapi import FastAPI, File, UploadFile, Form, Depends, HTTPException, status
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
from fastapi.responses import StreamingResponse
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from sqlalchemy import func, case, or_
|
||||
from typing import List, Optional
|
||||
@@ -20,6 +21,7 @@ import shutil
|
||||
from datetime import datetime, timedelta
|
||||
import sys
|
||||
import requests
|
||||
import json
|
||||
|
||||
# Función para enviar notificaciones al webhook
|
||||
def send_answer_notification(answer, question, mechanic, db):
|
||||
@@ -276,7 +278,7 @@ def extract_pdf_text_smart(pdf_content: bytes, max_chars: int = None) -> dict:
|
||||
}
|
||||
|
||||
|
||||
BACKEND_VERSION = "1.2.4"
|
||||
BACKEND_VERSION = "1.2.5"
|
||||
app = FastAPI(title="Checklist Inteligente API", version=BACKEND_VERSION)
|
||||
|
||||
# S3/MinIO configuration
|
||||
@@ -3621,14 +3623,21 @@ Longitud de respuesta: {response_length}
|
||||
api_key=ai_config.api_key
|
||||
)
|
||||
|
||||
response = client.chat.completions.create(
|
||||
# Usar streaming para respuestas más fluidas
|
||||
stream = client.chat.completions.create(
|
||||
model=ai_config.model_name or "gpt-4",
|
||||
messages=messages,
|
||||
max_tokens=max_tokens,
|
||||
temperature=0.7
|
||||
temperature=0.7,
|
||||
stream=True
|
||||
)
|
||||
|
||||
ai_response = response.choices[0].message.content
|
||||
# Recolectar respuesta completa del stream
|
||||
ai_response = ""
|
||||
for chunk in stream:
|
||||
if chunk.choices[0].delta.content is not None:
|
||||
ai_response += chunk.choices[0].delta.content
|
||||
|
||||
confidence = 0.85 # OpenAI no devuelve confidence directo
|
||||
|
||||
elif ai_config.provider == 'anthropic':
|
||||
|
||||
Reference in New Issue
Block a user