sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -1,4 +1,6 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.gateway.deps import get_config
|
||||
@@ -6,6 +8,7 @@ from deerflow.config.app_config import AppConfig
|
||||
from deerflow.config.model_config import ModelConfig
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["models"])
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_PROVIDER_KEYWORDS: list[tuple[str, str]] = [
|
||||
("langchain_openai", "openai"),
|
||||
@@ -29,7 +32,11 @@ def _derive_provider(use: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _build_model_response(model: ModelConfig) -> "ModelResponse":
|
||||
def _build_model_response(
|
||||
model: ModelConfig,
|
||||
*,
|
||||
supports_reasoning_effort: bool = False,
|
||||
) -> "ModelResponse":
|
||||
extra = model.model_extra or {}
|
||||
provider = str(extra["provider"]) if "provider" in extra else _derive_provider(model.use)
|
||||
is_local = bool(extra["is_local"]) if "is_local" in extra else (provider in _LOCAL_PROVIDERS)
|
||||
@@ -40,7 +47,7 @@ def _build_model_response(model: ModelConfig) -> "ModelResponse":
|
||||
display_name=model.display_name,
|
||||
description=model.description,
|
||||
supports_thinking=model.supports_thinking,
|
||||
supports_reasoning_effort=model.supports_reasoning_effort,
|
||||
supports_reasoning_effort=bool(supports_reasoning_effort and model.supports_thinking),
|
||||
supports_vision=model.supports_vision,
|
||||
supports_tool_calling=supports_tool_calling,
|
||||
is_local=is_local,
|
||||
@@ -76,13 +83,27 @@ class ModelsListResponse(BaseModel):
|
||||
token_usage: TokenUsageResponse
|
||||
|
||||
|
||||
async def _reasoning_capabilities(request: Request) -> dict[str, bool]:
|
||||
store = getattr(request.app.state, "model_capability_store", None)
|
||||
if store is None:
|
||||
return {}
|
||||
try:
|
||||
rows = await store.list_capabilities()
|
||||
except Exception:
|
||||
# Capability reads fail closed: the selector disappears, while ordinary
|
||||
# model use remains available.
|
||||
logger.warning("Failed to read model capabilities", exc_info=True)
|
||||
return {}
|
||||
return {str(row.get("model_name") or ""): bool(row.get("supports_reasoning_effort", False)) for row in rows if row.get("model_name")}
|
||||
|
||||
|
||||
@router.get(
|
||||
"/models",
|
||||
response_model=ModelsListResponse,
|
||||
summary="List All Models",
|
||||
description="Retrieve a list of all available AI models configured in the system.",
|
||||
)
|
||||
async def list_models(config: AppConfig = Depends(get_config)) -> ModelsListResponse:
|
||||
async def list_models(request: Request, config: AppConfig = Depends(get_config)) -> ModelsListResponse:
|
||||
"""List all available models from configuration.
|
||||
|
||||
Returns model information suitable for frontend display,
|
||||
@@ -118,7 +139,14 @@ async def list_models(config: AppConfig = Depends(get_config)) -> ModelsListResp
|
||||
}
|
||||
```
|
||||
"""
|
||||
models = [_build_model_response(model) for model in config.models]
|
||||
capabilities = await _reasoning_capabilities(request)
|
||||
models = [
|
||||
_build_model_response(
|
||||
model,
|
||||
supports_reasoning_effort=capabilities.get(model.name, False),
|
||||
)
|
||||
for model in config.models
|
||||
]
|
||||
return ModelsListResponse(
|
||||
models=models,
|
||||
token_usage=TokenUsageResponse(enabled=config.token_usage.enabled),
|
||||
@@ -131,7 +159,7 @@ async def list_models(config: AppConfig = Depends(get_config)) -> ModelsListResp
|
||||
summary="Get Model Details",
|
||||
description="Retrieve detailed information about a specific AI model by its name.",
|
||||
)
|
||||
async def get_model(model_name: str, config: AppConfig = Depends(get_config)) -> ModelResponse:
|
||||
async def get_model(model_name: str, request: Request, config: AppConfig = Depends(get_config)) -> ModelResponse:
|
||||
"""Get a specific model by name.
|
||||
|
||||
Args:
|
||||
@@ -157,4 +185,8 @@ async def get_model(model_name: str, config: AppConfig = Depends(get_config)) ->
|
||||
if model is None:
|
||||
raise HTTPException(status_code=404, detail=f"Model '{model_name}' not found")
|
||||
|
||||
return _build_model_response(model)
|
||||
capabilities = await _reasoning_capabilities(request)
|
||||
return _build_model_response(
|
||||
model,
|
||||
supports_reasoning_effort=capabilities.get(model.name, False),
|
||||
)
|
||||
Reference in new issue
Block a user