Skip to main content

key_token/
pricing.rs

1use rust_decimal::Decimal;
2use serde::{Deserialize, Serialize};
3
4/// 价格快照:请求开始时固化,不可变
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct PricingSnapshot {
7    pub model_name: String,
8    pub currency: String,
9    pub input_price_per_1k: Decimal,
10    pub output_price_per_1k: Decimal,
11}
12
13impl PricingSnapshot {
14    pub fn new(
15        model_name: impl Into<String>,
16        currency: impl Into<String>,
17        input_price_per_1k: Decimal,
18        output_price_per_1k: Decimal,
19    ) -> Self {
20        Self {
21            model_name: model_name.into(),
22            currency: currency.into(),
23            input_price_per_1k,
24            output_price_per_1k,
25        }
26    }
27}
28
29impl Default for PricingSnapshot {
30    fn default() -> Self {
31        Self {
32            model_name: String::new(),
33            currency: "CNY".to_string(),
34            input_price_per_1k: Decimal::ZERO,
35            output_price_per_1k: Decimal::ZERO,
36        }
37    }
38}