阶段4(下):LangChain 1.x、提示词与注入防护、模型侧(路由/vLLM/LoRA)、AI 编程工具与验证、Dify/Coze 专题
This commit is contained in:
1 parent
caaec830b3
commit
7a32d2c9a6
38 files changed
+3059
-67
No files matched your search
@@ -0,0 +1,12 @@
|
||||
"""一段“AI 生成”的代码:计算订单优惠后的金额。用于演示验证流程。"""
|
||||
from decimal import ROUND_HALF_UP, Decimal
|
||||
|
||||
|
||||
def final_price(amount: Decimal, coupon: Decimal, vip: bool) -> Decimal:
|
||||
"""先减优惠券(不能减到负数),VIP 再打 95 折,结果保留两位小数(四舍五入)。"""
|
||||
if amount < 0 or coupon < 0:
|
||||
raise ValueError("金额和优惠券不能为负数")
|
||||
price = max(amount - coupon, Decimal("0"))
|
||||
if vip:
|
||||
price = price * Decimal("0.95")
|
||||
return price.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
|
||||
Reference in new issue
Block a user