""" ╔══════════════════════════════════════════════════════════════════╗ ║ ATLAS-3 THINKING — Server A ║ ║ HuggingFace Space : Vincelil/Atlas3 ║ ║ FastAPI + ORO T3 (1000 unités vectorisées) ║ ║ Interroge Vincelil/Atlasdata via streaming ║ ╚══════════════════════════════════════════════════════════════════╝ """ import asyncio import time from contextlib import asynccontextmanager from fastapi import FastAPI, HTTPException from fastapi.responses import HTMLResponse, JSONResponse from fastapi.staticfiles import StaticFiles from pydantic import BaseModel from oro_t3 import OroT3Engine from faiss_index import FaissIndexer # ── Démarrage : construction de l'index en arrière-plan ─────────── indexer = FaissIndexer() engine = OroT3Engine(indexer) @asynccontextmanager async def lifespan(app: FastAPI): # Lance l'indexation FAISS en tâche de fond au démarrage asyncio.create_task(indexer.build_async()) yield indexer.stop() app = FastAPI( title="ATLAS-3 Thinking", description="ORO T3 — 1000 unités vectorisées sur FineWeb 15T", lifespan=lifespan, ) # ── Modèles Pydantic ────────────────────────────────────────────── class QueryRequest(BaseModel): query: str top_k: int = 5 class QueryResponse(BaseModel): query: str output: str oro_results: list faiss_hits: list index_size: int tick: int duration_ms: float # ── Routes ──────────────────────────────────────────────────────── @app.get("/", response_class=HTMLResponse) async def root(): with open("templates/index.html", encoding="utf-8") as f: return f.read() @app.post("/query", response_model=QueryResponse) async def query(req: QueryRequest): if not req.query.strip(): raise HTTPException(400, "Query vide") t0 = time.perf_counter() result = await engine.process(req.query, req.top_k) result["duration_ms"] = round((time.perf_counter() - t0) * 1000, 2) return JSONResponse(result) @app.get("/status") async def status(): return { "index_size": indexer.size(), "index_ready": indexer.is_ready(), "index_pct": indexer.progress_pct(), "oro_tick": engine.tick, "oro_count": engine.n_oro, "dataset": "Vincelil/Atlasdata", } @app.get("/oro/apprentissage") async def apprentissage(): return engine.get_learning_state()