mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-24 14:44:46 +08:00
* chore: add .claude/ to .gitignore Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat: add gateway module with FastAPI server - Add new gateway module with FastAPI app for API routing - Add gateway and serve commands to Makefile - Add fastapi, httpx, uvicorn, sse-starlette dependencies - Fix model config retrieval in lead_agent (support both model_name and model) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel, Field
|
|
|
|
from src.config import get_app_config
|
|
|
|
router = APIRouter(prefix="/api", tags=["models"])
|
|
|
|
|
|
class ModelResponse(BaseModel):
|
|
"""Response model for model information."""
|
|
|
|
name: str = Field(..., description="Unique identifier for the model")
|
|
display_name: str | None = Field(None, description="Human-readable name")
|
|
description: str | None = Field(None, description="Model description")
|
|
supports_thinking: bool = Field(default=False, description="Whether model supports thinking mode")
|
|
|
|
|
|
class ModelsListResponse(BaseModel):
|
|
"""Response model for listing all models."""
|
|
|
|
models: list[ModelResponse]
|
|
|
|
|
|
@router.get("/models", response_model=ModelsListResponse)
|
|
async def list_models() -> ModelsListResponse:
|
|
"""List all available models from configuration.
|
|
|
|
Returns model information suitable for frontend display,
|
|
excluding sensitive fields like API keys and internal configuration.
|
|
"""
|
|
config = get_app_config()
|
|
models = [
|
|
ModelResponse(
|
|
name=model.name,
|
|
display_name=model.display_name,
|
|
description=model.description,
|
|
supports_thinking=model.supports_thinking,
|
|
)
|
|
for model in config.models
|
|
]
|
|
return ModelsListResponse(models=models)
|
|
|
|
|
|
@router.get("/models/{model_name}", response_model=ModelResponse)
|
|
async def get_model(model_name: str) -> ModelResponse:
|
|
"""Get a specific model by name.
|
|
|
|
Args:
|
|
model_name: The unique name of the model to retrieve.
|
|
|
|
Returns:
|
|
Model information if found.
|
|
|
|
Raises:
|
|
HTTPException: 404 if model not found.
|
|
"""
|
|
config = get_app_config()
|
|
model = config.get_model_config(model_name)
|
|
if model is None:
|
|
raise HTTPException(status_code=404, detail=f"Model '{model_name}' not found")
|
|
|
|
return ModelResponse(
|
|
name=model.name,
|
|
display_name=model.display_name,
|
|
description=model.description,
|
|
supports_thinking=model.supports_thinking,
|
|
)
|