12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- """
- 文献启明星 API 服务器
- FastAPI应用程序入口
- """
- import logging
- import uvicorn
- from fastapi import FastAPI, HTTPException
- from fastapi.middleware.cors import CORSMiddleware
- from pathlib import Path
- import json
- import sys
- import os
- # 添加项目根目录到Python路径
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- from backend.api.research import router as research_router
- from backend.config import CORS_ORIGINS, BASE_DIR
- # 配置日志
- logging.basicConfig(
- level=logging.INFO,
- format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
- handlers=[
- logging.StreamHandler(),
- logging.FileHandler(Path(BASE_DIR) / "lightstar_api.log")
- ]
- )
- logger = logging.getLogger(__name__)
- # 创建FastAPI应用
- app = FastAPI(
- title="LightStar API",
- description="文献启明星 - 科研调研智能体API服务",
- version="0.1.0",
- )
- # 配置CORS
- app.add_middleware(
- CORSMiddleware,
- allow_origins=CORS_ORIGINS,
- allow_credentials=True,
- allow_methods=["*"],
- allow_headers=["*"],
- )
- # 注册路由
- app.include_router(research_router)
- # 健康检查端点
- @app.get("/health")
- async def health_check():
- return {"status": "healthy", "version": "0.1.0"}
- # API信息端点
- @app.get("/")
- async def root():
- return {
- "name": "LightStar API",
- "description": "文献启明星 - 科研调研智能体API服务",
- "version": "0.1.0",
- "endpoints": [
- "/api/research/process",
- "/api/research/extract-keywords",
- "/api/research/search-papers",
- "/api/research/cluster-papers",
- "/api/research/generate-report"
- ]
- }
- # 启动服务器
- if __name__ == "__main__":
- logger.info("Starting LightStar API server")
- uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|