Skip to content

fix(kimi): keep unknown pricing as None instead of raising - #3288

Open
BlueX888 wants to merge 1 commit into
confident-ai:mainfrom
BlueX888:fix/prep-kimi-model-float-none-cost-crash
Open

BlueX888 wants to merge 1 commit into
confident-ai:mainfrom
BlueX888:fix/prep-kimi-model-float-none-cost-crash

Conversation

@BlueX888

Copy link
Copy Markdown

Summary

KimiModel.__init__ no longer raises when the selected model has no registry pricing. Unknown pricing is reported as None, matching the other provider adapters.

Why

require_costs() is typed -> Tuple[Optional[float], Optional[float]] and returns None, None when neither the registry entry nor an explicit/env cost override supplies pricing (deepeval/models/utils.py:112-158). KimiModel.__init__ then coerced those values with float():

deepeval/models/llms/kimi_model.py:88-89

self.model_data.input_price = float(cost_per_input_token)
self.model_data.output_price = float(cost_per_output_token)

float(None) raises TypeError, so construction fails synchronously, before any request is made. Two reachable paths:

  • a shipped registry entry with input_price=None/output_price=None — kimi-k2-base (deepeval/models/llms/constants.py:1051-1057);
  • any model id absent from KIMI_MODELS_DATA, which falls back to the unpriced default model data (ModelDataRegistry.get, deepeval/models/llms/constants.py:42-53).

Sibling adapters assign the require_costs() result directly (deepeval/models/llms/deepseek_model.py:88-89, deepeval/models/llms/openai_model.py:122-123), and calculate_cost() already treats a missing price as unknown.

Changes

  • deepeval/models/llms/kimi_model.py — assign cost_per_input_token / cost_per_output_token to model_data.input_price / model_data.output_price without the float() coercion, as the sibling adapters do.
  • tests/test_core/test_models/test_kimi_model.py — regression tests for both paths: a registry entry without pricing (kimi-k2-base) and an id absent from the registry (moonshot-v1-256k). Each asserts construction succeeds and calculate_cost() returns None.

Testing

  • New tests against the unpatched tree: python -m pytest tests/test_core/test_models/test_kimi_model.py -k constructs → 2 failed, TypeError: float() argument must be a string or a real number, not 'NoneType' at kimi_model.py:88.
  • New tests against the patched tree: same command → 2 passed.
  • Module suite: python -m pytest tests/test_core/test_models/test_kimi_model.py → 8 passed.
  • Format: black --check (25.12.0, the version pinned in .github/workflows/black.yml) → 2 files would be left unchanged.
  • Lint: ruff check deepeval/models/llms/kimi_model.py tests/test_core/test_models/test_kimi_model.py → All checks passed!

No API key or network is required; the tests stub the OpenAI clients via tests/test_core/stubs.py (_RecordingClient).

Fixes #3287

require_costs() returns (None, None) when a model has no pricing entry and no
explicit cost override, matching every other provider adapter. KimiModel
wrapped that result in float(), so constructing it with the shipped
kimi-k2-base entry (or any id absent from KIMI_MODELS_DATA) raised
TypeError before the client was ever built. Assign the costs directly, as
the sibling adapters do, so calculate_cost() reports no cost instead.
@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown

@BlueX888 is attempting to deploy a commit to the Confident AI Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KimiModel.__init__ raises TypeError float(None) whenever the selected model has no registry pricing

1 participant