refactor: 精简pricing_display, tiered只保留有意义filter
- 过滤内部参数: value_mode, xxx_tokens 区间条件不展示 - tiered 只保留 model 等有意义的 filter key - display_text 去掉冗余 prefix
This commit is contained in:
parent
3eefe1a67f
commit
38ff69ca55
@ -856,17 +856,22 @@ async def get_pricing_display(ppid):
|
||||
'unit_label': unit_label
|
||||
}]
|
||||
|
||||
# 处理 filters 区间定价
|
||||
# 处理 filters 区间定价 - 只保留有意义的 filter(如 model)
|
||||
if 'filters' in p:
|
||||
tiered_pricing = []
|
||||
for fi in p['filters']:
|
||||
fi_copy = fi.copy()
|
||||
raw_tier_price = fi.get('unit_prices', unit_price)
|
||||
fi_copy.pop('unit_prices', None)
|
||||
tiered_pricing.append({
|
||||
'filters': fi_copy,
|
||||
'unit_prices': raw_tier_price # 新格式已是展示价
|
||||
})
|
||||
fi_copy.pop('value_mode', None) # 内部参数不展示
|
||||
# 只保留有意义的 filter key
|
||||
meaningful_filters = {k: v for k, v in fi_copy.items()
|
||||
if not k.endswith('_tokens') and k != 'value_mode'}
|
||||
if meaningful_filters: # 有 model 等有意义 filter 才加 tiered
|
||||
tiered_pricing.append({
|
||||
'filters': meaningful_filters,
|
||||
'unit_prices': raw_tier_price
|
||||
})
|
||||
if tiered_pricing:
|
||||
price_factors_display[0]['tiered'] = tiered_pricing
|
||||
|
||||
@ -906,16 +911,12 @@ async def get_pricing_display(ppid):
|
||||
# 生成可读价格表
|
||||
display_lines = [f"【{getattr(r, 'name', '')}】定价:"]
|
||||
for item in items:
|
||||
prefix = ''
|
||||
if item.get('filter_labels'):
|
||||
labels = ', '.join(f"{k}: {v}" for k, v in item['filter_labels'].items())
|
||||
prefix = f" ({labels})"
|
||||
for pf in item.get('price_factors', []):
|
||||
label = pf.get('label', pf.get('factor', ''))
|
||||
up = pf.get('unit_price')
|
||||
ul = pf.get('unit_label', '')
|
||||
if up is not None:
|
||||
display_lines.append(f" - {label}: {up} {ul}{prefix}")
|
||||
display_lines.append(f" - {label}: {up} {ul}")
|
||||
if pf.get('tiered'):
|
||||
for t in pf['tiered']:
|
||||
t_filters = ', '.join(f"{k}={v}" for k, v in t.get('filters', {}).items())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user