sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

@@ -1,8 +1,10 @@
import logging
from typing import Literal
from fastapi import APIRouter, Depends, HTTPException, Request
from pydantic import BaseModel, Field
from app.gateway.catalog_cache import cached_catalog
from app.gateway.deps import get_config
from deerflow.config.app_config import AppConfig
from deerflow.config.model_config import ModelConfig
@@ -36,6 +38,7 @@ def _build_model_response(
model: ModelConfig,
*,
supports_reasoning_effort: bool = False,
default_reasoning_effort: str = "xhigh",
) -> "ModelResponse":
extra = model.model_extra or {}
provider = str(extra["provider"]) if "provider" in extra else _derive_provider(model.use)
@@ -48,6 +51,7 @@ def _build_model_response(
description=model.description,
supports_thinking=model.supports_thinking,
supports_reasoning_effort=bool(supports_reasoning_effort and model.supports_thinking),
default_reasoning_effort=default_reasoning_effort if default_reasoning_effort in {"low", "medium", "xhigh"} else "xhigh",
supports_vision=model.supports_vision,
supports_tool_calling=supports_tool_calling,
is_local=is_local,
@@ -64,6 +68,7 @@ class ModelResponse(BaseModel):
description: str | None = Field(None, description="Model description")
supports_thinking: bool = Field(default=False, description="Whether model supports thinking mode")
supports_reasoning_effort: bool = Field(default=False, description="Whether model supports reasoning effort")
default_reasoning_effort: Literal["low", "medium", "xhigh"] = Field(default="xhigh", description="Globally configured default reasoning effort")
supports_vision: bool = Field(default=False, description="Whether model supports image inputs")
supports_tool_calling: bool = Field(default=True, description="Whether model supports tool/function calling")
is_local: bool = Field(default=False, description="Whether this is a locally-hosted model")
@@ -83,18 +88,22 @@ class ModelsListResponse(BaseModel):
token_usage: TokenUsageResponse
async def _reasoning_capabilities(request: Request) -> dict[str, bool]:
async def _reasoning_capabilities(request: Request) -> dict[str, dict[str, object]]:
store = getattr(request.app.state, "model_capability_store", None)
if store is None:
return {}
async def load() -> dict[str, dict[str, object]]:
rows = await store.list_capabilities()
return {str(row.get("model_name") or ""): row for row in rows if row.get("model_name")}
try:
rows = await store.list_capabilities()
return await cached_catalog(request, "models", "reasoning-capabilities", load)
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(
@@ -143,7 +152,8 @@ async def list_models(request: Request, config: AppConfig = Depends(get_config))
models = [
_build_model_response(
model,
supports_reasoning_effort=capabilities.get(model.name, False),
supports_reasoning_effort=bool(capabilities.get(model.name, {}).get("supports_reasoning_effort", False)),
default_reasoning_effort=str(capabilities.get(model.name, {}).get("default_reasoning_effort") or "xhigh"),
)
for model in config.models
]
@@ -188,5 +198,6 @@ async def get_model(model_name: str, request: Request, config: AppConfig = Depen
capabilities = await _reasoning_capabilities(request)
return _build_model_response(
model,
supports_reasoning_effort=capabilities.get(model.name, False),
supports_reasoning_effort=bool(capabilities.get(model.name, {}).get("supports_reasoning_effort", False)),
default_reasoning_effort=str(capabilities.get(model.name, {}).get("default_reasoning_effort") or "xhigh"),
)