Spaces:
Sleeping
Sleeping
File size: 1,610 Bytes
f1db1e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List
from contextlib import asynccontextmanager
from src.engine.analysis_engine import AnalysisEngine
engine = None
@asynccontextmanager
async def lifespan(app: FastAPI):
global engine
engine = AnalysisEngine()
yield
app = FastAPI(lifespan=lifespan, title="FactChecker Ultra-Ligero")
class Paragraph(BaseModel):
type: str
text: str
class AnalysisRequest(BaseModel):
title: str
paragraphs: List[Paragraph]
user_text: str
class RagItem(BaseModel):
summary: str
class RagAnalysisRequest(BaseModel):
rag_results: List[RagItem]
user_text: str
@app.get("/")
def home():
return {"status": "corriendo", "modelos_cargados": "una sola vez"}
@app.post("/analyze")
async def analyze(payload: AnalysisRequest):
result = engine.analyze(
user_text=payload.user_text,
document_paragraphs=[p.dict() for p in payload.paragraphs],
title=payload.title,
)
return result
@app.post("/analyze-rag")
async def analyze_rag(payload: RagAnalysisRequest):
# 1. Convertir summaries a párrafos estándar del analizador
rag_paragraphs = [
{
"type": "rag_summary",
"text": item.summary
}
for item in payload.rag_results
]
# 2. Ejecutar el MISMO engine
result = engine.analyze(
user_text=payload.user_text,
document_paragraphs=rag_paragraphs,
title="RAG_CONTEXT"
)
# 3. Marcar que viene de RAG (trazabilidad futura)
result["source"] = "rag"
return result
|