diff --git a/Dockerfile b/Dockerfile index d56ad10..8feb48a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,17 @@ FROM python:3.12-slim + WORKDIR /app + ENV PYTHONUNBUFFERED=1 +ENV PYTHONDONTWRITEBYTECODE=1 + RUN apt-get update && apt-get install -y gcc curl && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 -HEALTHCHECK --interval=30s --timeout=10s CMD curl -f http://localhost:8000/health || exit 1 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:8000/health || exit 1 + CMD ["python", "run_api_server.py"] diff --git a/requirements.txt b/requirements.txt index b6b6bab..811555a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,13 @@ +# Pydantic AI pydantic-ai>=0.0.14 + +# MCP mcp>=0.9.0 fastmcp>=0.1.0 + +# FastAPI fastapi>=0.109.0 uvicorn[standard]>=0.27.0 + +# HTTP Client aiohttp>=3.9.0 diff --git a/run_api_server.py b/run_api_server.py index 38d02f7..fdd7da9 100644 --- a/run_api_server.py +++ b/run_api_server.py @@ -1,11 +1,17 @@ #!/usr/bin/env python -"""启动获客 Agent API 服务器""" +"""启动 API 服务器""" import sys from pathlib import Path + sys.path.insert(0, str(Path(__file__).parent)) if __name__ == '__main__': from src.server.api_server import app import uvicorn import os - uvicorn.run(app, host=os.getenv('API_HOST', '0.0.0.0'), port=int(os.getenv('API_PORT', '8000')), log_level="info") + + host = os.getenv('API_HOST', '0.0.0.0') + port = int(os.getenv('API_PORT', '8000')) + + print(f"🚀 启动 Agent API: http://{host}:{port}") + uvicorn.run(app, host=host, port=port, log_level="info") diff --git a/src/server/api_server.py b/src/server/api_server.py index e1976bb..ed18d98 100644 --- a/src/server/api_server.py +++ b/src/server/api_server.py @@ -55,7 +55,7 @@ async def verify_api_key( return api_key.strip() if authorization: - key = authorization[7:].strip() if authorization.startswith("Bearer") else authorization.strip() + key = authorization[7:].strip() if authorization.startswith("Bearer ") else authorization.strip() if key and key != "sk": return key @@ -68,7 +68,7 @@ def get_api_key_from_request(request: Request) -> Optional[str]: if not api_key: auth = request.headers.get("Authorization") if auth: - api_key = auth[7:] if auth.startswith("Bearer") else auth + api_key = auth[7:] if auth.startswith("Bearer ") else auth return api_key