Skip to content

发送消息时报错:费用计算中 Decimal 和 float 混用 #25

Open

Description

@Arkto454

在 Windows 上启动项目后,发送普通消息,界面报错:

Model API error (TypeError): unsupported operand type(s) for *: 'decimal.Decimal' and 'float'

环境是 Python 3.14.0,本地提交 fd9bf63,连接的是 DeepSeek。

排查发现,不连接模型也能复现。在仓库根目录,使用安装了本项目的 Python 执行:

python -c "from minicode.cost_tracker import calculate_cost; print(calculate_cost('deepseek-flash', input_tokens=100, output_tokens=20))"

同样会报 TypeError,位置在 minicode/cost_tracker.py 的 calculate_cost():

(input_tokens / _DECIMAL_1M) * pricing["input"]

这里 _DECIMAL_1M 是 Decimal("1000000"),但价格表中的值是 float,两者相乘会报错。其余三项也用了同样的写法。

预期是正常返回费用估算值,而不是让这一轮对话中断。是否可以统一这里的数值类型?

以下是报错的截图:

download

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