发布

  • [BE] fix: register perplexity as a canonical provider so Perplexity model prices load (#7432)

    frostbyte_neo 发布于 2026-07-15 11:23:00 +00:00

    • [BE] fix: register perplexity as a canonical provider so Perplexity model prices load

    Following the pattern of #7262 (which registered azure), Perplexity's 41
    entries in model_prices_and_context_window.json currently drop at load
    time because perplexity is not in PROVIDERS_MAPPING. Of those 41, 16
    publish non-zero input+output rates — the sonar family (sonar, sonar-pro,
    sonar-reasoning*, sonar-deep-research) plus the legacy
    perplexity/llama-* and perplexity/codellama-* chat models. None
    publish cache_read or cache_creation rates, so Perplexity requests route
    cleanly through textGenerationCost and no cache-calculator wiring is
    needed.

    Add perplexity -> perplexity to PROVIDERS_MAPPING; no other changes.

    Parameterized integration test uses perplexity/sonar (input=output=1e-6)
    and perplexity/sonar-pro (input 3e-6 / output 1.5e-5), covering both a
    uniform-rate model and a model where input and output rates differ, to
    prove the plumbing routes correctly.

    • [BE] fix: fall back to model-name provider prefix when aggregator routing misses

    Addressing baz-reviewer's High-severity finding on #7432. Registering
    perplexity as a canonical provider (this PR's original scope) fixes
    direct callers, but BudgetGuard also invokes CostService.calculateCost via
    LlmProviderFactoryImpl.getResolvedModelInfo(), which enumerates
    perplexity/*, xai/*, and deepseek/* under OpenRouter and therefore
    returns provider="openrouter". Without an openrouter row for these
    models the lookup lands on DEFAULT_COST and Perplexity-hosted evaluations
    charge $0.

    Add a final fallback in findModelPrice: when every primary lookup has
    missed and the original model name carries a provider prefix that maps to
    a canonical provider we know pricing for (e.g. perplexity/sonar maps
    prefix perplexity -> canonical perplexity), retry the lookup under
    that prefix's canonical provider. Only kicks in as a fallback so no
    existing lookup semantics change for callers that already pass a matching
    provider directly, and only when the prefix appears in PROVIDERS_MAPPING
    so unmapped prefixes cannot leak through.

    The same fallback covers the parallel deepseek and xai cases (#7434,
    #7433) — those models are also enumerated under OpenRouter and would
    otherwise silently drop to $0 through the aggregator-routed BudgetGuard
    path.

    Parameterized test uses perplexity/sonar and perplexity/sonar-pro through
    both openrouter and custom-llm providers; each returns the same cost
    as the direct perplexity lookup.


    Co-authored-by: Andres Cruz andresc@comet.com

    下载附件