Spaces:
Sleeping
Sleeping
File size: 3,552 Bytes
c913c62 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | """
Demo test script for the Enterprise Comment API.
Sends multiple separate code snippets (one per request) and prints
clean, presentation-friendly output.
"""
import json
import requests
URL = "http://127.0.0.1:8000/generate_comment"
test_cases = [
{
"name": "payment_terms",
"code": """def compute_due_date(invoice_date, terms):
# terms could include credit_days, installment_percentages, etc.
credit_days = terms.get("credit_days", 0)
due_date = add_days(invoice_date, credit_days)
return due_date""",
},
{
"name": "payment_entry_allocation_and_outstanding_balances",
"code": """def allocate_payment(payment_amount: float, references: list[dict]):
allocated = []
remaining = payment_amount
for ref in references: # e.g. invoices with outstanding_amount
take = min(ref["outstanding_amount"], remaining)
allocated.append({
"reference_doctype": ref["doctype"],
"reference_name": ref["name"],
"allocated_amount": take,
})
remaining -= take
if remaining <= 0:
break
if remaining > 0:
raise ValueError("Payment exceeds referenced outstanding balances")
return allocated""",
},
{
"name": "chart_of_accounts_account_and_account_number",
"code": """def validate_account_hierarchy(account: dict):
# group accounts vs ledger accounts
if account["account_type"] == "Group":
assert account.get("parent_account") is not None
else:
assert account["parent_account"] is not None
# uniqueness for account_number
if account_number_exists(account["account_number"], exclude=account["name"]):
raise ValueError("account_number must be unique")""",
},
{
"name": "make_acc_dimensions_offsetting_entry",
"code": """def make_acc_dimensions_offsetting_entry(gl_map):
accounting_dimensions_to_offset = get_accounting_dimensions_for_offsetting_entry(
gl_map, gl_map[0].company
)
no_of_dimensions = len(accounting_dimensions_to_offset)
if no_of_dimensions == 0:
return""",
},
{
"name": "fiscal_year_accounting_period_and_ledger_entry",
"code": """def validate_transaction_in_fiscal_year(posting_date: str, company: str) -> None:
fy = get_fiscal_year(company=company, posting_date=posting_date)
if fy is None:
raise ValueError("Posting date must be within an active fiscal year")""",
},
]
def code_preview(code: str, max_lines: int = 8) -> str:
lines = code.strip("\n").splitlines()
shown = lines[:max_lines]
preview = "\n".join(shown)
if len(lines) > max_lines:
preview += "\n..."
return preview
def main() -> None:
print("Enterprise Comment API - RAG End-to-End Test (5 sets)")
print(f"URL: {URL}")
for i, case in enumerate(test_cases, start=1):
print("\n" + "=" * 90)
print(f"SET {i}/{len(test_cases)}: {case['name']}")
print("- Code (preview) -")
print(code_preview(case["code"]))
print("- Requesting API -")
resp = requests.post(URL, json={"code": case["code"]})
if resp.status_code != 200:
print(f"[ERROR] Status Code: {resp.status_code}")
print(resp.text)
continue
result = resp.json()
print("[RESPONSE]")
print(json.dumps(result, indent=2, ensure_ascii=True))
print("\n" + "=" * 90)
print("Done.")
if __name__ == "__main__":
main()
|