From b6a78f0156e148a13dffc4f746fc9f64e0703380 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 20 Apr 2026 21:49:17 +0800 Subject: [PATCH] bugfix --- pricing/pricing.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pricing/pricing.py b/pricing/pricing.py index 00d9871..7e1f9f3 100644 --- a/pricing/pricing.py +++ b/pricing/pricing.py @@ -409,7 +409,9 @@ order by b.enabled_date desc""" exception(f'{e}') raise Exception(e) data_value = config_data.get(k) - data_value = data_mapping(d, k, data_value) #需要mapping的数据转换 + p[f'old_{k}'] = datavalue + p[f'mapping_{k}'] = data_mapping(d, k, data_value) #需要mapping的数据转换 + data_value = p[f'mapping_{k}'] if data_value is None: e = f'数据({config_data})没有({k})数据' exception(e) @@ -487,3 +489,32 @@ async def test_pricing(pptid, data): for p in prices: amount += p.amount return amount + +if __name__ == '__main__': + yamlstr = """fields: + formula: + label: 计算公式 + type: str + model: + label: 模型 + type: str +model_mappings: # 模型映射 + "doubao-seed-2-0-pro-260215": "doubao-seed-2-0-pro" + "doubao-seed-2-0-lite-260215": "doubao-seed-2-0-lite" + "doubao-seed-2-0-mini-260215": "doubao-seed-2-0-mini" + "doubao-seed-2-0-code-preview-260215": "doubao-seed-2-0-code" +pricings: +- formula: (3.2 * float(prompt_tokens) + 16 * float(completion_tokens)) / 1000000.0 + model: doubao-seed-2-0-pro +- formula: 0.6 * float(prompt_tokens) + 3.6 * float(completion_tokens)) / 1000000.0 + model: doubao-seed-2-0-lite +- formula: (0.2 * float(prompt_tokens) + 2 * float(completion_tokens)) / 1000000.0 + model: doubao-seed-2-0-mini +- formula: (3.2 * float(prompt_tokens) + 16 * float(completion_tokens)) / 1000000.0 + model: doubao-seed-2-0-code +""" + config_data = {'completion_tokens': 1416, 'prompt_tokens': 52, 'total_tokens': 1468, 'prompt_tokens_details': {'cached_tokens': 0}, 'completion_tokens_details': {'reasoning_tokens': 884}, 'model': 'doubao-seed-2-0-pro-260215'} + print(f'{config_data=}, {yamlstr=}') + p = PricingProgram.get_pricing_from_ymalstr(config_data, yamlstr) + print(f'{p=}') +