- 更新 README 描述从后端壳子到 AI Core/Agent Core - 添加 ToolCall 和 ToolResult 数据结构定义 - 扩展 AgentRun 模型增加输出、错误码、工具调用结果等字段 - 添加 mock 提供商类型支持 - 实现聊天、代理运行、工具调用和提供商管理的核心路由逻辑 - 集成容器化依赖注入和错误处理机制 - 更新 API 接口契约和文档说明
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.exceptions import RequestValidationError
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from starlette.exceptions import HTTPException as StarletteHttpException
|
|
|
|
from app.config import get_settings
|
|
from app.errors import ApiError, api_error_handler, http_error_handler, validation_error_handler
|
|
from app.routes import router as api_router
|
|
from app.schemas import HealthResponse, ServiceStatusResponse
|
|
|
|
settings = get_settings()
|
|
|
|
app = FastAPI(
|
|
title=settings.name,
|
|
version=settings.version,
|
|
description="AI 笔记软件的本地 AI Core 与 Agent Core 服务。",
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://127.0.0.1:5173", "http://localhost:5173"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.add_exception_handler(ApiError, api_error_handler)
|
|
app.add_exception_handler(RequestValidationError, validation_error_handler)
|
|
app.add_exception_handler(StarletteHttpException, http_error_handler)
|
|
app.include_router(api_router)
|
|
|
|
|
|
@app.get("/health", response_model=HealthResponse, tags=["System"])
|
|
async def health() -> HealthResponse:
|
|
return HealthResponse()
|
|
|
|
|
|
@app.get("/api/status", response_model=ServiceStatusResponse, tags=["System"])
|
|
async def service_status() -> ServiceStatusResponse:
|
|
return ServiceStatusResponse(
|
|
name=settings.name,
|
|
version=settings.version,
|
|
environment=settings.environment,
|
|
)
|