This commit is contained in:
yumoqing 2026-04-20 21:49:17 +08:00
parent e12b217d4e
commit b6a78f0156

View File

@ -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=}')