Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,12 +22,26 @@ def get_model():
|
|
| 22 |
# =======================================
|
| 23 |
@tool
|
| 24 |
def add(a: float, b: float) -> float:
|
| 25 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return a + b
|
| 27 |
|
| 28 |
@tool
|
| 29 |
def mul(a: float, b: float) -> float:
|
| 30 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
return a * b
|
| 32 |
|
| 33 |
def run_ex1():
|
|
@@ -75,7 +89,13 @@ def run_ex2():
|
|
| 75 |
# =======================================
|
| 76 |
@tool
|
| 77 |
def validate_pr(pr: dict) -> dict:
|
| 78 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
req = ["pr_id","requester","cost_center","currency","items"]
|
| 80 |
errors = [f"Missing {k}" for k in req if k not in pr]
|
| 81 |
if not isinstance(pr.get("items", []), list) or not pr["items"]:
|
|
@@ -84,12 +104,18 @@ def validate_pr(pr: dict) -> dict:
|
|
| 84 |
|
| 85 |
@tool
|
| 86 |
def create_po(pr: dict) -> dict:
|
| 87 |
-
"""Create a simple
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
subtotal = 0.0
|
| 89 |
items_out = []
|
| 90 |
for it in pr.get("items", []):
|
| 91 |
line = float(it["quantity"]) * float(it["unit_price"])
|
| 92 |
-
items_out.append({"sku": it
|
| 93 |
subtotal += line
|
| 94 |
tax = round(subtotal * 0.08, 2)
|
| 95 |
total = round(subtotal + tax, 2)
|
|
|
|
| 22 |
# =======================================
|
| 23 |
@tool
|
| 24 |
def add(a: float, b: float) -> float:
|
| 25 |
+
"""Add two numbers.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
a (float): First addend.
|
| 29 |
+
b (float): Second addend.
|
| 30 |
+
Returns:
|
| 31 |
+
float: Sum a + b.
|
| 32 |
+
"""
|
| 33 |
return a + b
|
| 34 |
|
| 35 |
@tool
|
| 36 |
def mul(a: float, b: float) -> float:
|
| 37 |
+
"""Multiply two numbers.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
a (float): First factor.
|
| 41 |
+
b (float): Second factor.
|
| 42 |
+
Returns:
|
| 43 |
+
float: Product a * b.
|
| 44 |
+
"""
|
| 45 |
return a * b
|
| 46 |
|
| 47 |
def run_ex1():
|
|
|
|
| 89 |
# =======================================
|
| 90 |
@tool
|
| 91 |
def validate_pr(pr: dict) -> dict:
|
| 92 |
+
"""Validate basic PR fields and structure.
|
| 93 |
+
|
| 94 |
+
Args:
|
| 95 |
+
pr (dict): Purchase Requisition object with keys: pr_id, requester, cost_center, currency, items.
|
| 96 |
+
Returns:
|
| 97 |
+
dict: {{"ok": bool, "errors": list[str]}}
|
| 98 |
+
"""
|
| 99 |
req = ["pr_id","requester","cost_center","currency","items"]
|
| 100 |
errors = [f"Missing {k}" for k in req if k not in pr]
|
| 101 |
if not isinstance(pr.get("items", []), list) or not pr["items"]:
|
|
|
|
| 104 |
|
| 105 |
@tool
|
| 106 |
def create_po(pr: dict) -> dict:
|
| 107 |
+
"""Create a simple Purchase Order (PO) from a PR.
|
| 108 |
+
|
| 109 |
+
Args:
|
| 110 |
+
pr (dict): Validated PR dict with items[{sku, quantity, unit_price}] and currency.
|
| 111 |
+
Returns:
|
| 112 |
+
dict: PO JSON with po_id, items, subtotal, tax, total, source_pr_id.
|
| 113 |
+
"""
|
| 114 |
subtotal = 0.0
|
| 115 |
items_out = []
|
| 116 |
for it in pr.get("items", []):
|
| 117 |
line = float(it["quantity"]) * float(it["unit_price"])
|
| 118 |
+
items_out.append({"sku": it.get("sku","UNKNOWN"), "line_total": round(line,2)})
|
| 119 |
subtotal += line
|
| 120 |
tax = round(subtotal * 0.08, 2)
|
| 121 |
total = round(subtotal + tax, 2)
|