Skip to content

Cost calculation crashes with AttributeError for unmapped models (e.g. local Ollama models) #67

Description

@na55imK

Summary

fastllm's cost tracking crashes for model not present in the bundled
model_prices.json . Only a small hand-picked subset of Ollama tags
are keys in that file — e.g. ollama/llama2 is present, but ministral-3:3b
(and many other locally-pulled models) isn't.

Repro

ssage --vendor_name openai_chat --base_url http://localhost:11434/v1
--api_key ollama --model ministral-3:3b "hi"

The completion succeeds, but crashes right after while tracking usage:

File ".../fastllm/openai_chat.py", line 204, in cost
cost = in_txt * m.input_cost_per_token + out_txt * m.output_cost_per_token
AttributeError: input_cost_per_token

Cause

cost() looks up the model name in model_prices.json and assumes the
result always has input_cost_per_token/output_cost_per_token. There's as far as I can see no
fallback for models that aren't a key in that file.

Suggested fix

Default to cost = 0 when a model isn't found, rather than raising. Probably
also add a wildcard fallback for ollama models generally.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions