From d89edd3e74cfdc65cda049c2e0392866870f63f2 Mon Sep 17 00:00:00 2001 From: zhanggangyong Date: Sat, 24 Jan 2026 09:13:15 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=85=A8=E5=AF=B9=E9=BD=90=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=EF=BC=9A=E4=BF=AE=E6=AD=A3=E6=89=80=E6=9C=89=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E5=B7=AE=E5=BC=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正 Bearer token 解析:添加空格检查(Bearer 后必须有空格) - 修正 run_api_server.py:添加启动信息打印,格式与模板一致 - 修正 Dockerfile:添加 PYTHONDONTWRITEBYTECODE 环境变量 - 修正 Dockerfile HEALTHCHECK:添加 start-period 和 retries 参数 - 修正 requirements.txt:添加注释分组,与模板格式一致 --- Dockerfile | 9 ++++++++- requirements.txt | 7 +++++++ run_api_server.py | 10 ++++++++-- src/server/api_server.py | 4 ++-- 4 files changed, 25 insertions(+), 5 deletions(-) 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