File size: 1,524 Bytes
9d94d64 | 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 | import httpx
from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from routes_auth import router as auth_router
from service_chat import stream_chat_pipeline
from connector_browser import sync_user_cookies
app = FastAPI(title="Omni 4.8 Connectors API")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
if hasattr(auth_router, "prefix") and not auth_router.prefix:
app.include_router(auth_router, prefix="/auth")
else:
app.include_router(auth_router)
class CookieSyncRequest(BaseModel):
user_id: str
cookies: str
url: str
@app.get("/")
async def root():
return {"status": "ok", "service": "Omni 4.8 Backend"}
@app.post("/browser/sync-cookies")
async def sync_cookies_endpoint(data: CookieSyncRequest):
success = await sync_user_cookies(data.user_id, data.cookies, data.url)
return {"status": "success" if success else "failed", "synced": success}
@app.post("/generate")
async def generate_endpoint(request: Request):
body = await request.json()
client = httpx.AsyncClient(timeout=180.0)
async def stream_wrapper():
try:
async for chunk in stream_chat_pipeline(request, body, client):
yield chunk
finally:
await client.aclose()
return StreamingResponse(stream_wrapper(), media_type="text/event-stream")
|