| """ |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| β 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 |
|
|
| |
| indexer = FaissIndexer() |
| engine = OroT3Engine(indexer) |
|
|
|
|
| @asynccontextmanager |
| async def lifespan(app: FastAPI): |
| |
| 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, |
| ) |
|
|
|
|
| |
| 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 |
|
|
|
|
| |
|
|
| @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() |
|
|