48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""
|
|
Main entry point for RAG API server
|
|
"""
|
|
import os
|
|
import warnings
|
|
import uvicorn
|
|
from loguru import logger
|
|
from config import settings
|
|
|
|
# Suppress pkg_resources deprecation warning from debugpy extension
|
|
# This warning appears before api.main is imported, so we need to filter it here
|
|
warnings.filterwarnings("ignore", message=".*pkg_resources is deprecated.*", category=UserWarning)
|
|
|
|
# 检查并提示 NLTK_DATA 环境变量(提升导入速度)
|
|
if not os.environ.get("NLTK_DATA"):
|
|
logger.warning(
|
|
"NLTK_DATA 环境变量未设置,这可能导致 llama_index 导入较慢。"
|
|
"建议设置本地路径,例如: export NLTK_DATA=./nltk_data/"
|
|
)
|
|
|
|
|
|
def main():
|
|
"""Start the FastAPI server"""
|
|
logger.info(f"Starting {settings.API_TITLE} v{settings.API_VERSION}")
|
|
logger.info(f"Server will run on {settings.API_HOST}:{settings.API_PORT}")
|
|
|
|
# Configure uvicorn for production with better concurrency
|
|
uvicorn.run(
|
|
"api.main:app",
|
|
host=settings.API_HOST,
|
|
port=settings.API_PORT,
|
|
reload=False,
|
|
log_level="info",
|
|
# Enable access logs for better monitoring
|
|
access_log=True,
|
|
# Set timeout for long-running requests
|
|
timeout_keep_alive=120,
|
|
# Limit max requests to prevent memory issues
|
|
limit_max_requests=1000,
|
|
# Graceful shutdown timeout
|
|
timeout_graceful_shutdown=30
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|