发布

  • feat(ollama): report model capabilities + details on /api/tags and /api/show (#9766)

    frostbyte_neo 发布于 2026-05-11 22:16:19 +00:00

    Ollama-compatible clients (Open WebUI, Enchanted, ollama-grid-search,
    etc.) rely on the capabilities list and details.{parameter_size, quantization_level,families} fields returned by /api/tags and
    /api/show to decide which models are eligible for a given task --
    for example to filter the "embedding model" picker. Upstream Ollama
    returns these; LocalAI's compat layer was leaving them empty, so
    embedding models were silently rejected by clients that only allow
    chat models for chat and only allow embedding models for embeddings.

    This wires up the existing config signals already present in
    ModelConfig:

    • modelCapabilities() derives the Ollama capability strings from the
      config: "embedding" (FLAG_EMBEDDINGS), "completion" (FLAG_CHAT /
      FLAG_COMPLETION), "vision" (explicit KnownUsecases bit or MMProj /
      multimodal template / backend media marker), "tools" (auto-detected
      ToolFormatMarkers, JSON/Response regex, XML format, grammar
      triggers), "thinking" (ReasoningConfig with reasoning not disabled)
      and "insert" (presence of a completion template).
    • modelDetailsFromModelConfig() now fills families, parameter_size
      and quantization_level. The latter two are parsed from the GGUF
      filename via regex -- conservative tokens only (Q*/IQ*/F16/F32/BF16
      and \d+(.\d+)?[BM] surrounded by separators) so we don't accidentally
      match "Qwen3" as "3B".
    • modelInfoFromModelConfig() exposes general.architecture and
      general.context_length in the new ShowResponse.model_info map.

    Note: HasUsecases(FLAG_VISION) cannot be used directly -- GuessUsecases
    has no FLAG_VISION case and returns true at the end for any chat model.
    hasVisionSupport() instead reads KnownUsecases explicitly plus MMProj /
    template / media-marker signals.

    Tests are written first (TDD) using Ginkgo/Gomega -- DescribeTable for
    the capability mapping (embedding-only, chat, vision, thinking, tools
    via markers, tools via JSON regex, no-capability rerank) plus
    integration tests against ShowModelEndpoint that round-trip JSON
    through a real ModelConfigLoader populated from a temp YAML file.

    Fixes #9760.

    Assisted-by: Claude Code:claude-opus-4-7

    Signed-off-by: Ettore Di Giacinto mudler@localai.io
    Co-authored-by: Ettore Di Giacinto mudler@localai.io

    下载附件