from fastapi import APIRouter from fastapi.responses import HTMLResponse import sys import os #sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) page_route = APIRouter(prefix="/pages", tags=["pages"]) @page_route.get("/chats") async def chat_stream(): """ 直接返回SSE.html页面内容 """ html_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../SSE.html") try: with open(html_path, "r", encoding="utf-8") as f: html_content = f.read() return HTMLResponse(content=html_content) except Exception as e: return HTMLResponse(content=f"无法加载SSE.html页面: {e}", status_code=500)