feat: get_pricing_display supports optional model filter
- Add model parameter to filter displayed pricing items to a single model - DSPY endpoint accepts ?model=xxx param - Backward compatible: omitting model returns all items
This commit is contained in:
parent
64a93049f0
commit
2fcd33cdba
@ -753,9 +753,13 @@ def generate_formula_from_factors(price_factors):
|
|||||||
return formula
|
return formula
|
||||||
|
|
||||||
|
|
||||||
async def get_pricing_display(ppid):
|
async def get_pricing_display(ppid, model=None):
|
||||||
"""获取定价项目的可读定价数据,供客户/前端展示。
|
"""获取定价项目的可读定价数据,供客户/前端展示。
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ppid: 定价项目ID
|
||||||
|
model: 可选,按模型名过滤,只返回匹配该模型的定价项
|
||||||
|
|
||||||
返回结构:
|
返回结构:
|
||||||
{
|
{
|
||||||
"ppid": "...",
|
"ppid": "...",
|
||||||
@ -915,6 +919,21 @@ async def get_pricing_display(ppid):
|
|||||||
item['formula'] = p['formula']
|
item['formula'] = p['formula']
|
||||||
items.append(item)
|
items.append(item)
|
||||||
|
|
||||||
|
# 按模型过滤:只返回匹配该模型的定价项
|
||||||
|
if model:
|
||||||
|
filtered_items = []
|
||||||
|
for item in items:
|
||||||
|
item_model = None
|
||||||
|
# 从 filters dict 中取 model
|
||||||
|
if item.get('filters') and isinstance(item['filters'], dict):
|
||||||
|
item_model = item['filters'].get('model')
|
||||||
|
# 从 filter_labels 中取(用 key 名"模型"查找)
|
||||||
|
if not item_model and item.get('filter_labels'):
|
||||||
|
item_model = item['filter_labels'].get('模型')
|
||||||
|
if item_model == model:
|
||||||
|
filtered_items.append(item)
|
||||||
|
items = filtered_items
|
||||||
|
|
||||||
# 生成可读价格表
|
# 生成可读价格表
|
||||||
display_lines = [f"【{getattr(r, 'name', '')}】定价:"]
|
display_lines = [f"【{getattr(r, 'name', '')}】定价:"]
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
ppid = params_kw.get('ppid')
|
ppid = params_kw.get('ppid')
|
||||||
|
model = params_kw.get('model')
|
||||||
if not ppid:
|
if not ppid:
|
||||||
return json.dumps({"status": "error", "message": "ppid parameter required"}, ensure_ascii=False)
|
return json.dumps({"status": "error", "message": "ppid parameter required"}, ensure_ascii=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = await get_pricing_display(ppid)
|
result = await get_pricing_display(ppid, model)
|
||||||
return json.dumps({"status": "ok", "data": result}, ensure_ascii=False, default=str)
|
return json.dumps({"status": "ok", "data": result}, ensure_ascii=False, default=str)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception(f'get_pricing_display({ppid}) failed: {e}\n{format_exc()}')
|
exception(f'get_pricing_display({ppid}) failed: {e}\n{format_exc()}')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user