Commit 8505bb1b by imwangxiaozhou

build(backend): 新增Python依赖并调整.gitignore的SQLite忽略规则

注释.gitignore中的SQLite数据库文件忽略规则,允许本地相关文件被git追踪。
新增agentscope>=1.0.0和numpy>=1.26.0依赖至backend的requirements.txt。
1 parent 2dd71a25
...@@ -44,9 +44,9 @@ tmp/ ...@@ -44,9 +44,9 @@ tmp/
uploads/ uploads/
# SQLite runtime files # SQLite runtime files
*.db # *.db
*.db-shm # *.db-shm
*.db-wal # *.db-wal
.workbuddy/ .workbuddy/
......
...@@ -21,6 +21,7 @@ class ServerSettings(BaseModel): ...@@ -21,6 +21,7 @@ class ServerSettings(BaseModel):
host: str = "0.0.0.0" host: str = "0.0.0.0"
port: int = 8000 port: int = 8000
reload: bool = True reload: bool = True
base_path: str = ""
class IMSettings(BaseModel): class IMSettings(BaseModel):
......
...@@ -23,6 +23,12 @@ from app.service.console_im_service import ConsoleIMService ...@@ -23,6 +23,12 @@ from app.service.console_im_service import ConsoleIMService
from app.service.im_service import IMService from app.service.im_service import IMService
agent_hub_instance = None agent_hub_instance = None
runtime_settings = ConfigLoader().load_settings()
base_path = (runtime_settings.server.base_path or "").rstrip("/")
docs_url = f"{base_path}/docs" if base_path else "/docs"
redoc_url = f"{base_path}/redoc" if base_path else "/redoc"
openapi_url = f"{base_path}/openapi.json" if base_path else "/openapi.json"
oauth2_redirect_url = f"{base_path}/docs/oauth2-redirect" if base_path else "/docs/oauth2-redirect"
@asynccontextmanager @asynccontextmanager
...@@ -62,7 +68,15 @@ async def lifespan(app: FastAPI): ...@@ -62,7 +68,15 @@ async def lifespan(app: FastAPI):
await agent_hub_instance.close() await agent_hub_instance.close()
app = FastAPI(title="Agent Admin API", version="1.0.0", lifespan=lifespan) app = FastAPI(
title="Agent Admin API",
version="1.0.0",
lifespan=lifespan,
docs_url=docs_url,
redoc_url=redoc_url,
openapi_url=openapi_url,
swagger_ui_oauth2_redirect_url=oauth2_redirect_url,
)
@app.exception_handler(HTTPException) @app.exception_handler(HTTPException)
...@@ -98,7 +112,7 @@ async def unhandled_exception_handler(_: Request, exc: Exception): ...@@ -98,7 +112,7 @@ async def unhandled_exception_handler(_: Request, exc: Exception):
async def wrap_json_response(request: Request, call_next): async def wrap_json_response(request: Request, call_next):
response = await call_next(request) response = await call_next(request)
if request.url.path in {"/openapi.json", "/docs", "/docs/oauth2-redirect", "/redoc"}: if request.url.path in {openapi_url, docs_url, oauth2_redirect_url, redoc_url}:
return response return response
content_type = response.headers.get("content-type", "") content_type = response.headers.get("content-type", "")
...@@ -138,10 +152,10 @@ async def wrap_json_response(request: Request, call_next): ...@@ -138,10 +152,10 @@ async def wrap_json_response(request: Request, call_next):
) )
app.include_router(api_router) app.include_router(api_router, prefix=base_path)
@app.get("/health") @app.get(f"{base_path}/health" if base_path else "/health")
def health_check(): def health_check():
return {"status": "ok"} return {"status": "ok"}
......
...@@ -73,6 +73,7 @@ class HttpChatCompletionsBatchDispatcher: ...@@ -73,6 +73,7 @@ class HttpChatCompletionsBatchDispatcher:
port = int(os.getenv("DOWNSTREAM_CHAT_PORT") or settings.downstream_chat.port) port = int(os.getenv("DOWNSTREAM_CHAT_PORT") or settings.downstream_chat.port)
resolved_base_url = base_url or f"http://{host}:{port}" resolved_base_url = base_url or f"http://{host}:{port}"
self.base_url = resolved_base_url.rstrip("/") self.base_url = resolved_base_url.rstrip("/")
self.base_path = (settings.server.base_path or "").rstrip("/")
self.timeout_seconds = timeout_seconds self.timeout_seconds = timeout_seconds
def dispatch(self, payload: dict[str, Any]) -> None: def dispatch(self, payload: dict[str, Any]) -> None:
...@@ -82,7 +83,7 @@ class HttpChatCompletionsBatchDispatcher: ...@@ -82,7 +83,7 @@ class HttpChatCompletionsBatchDispatcher:
try: try:
with httpx.Client(timeout=self.timeout_seconds) as client: with httpx.Client(timeout=self.timeout_seconds) as client:
response = client.post( response = client.post(
f"{self.base_url}/api/v1/chat/completions", f"{self.base_url}{self.base_path}/api/v1/chat/completions",
json=request_body, json=request_body,
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
) )
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"server": { "server": {
"host": "0.0.0.0", "host": "0.0.0.0",
"port": 8000, "port": 8000,
"reload": true "reload": true,
"base_path": "/backend"
}, },
"im": { "im": {
"use_console": true, "use_console": true,
......
...@@ -24,6 +24,8 @@ pytest-mock==3.15.1 ...@@ -24,6 +24,8 @@ pytest-mock==3.15.1
# AI/ML APIs # AI/ML APIs
openai>=1.0.0 openai>=1.0.0
dashscope>=1.20.0 dashscope>=1.20.0
agentscope>=1.0.0
numpy>=1.26.0
# Document processing # Document processing
python-docx>=1.1.0 python-docx>=1.1.0
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!